ss/cmd/test/main.go

58 lines
917 B
Go
Raw Normal View History

2023-12-07 12:29:57 +03:00
package main
import (
"github.com/omnipunk/bond"
)
var root = bond.Mux().
Def(
"",
2023-12-07 16:55:23 +03:00
bond.ApiFunc(func(c *bond.Context){
2023-12-07 12:29:57 +03:00
c.W.Write([]byte("This is the index page"))
}),
).Def(
"hello",
bond.Mux().Def(
"en",
2023-12-07 16:55:23 +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-07 16:55:23 +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",
bond.ApiFunc(func(c *bond.Context){
c.SetContentType(bond.PlainText)
c.Printf(
"Path: %q\n" +
"Content-Type: %q\n",
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{
Addr: ":10800",
Handler: root,
}
err := srv.ListenAndServe()
if err != nil {
panic(err)
}
}