示例#1
0
文件: hello.go 项目: jango2015/her
func main() {
	app := her.NewApplication()
	app.Route.Handle("/", func() string {
		return "hello world!"
	})
	app.Route.Handle("/hello/{val}", func(val string) string {
		return "hello " + val
	})
	app.Route.Handle("/hi/{val}", func(ctx *her.Context, val int) {
		ctx.WriteString("hi " + strconv.Itoa(val))
	})

	app.Route.Handle("/par/{val}", func(ctx *her.Context) {
		ctx.WriteString("par: " + ctx.Params["val"])
	})

	app.Route.Handle("/api/her.xml", func(ctx *her.Context) {
		info := &Info{Name: "her", Description: "a web framework for golang"}
		ctx.Xml(info)
	})

	app.Route.Handle("/api/her.json", func(ctx *her.Context) {
		info := &Info{Name: "her", Description: "a web framework for golang"}
		ctx.Json(info)
	})

	app.Start()
}
示例#2
0
文件: book.go 项目: jango2015/her
func main() {
	app := her.NewApplication()

	app.Database.Connection("sqlite", "sqlite3", "./book.s3db")

	app.Route.Handle("/", handler.Book.HomeHandler)
	app.Route.Handle("/create", handler.Book.CreateHandler)
	app.Route.Handle("/del/{id:[0-9]+}", handler.Book.DeleteHandler)
	app.Route.Handle("/static/{path:.*}", her.StaticFileHandler("static"))

	app.Start()
}
示例#3
0
文件: hello.go 项目: jemygraw/her
func main() {
	app := her.NewApplication()
	app.Route.Handle("/", func() string {
		return "hello world!"
	})
	app.Route.Handle("/hello/{val}", func(val string) string {
		return "hello " + val
	})
	app.Route.Handle("/hi/{val}", func(ctx *her.Context, val int) {
		ctx.WriteString("hi " + strconv.Itoa(val))
	})

	app.Route.Handle("/par/{val}", func(ctx *her.Context) {
		ctx.WriteString("par: " + ctx.Params["val"])
	})
	app.Start()
}