ss/cmd/hook/main.go

57 lines
1 KiB
Go
Raw Normal View History

2024-01-10 18:23:02 +03:00
package main
import (
"vultras.su/core/bond"
//"vultras.su/core/bond/methods"
"vultras.su/core/bond/statuses"
2024-01-10 18:23:02 +03:00
"fmt"
"io"
"net/url"
)
type GetNotesOptions struct {
Id int `json:"id"`
Name string `json:"name"`
}
var root = bond.Root(bond.Path().
Def(
2024-01-10 18:23:02 +03:00
"hook",
/*bond.Method().Def(
methods.Post,*/
bond.Func(func(c *bond.Context){
fmt.Printf("Content-Type: %q\n", c.ContentType())
2024-01-10 18:23:02 +03:00
body, err := io.ReadAll(c.R.Body)
if err != nil {
fmt.Printf("err:%s\n", err)
return
}
fmt.Printf("rawBody: %q\n", body)
unesc, err := url.QueryUnescape(string(body))
if err != nil {
fmt.Printf("err:%s\n", err)
return
}
fmt.Printf("unescapeBody: %q\n", unesc)
2024-01-10 18:23:02 +03:00
values, err := url.ParseQuery(string(body))
if err != nil {
fmt.Printf("err:%s\n", err)
return
}
fmt.Printf("Values: %q\n", values)
c.SetStatus(statuses.OK)
2024-01-10 18:23:02 +03:00
}),
//),
))
2024-01-10 18:23:02 +03:00
func main() {
srv := bond.Server{
Addr: ":15080",
Handler: root,
}
err := srv.ListenAndServe()
if err != nil {
panic(err)
}
}