ss/cmd/test/main.go

58 lines
926 B
Go
Raw Normal View History

2023-12-07 12:29:57 +03:00
package main
import (
2023-12-14 21:59:41 +03:00
"github.com/di4f/bond"
2023-12-07 12:29:57 +03:00
)
var root = bond.Mux().
2023-12-14 21:59:41 +03:00
Def(
"",
bond.ApiFunc(func(c *bond.Context) {
c.W.Write([]byte("This is the index page"))
}),
).Def(
2023-12-07 12:29:57 +03:00
"hello",
bond.Mux().Def(
"en",
2023-12-14 21:59:41 +03:00
bond.ApiFunc(func(c *bond.Context) {
2023-12-07 12:29:57 +03:00
c.W.Write([]byte("Hello, World!"))
}),
).Def(
"ru",
2023-12-14 21:59:41 +03:00
bond.ApiFunc(func(c *bond.Context) {
2023-12-07 12:29:57 +03:00
c.W.Write([]byte("Привет, Мир!"))
}),
),
2023-12-07 13:22:11 +03:00
).Def(
"web",
bond.Static("./static"),
2023-12-07 16:55:23 +03:00
).Def(
"test",
2023-12-14 21:59:41 +03:00
bond.ApiFunc(func(c *bond.Context) {
2023-12-07 16:55:23 +03:00
c.SetContentType(bond.PlainText)
c.Printf(
2023-12-14 21:59:41 +03:00
"Path: %q\n"+
"Content-Type: %q\n",
2023-12-07 16:55:23 +03:00
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)
}
}
}),
2023-12-07 12:29:57 +03:00
)
func main() {
srv := bond.Server{
2023-12-14 21:59:41 +03:00
Addr: ":10800",
2023-12-07 12:29:57 +03:00
Handler: root,
}
err := srv.ListenAndServe()
if err != nil {
panic(err)
}
}