package main import ( "vultras.su/core/bond" "vultras.su/core/bond/methods" "vultras.su/core/bond/contents" "vultras.su/core/bond/statuses" ) type GetNotesOptions struct { Id int `json:"id"` Name string `json:"name"` } var root = bond.Root(bond.Path(). Def( "", bond.StaticFile("index.html"), ).Def( "hello", bond.Path().Def( // Using the relative redirect to force us to the en. "", bond.Redirect("en", statuses.Found), ).Def( "en", bond.Func(func(c *bond.Context) { c.Printf("Hello, World!") }), ).Def( "ru", bond.Func(func(c *bond.Context) { c.Printf("Привет, Мир!") }), ), ).Def( "google", bond.Redirect("https://google.com", statuses.Found), ).Def( "web", bond.StaticDir("./static"), ).Def( "test", bond.Func(func(c *bond.Context) { c.SetContentType(contents.Plain) c.Printf( "AbsPath: %q\n" + "Prefix: %q\n" + "Path: %q\n"+ "Content-Type: %q\n", c.AbsPath(), c.PathPrefix(), c.Path(), c.ContentType(), ) c.Printf("Query:\n") for k, vs := range c.Query() { c.Printf("\t%q:\n", k) for _, v := range vs { c.Printf("\t\t%q\n", v) } } }), ).Def( "get-notes", bond.Method().Def( methods.Get, bond.Func(func(c *bond.Context) { opts := GetNotesOptions{} c.Scan(&opts) c.Printf("%v", opts) }), ), )) func main() { srv := bond.Server{ Addr: ":10800", Handler: root, } err := srv.ListenAndServe() if err != nil { panic(err) } }