本文整理汇总了Golang中gnd/la/app.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: printResources
func printResources(ctx *app.Context) {
// TODO: Define an interface in package vfs, so this fails
// if the interface is changed or renamed.
type rooter interface {
Root() string
}
var assets string
var templates string
if mgr := ctx.App().AssetsManager(); mgr != nil {
if r, ok := mgr.VFS().(rooter); ok {
assets = r.Root()
}
}
if r, ok := ctx.App().TemplatesFS().(rooter); ok {
templates = r.Root()
}
resources := map[string]string{
"assets": assets,
"templates": templates,
}
data, err := json.Marshal(resources)
if err != nil {
panic(err)
}
fmt.Println(string(data))
}
开发者ID:rainycape,项目名称:gondola,代码行数:26,代码来源:cmds.go
示例2: ListHandler
func ListHandler(ctx *app.Context) {
var groups []*packageGroup
dctx := getEnvironment(ctx)
for _, gr := range appDocGroups(ctx) {
var groupPackages []*doc.Package
for _, v := range gr.Packages {
pkgs, err := dctx.ImportPackages(packageDir(dctx, v))
if err != nil {
log.Errorf("error importing %s: %s", v, err)
continue
}
groupPackages = append(groupPackages, pkgs...)
}
if len(groupPackages) > 0 {
groups = append(groups, &packageGroup{
Title: gr.Title,
Packages: groupPackages,
})
}
}
if len(groups) == 0 {
ctx.NotFound("no packages to list")
return
}
title := "Package Index"
data := map[string]interface{}{
"Header": title,
"Title": title,
"Groups": groups,
}
ctx.MustExecute(PackagesTemplateName, data)
}
开发者ID:rainycape,项目名称:gondola,代码行数:32,代码来源:handlers.go
示例3: afterTask
func afterTask(ctx *app.Context, task *Task, started time.Time, terr *error) {
name := task.Name()
if err := recover(); err != nil {
skip, stackSkip, _, _ := runtimeutil.GetPanic()
var buf bytes.Buffer
fmt.Fprintf(&buf, "Panic executing task %s: %v\n", name, err)
stack := runtimeutil.FormatStack(stackSkip)
location, code := runtimeutil.FormatCaller(skip, 5, true, true)
if location != "" {
buf.WriteString("\n At ")
buf.WriteString(location)
if code != "" {
buf.WriteByte('\n')
buf.WriteString(code)
buf.WriteByte('\n')
}
}
if stack != "" {
buf.WriteString("\nStack:\n")
buf.WriteString(stack)
}
*terr = errors.New(buf.String())
}
end := time.Now()
running.Lock()
defer running.Unlock()
c := running.tasks[task] - 1
if c > 0 {
running.tasks[task] = c
} else {
delete(running.tasks, task)
}
ctx.Logger().Infof("Finished task %s (%d instances now running) at %v (took %v)", name, c, end, end.Sub(started))
}
开发者ID:rainycape,项目名称:gondola,代码行数:34,代码来源:tasks.go
示例4: redirectToFrom
func redirectToFrom(ctx *app.Context) {
from := ctx.FormValue(app.SignInFromParameterName)
if from == "" {
from = "/"
}
ctx.Redirect(from, false)
}
开发者ID:rainycape,项目名称:gondola,代码行数:7,代码来源:util.go
示例5: testing2
func testing2(ctx app.Context) {
ctx.T("Testing even more translations")
var t1 i18n.String = "Var inside function"
/// This is a var string declared via cast
t2 := i18n.String("Testing var string")
fmt.Println(t1, t2)
}
开发者ID:rainycape,项目名称:gondola,代码行数:7,代码来源:test.go
示例6: StdListHandler
func StdListHandler(ctx *app.Context) {
dctx := getEnvironment(ctx)
allPkgs, err := dctx.ImportPackages(dctx.Join(dctx.Context.GOROOT, "src"))
if err != nil {
panic(err)
}
var pkgs []*doc.Package
var cmds []*doc.Package
for _, v := range allPkgs {
if dctx.Base(v.Dir()) == "cmd" {
cmds = append(cmds, v)
} else {
pkgs = append(pkgs, v)
}
}
title := "Go Standard Library"
groups := []packageGroup{
{Title: "Go Standard Library", Packages: pkgs},
{Title: "Go Commands", Packages: cmds},
}
data := map[string]interface{}{
"Header": title,
"Title": title,
"Groups": groups,
}
ctx.MustExecute(PackagesTemplateName, data)
}
开发者ID:rainycape,项目名称:gondola,代码行数:27,代码来源:handlers.go
示例7: decodeResetPayload
func decodeResetPayload(ctx *app.Context, payload string) (reflect.Value, error) {
se, err := ctx.App().EncryptSigner(Salt)
if err != nil {
return reflect.Value{}, err
}
value, err := se.UnsignDecrypt(payload)
if err != nil {
return reflect.Value{}, err
}
qs, err := url.ParseQuery(string(value))
if err != nil {
return reflect.Value{}, err
}
userId, err := strconv.ParseInt(qs.Get("u"), 36, 64)
if err != nil {
return reflect.Value{}, err
}
ts, err := strconv.ParseInt(qs.Get("t"), 36, 64)
if err != nil {
return reflect.Value{}, err
}
if time.Since(time.Unix(ts, 0)) > PasswordResetExpiry {
return reflect.Value{}, errResetExpired
}
user, userVal := newEmptyUser(ctx)
ok := ctx.Orm().MustOne(orm.Eq("User.UserId", userId), userVal)
if !ok {
return reflect.Value{}, errNoSuchUser
}
return user, nil
}
开发者ID:rainycape,项目名称:gondola,代码行数:31,代码来源:handlers.go
示例8: ArticleListHandler
func ArticleListHandler(ctx *app.Context) {
data := map[string]interface{}{
"Articles": getArticles(ctx),
"Title": ctx.App().Name(),
}
ctx.MustExecute("list.html", data)
}
开发者ID:rainycape,项目名称:gondola,代码行数:7,代码来源:handlers.go
示例9: signInFacebookTokenHandler
func signInFacebookTokenHandler(ctx *app.Context, client *oauth2.Client, token *oauth2.Token) {
user, err := userFromFacebookToken(ctx, token)
if err != nil {
panic(err)
}
ctx.MustSignIn(asGondolaUser(user))
redirectToFrom(ctx)
}
开发者ID:rainycape,项目名称:gondola,代码行数:8,代码来源:facebook.go
示例10: signInGoogleTokenHandler
func signInGoogleTokenHandler(ctx *app.Context, client *oauth2.Client, token *oauth2.Token) {
d := data(ctx)
googleApp := d.opts.GoogleApp.Clone(ctx)
user, err := userFromGoogleToken(ctx, googleApp, token)
if err != nil {
panic(err)
}
ctx.MustSignIn(asGondolaUser(user))
redirectToFrom(ctx)
}
开发者ID:rainycape,项目名称:gondola,代码行数:10,代码来源:google.go
示例11: validateNewUsername
func validateNewUsername(ctx *app.Context, username string) error {
userType := getUserType(ctx)
found, err := ctx.Orm().Exists(ctx.Orm().TypeTable(userType), ByUsername(username))
if err != nil {
return err
}
if found {
return i18n.Errorf("username %q is already in use", username)
}
return nil
}
开发者ID:rainycape,项目名称:gondola,代码行数:11,代码来源:util.go
示例12: Skip
func (m *SimpleMediator) Skip(ctx *app.Context) bool {
if m := ctx.R.Method; m != "GET" && m != "HEAD" {
return true
}
c := ctx.Cookies()
for _, v := range m.SkipCookies {
if c.Has(v) {
return true
}
}
return false
}
开发者ID:rainycape,项目名称:gondola,代码行数:12,代码来源:mediator.go
示例13: executeTask
func executeTask(ctx *app.Context, task *Task) (ran bool, err error) {
var n int
if n, err = numberOfInstances(task); err != nil {
return
}
started := time.Now()
ctx.Logger().Infof("Starting task %s (%d instances now running) at %v", task.Name(), n, started)
ran = true
defer afterTask(ctx, task, started, &err)
task.Handler(ctx)
return
}
开发者ID:rainycape,项目名称:gondola,代码行数:12,代码来源:tasks.go
示例14: FormErrors
func FormErrors(ctx *app.Context, frm *form.Form) {
errors := make(map[string]string)
for _, v := range frm.Fields() {
if ferr := v.Err(); ferr != nil {
errors[v.HTMLName] = ferr.Error()
}
}
data := map[string]interface{}{
"errors": errors,
}
ctx.WriteJSON(data)
}
开发者ID:rainycape,项目名称:gondola,代码行数:12,代码来源:handlers.go
示例15: serveFile
func serveFile(ctx *app.Context, path string) {
f, err := os.Open(path)
if err != nil {
ctx.NotFound("")
return
}
defer f.Close()
var modtime time.Time
if fi, err := f.Stat(); err == nil {
modtime = fi.ModTime()
}
http.ServeContent(ctx, ctx.R, filepath.Base(path), modtime, f)
}
开发者ID:rainycape,项目名称:governator.io,代码行数:13,代码来源:app.go
示例16: listUsers
func listUsers(ctx *app.Context) {
userVal, ptr := newEmptyUser(ctx)
iter := ctx.Orm().All().Iter()
w := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', tabwriter.Debug)
fmt.Fprint(w, "ID\tUsername\tEmail\tAdmin?\n")
for iter.Next(ptr) {
val := userVal.Elem().FieldByName("User").Interface().(User)
fmt.Fprintf(w, "%d\t%s\t%s\t%v\n", val.UserId, val.Username, val.Email, val.Admin)
}
if err := w.Flush(); err != nil {
panic(err)
}
}
开发者ID:rainycape,项目名称:gondola,代码行数:13,代码来源:commands.go
示例17: windowCallbackHandler
func windowCallbackHandler(ctx *app.Context, user reflect.Value, callback string) {
inWindow := ctx.FormValue("window") != ""
if user.IsValid() {
ctx.MustSignIn(asGondolaUser(user))
}
if inWindow {
var payload []byte
if user.IsValid() {
var err error
payload, err = JSONEncode(ctx, user.Interface())
if err != nil {
panic(err)
}
}
ctx.MustExecute("js-callback.html", map[string]interface{}{
"Callback": callback,
"Payload": payload,
})
} else {
if user.IsValid() {
redirectToFrom(ctx)
} else {
ctx.MustRedirectReverse(false, app.SignInHandlerName)
}
}
}
开发者ID:rainycape,项目名称:gondola,代码行数:26,代码来源:handlers.go
示例18: validateNewEmail
func validateNewEmail(ctx *app.Context, email string) (string, error) {
addr, err := mail.Validate(email, true)
if err != nil {
return "", i18n.Errorf("this does not look like a valid email address")
}
userType := getUserType(ctx)
found, err := ctx.Orm().Exists(ctx.Orm().TypeTable(userType), ByEmail(addr))
if err != nil {
return "", err
}
if found {
return "", i18n.Errorf("email %q is already in use", addr)
}
return addr, nil
}
开发者ID:rainycape,项目名称:gondola,代码行数:15,代码来源:util.go
示例19: jsSignUpHandler
func jsSignUpHandler(ctx *app.Context) {
d := data(ctx)
if !d.allowRegistration() {
ctx.NotFound("")
return
}
user, _ := newEmptyUser(ctx)
form := SignUpForm(ctx, user)
if form.Submitted() && form.IsValid() {
saveNewUser(ctx, user)
writeJSONEncoded(ctx, user)
return
}
FormErrors(ctx, form)
}
开发者ID:rainycape,项目名称:gondola,代码行数:15,代码来源:handlers.go
示例20: help
// Implementation of the help command for Gondola apps
func help(ctx *app.Context) {
var cmd string
ctx.ParseIndexValue(0, &cmd)
if cmd != "" {
c := strings.ToLower(cmd)
if _, ok := commands[c]; ok {
fmt.Fprintf(os.Stderr, "Help for command %s:\n", c)
commandHelp(c, -1, os.Stderr)
} else {
fmt.Fprintf(os.Stderr, "No such command %q\n", cmd)
}
} else {
fmt.Fprintf(os.Stderr, "Commands:\n")
commandsHelp(os.Stderr)
}
}
开发者ID:rainycape,项目名称:gondola,代码行数:17,代码来源:commands.go
注:本文中的gnd/la/app.Context类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论