示例#1
0
func init() {
	views.AdminAuth = NewBasicAuth("Username: admin, Password: admin", "admin", "admin")

	views.Admin = &Page{
		Title: Escape("Admin"),
		Content: Views{
			H1("Admin Page"),
			root.Navigation(),
			H3("Manage Users:"),
			UL(
				DynamicView(
					func(ctx *Context) (View, error) {
						url := views.Admin_User0.URL(ctx.ForURLArgs("ErikUnger"))
						return A(url, "ErikUnger"), nil
					},
				),
				DynamicView(
					func(ctx *Context) (View, error) {
						url := views.Admin_User0.URL(ctx.ForURLArgs("AlexTacho"))
						return A(url, "AlexTacho"), nil
					},
				),
			),
		},
	}
}
示例#2
0
func init() {
	views.Admin_User0 = &Page{
		Title: RenderView(
			func(ctx *Context) error {
				// The username is in ctx.URLArgs[0]
				ctx.Response.WriteString("Manage " + ctx.URLArgs[0])
				return nil
			},
		),
		Content: Views{
			DynamicViewBindURLArgs(
				// The URL argument 0 can also be bound dynamically
				// to a function argument:
				func(ctx *Context, username string) (View, error) {
					return H1("Manage user ", username), nil
				},
			),
			root.Navigation(),
			DynamicViewBindURLArgs(
				func(ctx *Context, username string) (View, error) {
					return Views{
						H4(Printf("This view uses the URL argument '%s':", username)),
						HTML(views.Admin_User0.URL(ctx)),
					}, nil
				},
			),
		},
	}
}