package main import ( "vultras.su/core/bond" //"vultras.su/core/bond/urlenc" //"vultras.su/core/bond/methods" "vultras.su/core/bond/statuses" "vultras.su/core/bond/jsons" "fmt" //"io" //"net/url" //"strconv" ) type GetNotesOptions struct { Id int `json:"id"` Name string `json:"name"` } type WebhookRequest struct { Leads Leads `json:"leads"` Account Account `json:"account"` } type Leads struct { Status jsons.ArrayMap[Status]`json:"status"` Add jsons.ArrayMap[Status] `json:"add"` } type Status struct { Id jsons.Int `json:"id"` StatusId jsons.Int`json:"status_id"` PipelineId jsons.Int `json:"pipeline_id"` OldStatusId jsons.Int `json:"old_status_id"` OldPipelineId jsons.Int `json:"old_pipeline_id"` } type Account struct { Id jsons.Int `json:"id"` SubDomain string `json:"subdomain"` } var root = bond.Root(bond.Path(). Def( "hook", /*bond.Method().Def( methods.Post,*/ bond.Func(func(c *bond.Context){ reciever := WebhookRequest{} c.Scan(&reciever) if c.ScanErr() != nil { fmt.Printf("err: %s\n", c.ScanErr()) } fmt.Printf("%#v\n", reciever) return /*fmt.Printf("Content-Type: %q\n", c.ContentType()) 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) mp := map[string] any{} err = bond.ParseStr(unesc, mp) if err != nil { fmt.Printf("err:%s\n", err) return } js, err := json.MarshalIndent(mp, "", "\t") if err != nil { fmt.Printf("err:%s\n", err) return } fmt.Printf("\nparsed: %v\n", string(js))*/ c.SetStatus(statuses.OK) }), //), ).Def( "auth", bond.Func(func(c *bond.Context){ }) )) func main() { /*requestString := "leads[status][0][id]=2050297&" + "leads[status][0][status_id]=35573056&" + "leads[status][0][pipeline_id]=3643927&" + "leads[status][0][old_status_id]=35572897&" + "leads[status][0][old_pipeline_id]=3643927&" + "account[id]=29085955&" + "account[subdomain]=domain" reciever := WebhookRequest{} err := urlenc.Unmarshal([]byte(requestString), &reciever) if err != nil { panic(err) }*/ //fmt.Printf("%#v\n", reciever) srv := bond.Server{ Addr: ":15080", Handler: root, } err := srv.ListenAndServe() if err != nil { panic(err) } }