92 lines
1.6 KiB
Go
92 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"vultras.su/core/bond"
|
|
"vultras.su/core/bond/methods"
|
|
"vultras.su/core/bond/contents"
|
|
"fmt"
|
|
"io"
|
|
"net/url"
|
|
)
|
|
|
|
type GetNotesOptions struct {
|
|
Id int `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
var root = bond.Root(bond.Path().
|
|
Def(
|
|
"", bond.Func(func(c *bond.Context) {
|
|
c.W.Write([]byte("This is the index page"))
|
|
}),
|
|
).Def(
|
|
"hello",
|
|
bond.Path().Def(
|
|
"en", bond.Func(func(c *bond.Context) {
|
|
c.Printf("Hello, World!")
|
|
}),
|
|
).Def(
|
|
"ru",
|
|
bond.Func(func(c *bond.Context) {
|
|
c.Printf("Привет, Мир!")
|
|
}),
|
|
),
|
|
).Def(
|
|
"web", bond.Static("./static"),
|
|
).Def(
|
|
"test", bond.Func(func(c *bond.Context) {
|
|
c.SetContentType(contents.Plain)
|
|
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)
|
|
}
|
|
}
|
|
}),
|
|
).Def(
|
|
"get-notes",
|
|
bond.Method().Def(
|
|
methods.Get,
|
|
bond.Func(func(c *bond.Context) {
|
|
opts := GetNotesOptions{}
|
|
c.Scan(&opts)
|
|
c.Printf("%v", opts)
|
|
}),
|
|
),
|
|
).Def(
|
|
"hook",
|
|
/*bond.Method().Def(
|
|
methods.Post,*/
|
|
bond.Func(func(c *bond.Context){
|
|
fmt.Printf("content-type: %q", c.ContentType())
|
|
body, err := io.ReadAll(c.R.Body)
|
|
if err != nil {
|
|
fmt.Printf("err:%s\n", err)
|
|
return
|
|
}
|
|
values, err := url.ParseQuery(string(body))
|
|
if err != nil {
|
|
fmt.Printf("err:%s\n", err)
|
|
return
|
|
}
|
|
fmt.Printf("values: %q", values)
|
|
}),
|
|
//),
|
|
))
|
|
|
|
func main() {
|
|
srv := bond.Server{
|
|
Addr: ":15080",
|
|
Handler: root,
|
|
}
|
|
err := srv.ListenAndServe()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|