2023-12-07 12:29:57 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-09 07:40:32 +03:00
|
|
|
"vultras.su/core/bond"
|
|
|
|
"vultras.su/core/bond/methods"
|
|
|
|
"vultras.su/core/bond/contents"
|
2024-01-10 20:11:02 +03:00
|
|
|
"vultras.su/core/bond/statuses"
|
2023-12-07 12:29:57 +03:00
|
|
|
)
|
|
|
|
|
2024-01-03 21:23:03 +03:00
|
|
|
type GetNotesOptions struct {
|
2024-01-09 07:40:32 +03:00
|
|
|
Id int `json:"id"`
|
2024-01-03 21:23:03 +03:00
|
|
|
Name string `json:"name"`
|
|
|
|
}
|
|
|
|
|
2024-01-10 20:11:02 +03:00
|
|
|
var root = bond.Root(bond.Path().
|
|
|
|
Def(
|
|
|
|
"",
|
2024-01-10 21:19:23 +03:00
|
|
|
bond.StaticFile("index.html"),
|
2024-01-10 20:11:02 +03:00
|
|
|
).Def(
|
2023-12-07 12:29:57 +03:00
|
|
|
"hello",
|
2024-01-10 20:11:02 +03:00
|
|
|
bond.Path().Def(
|
|
|
|
// Using the relative redirect to force us to the en.
|
2024-01-10 21:19:23 +03:00
|
|
|
"", bond.Redirect("en", statuses.Found),
|
2024-01-10 20:11:02 +03:00
|
|
|
).Def(
|
|
|
|
"en", bond.Func(func(c *bond.Context) {
|
2024-01-03 21:23:03 +03:00
|
|
|
c.Printf("Hello, World!")
|
2023-12-07 12:29:57 +03:00
|
|
|
}),
|
|
|
|
).Def(
|
2024-01-10 20:11:02 +03:00
|
|
|
"ru", bond.Func(func(c *bond.Context) {
|
2024-01-03 21:23:03 +03:00
|
|
|
c.Printf("Привет, Мир!")
|
2023-12-07 12:29:57 +03:00
|
|
|
}),
|
|
|
|
),
|
2023-12-07 13:22:11 +03:00
|
|
|
).Def(
|
2024-01-10 21:19:23 +03:00
|
|
|
"google", bond.Redirect("https://google.com", statuses.Found),
|
|
|
|
).Def(
|
|
|
|
"web", bond.StaticDir("./static"),
|
2023-12-07 16:55:23 +03:00
|
|
|
).Def(
|
2024-01-10 20:11:02 +03:00
|
|
|
"test", bond.Func(func(c *bond.Context) {
|
2024-01-03 21:23:03 +03:00
|
|
|
c.SetContentType(contents.Plain)
|
2023-12-07 16:55:23 +03:00
|
|
|
c.Printf(
|
2024-01-10 21:19:23 +03:00
|
|
|
"AbsPath: %q\n" +
|
|
|
|
"Prefix: %q\n" +
|
2023-12-14 21:59:41 +03:00
|
|
|
"Path: %q\n"+
|
|
|
|
"Content-Type: %q\n",
|
2024-01-10 21:19:23 +03:00
|
|
|
c.AbsPath(),
|
|
|
|
c.PathPrefix(),
|
|
|
|
c.Path(),
|
|
|
|
c.ContentType(),
|
2023-12-07 16:55:23 +03:00
|
|
|
)
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
2024-01-03 21:23:03 +03:00
|
|
|
).Def(
|
|
|
|
"get-notes",
|
|
|
|
bond.Method().Def(
|
|
|
|
methods.Get,
|
2024-01-09 07:40:32 +03:00
|
|
|
bond.Func(func(c *bond.Context) {
|
2024-01-03 21:23:03 +03:00
|
|
|
opts := GetNotesOptions{}
|
|
|
|
c.Scan(&opts)
|
|
|
|
c.Printf("%v", opts)
|
|
|
|
}),
|
|
|
|
),
|
2024-01-10 20:11:02 +03:00
|
|
|
))
|
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)
|
|
|
|
}
|
|
|
|
}
|