Exemple #1
0
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()
}
Exemple #2
0
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()
}
Exemple #3
0
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()
}