本文整理汇总了Golang中gnd/la/app.App类的典型用法代码示例。如果您正苦于以下问题:Golang App类的具体用法?Golang App怎么用?Golang App使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了App类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: reverseAppsArticle
func reverseAppsArticle(a *app.App, art interface{}, checked map[*app.App]bool) (string, error) {
checked[a] = true
var articles []*article.Article
aa, _ := reusableapp.AppData(a).(*appData)
if aa != nil {
articles = aa.Articles
}
switch x := art.(type) {
case string:
for _, v := range articles {
if articleId(v) == x {
return a.Reverse(ArticleHandlerName, v.Slug())
}
}
case *article.Article:
return a.Reverse(ArticleHandlerName, x.Slug())
case article.Article:
return a.Reverse(ArticleHandlerName, x.Slug())
}
if p := a.Parent(); p != nil && !checked[p] {
return reverseAppsArticle(p, art, checked)
}
for _, v := range a.Included() {
if checked[v] {
continue
}
if url, err := reverseAppsArticle(v, art, checked); err == nil {
return url, nil
}
}
if id, ok := art.(string); ok {
return "", fmt.Errorf("no article with id %q found", id)
}
return "", fmt.Errorf("can't reverse Article from %T, must be *Article or string (article id)", art)
}
示例2: New
// New returns prepares the *app.App and then
// returns a new Tester. It also disables
// logging in the App, since the Tester does
// its own logging.
func New(r Reporter, a *app.App) *Tester {
if !flag.Parsed() {
flag.Parse()
}
if *remoteHost == "" {
if gaeLocal != nil && *gaeLocal {
h := gaeLocalHost
remoteHost = &h
} else if gaeRemote != nil && *gaeRemote {
h := internal.AppEngineAppHost()
if h == "" {
panic(errors.New("no application found in app.yaml - please, specify one to run remote tests"))
}
remoteHost = &h
}
}
if *remoteHost != "" {
r.Log(fmt.Sprintf("using host %s", *remoteHost))
}
if err := a.Prepare(); err != nil {
r.Fatal(fmt.Errorf("error preparing app: %s", err))
}
a.Logger = nil
return &Tester{r, a}
}
示例3: loadDatabase
func loadDatabase(a *app.App, filename string) error {
g, err := geoip.Open(filename)
if err != nil {
return err
}
a.Set(geoIPKey, g)
return nil
}
示例4: AppDataWithKey
// AppDataWithKey works similarly to AppData, but uses the provided key instead.
// Also, if the data is not found in the *app.App passed in as the first argument,
// its children apps are also searched. This allows reusable apps to retrieve their
// additional data in contexts where the reusable app pointer is not available.
// (e.g. in template plugins which are called from the parent app). See gnd.la/apps/users
// for an example of this usage.
func AppDataWithKey(a *app.App, key interface{}) interface{} {
ra, _ := a.Get(key).(*App)
if ra != nil {
return ra.Data()
}
if key != reusableAppKey {
for _, ia := range a.Included() {
if data := AppDataWithKey(ia, key); data != nil {
return data
}
}
}
return nil
}
示例5: executeCommand
func executeCommand(name string, cmd *command, args []string, a *app.App) (err error) {
// Parse command flags
set := flag.NewFlagSet(name, flag.ContinueOnError)
set.Usage = func() {
commandHelp(name, -1, os.Stderr)
}
flags := map[string]interface{}{}
for _, arg := range cmd.opts.Flags {
switch arg.typ {
case typBool:
var b bool
set.BoolVar(&b, arg.name, arg.def.(bool), arg.help)
flags[arg.name] = &b
case typInt:
var i int
set.IntVar(&i, arg.name, arg.def.(int), arg.help)
flags[arg.name] = &i
case typString:
var s string
set.StringVar(&s, arg.name, arg.def.(string), arg.help)
flags[arg.name] = &s
default:
panic("invalid arg type")
}
}
// Print error/help messages ourselves
set.SetOutput(ioutil.Discard)
err = set.Parse(args)
if err != nil {
if err == flag.ErrHelp {
return
}
if strings.Contains(err.Error(), "provided but not defined") {
flagName := strings.TrimSpace(strings.Split(err.Error(), ":")[1])
fmt.Fprintf(os.Stderr, "command %s does not accept flag %s\n", name, flagName)
return
}
return err
}
var params []string
paramValues := make(map[string]string)
for _, arg := range cmd.opts.Flags {
params = append(params, arg.name)
paramValues[arg.name] = fmt.Sprintf("%v", reflect.ValueOf(flags[arg.name]).Elem().Interface())
}
provider := &contextProvider{
args: set.Args(),
params: params,
paramValues: paramValues,
}
if os.Getenv("GONDOLA_COMMANDS_NO_RECOVER") == "" {
defer func() {
if r := recover(); r != nil {
if e, ok := r.(error); ok {
err = e
} else {
err = fmt.Errorf("%v", r)
}
if file, line, ok := runtimeutil.PanicLocation(); ok {
err = fmt.Errorf("%v (at %s:%d)", err, file, line)
}
}
}()
}
ctx := a.NewContext(provider)
defer a.CloseContext(ctx)
cmd.handler(ctx)
return
}
示例6: Attach
// Attach attaches a reusable app into its parent app.
func (a *App) Attach(parent *app.App) {
parent.Include(a.Prefix, a.name, &a.App, a.ContainerTemplateName)
}
示例7: Attach
func (b *Broadcaster) Attach(a *app.App) {
a.HandleWebsocket(b.pattern(), b.handler())
a.AddTemplateVars(devserver.TemplateVars(&app.Context{}))
a.AddTemplatePlugin(devserver.ReloadPlugin())
b.ts = time.Now()
}
示例8: Attach
func (a *App) Attach(parent *app.App) {
parent.SetUserFunc(userFunc)
a.App.Attach(parent)
}