amo/cmd/test/main.go

77 lines
1.4 KiB
Go

package main
import (
"vultras.su/core/amo"
"vultras.su/core/bond"
"vultras.su/core/bond/statuses"
"os"
"fmt"
"io"
)
type Context = bond.Context
var root = bond.Root(bond.Path().
Def(
"hook",
bond.Func(func(c *Context){
v := map[string]any{}
c.Scan(&v)
if c.ScanErr() != nil {
fmt.Println("scan-err:", c.ScanErr())
}
fmt.Println("request:", v)
c.SetStatus(statuses.OK)
}),
).Def(
"auth",
bond.Func(func(c *Context){
fmt.Println("header:", c.R.Header)
fmt.Println("content-type:", c.ContentType())
bts, _ := io.ReadAll(c.R.Body)
fmt.Println("request:", string(bts))
c.SetStatus(statuses.OK)
return
v := map[string]any{}
c.Scan(&v)
if c.ScanErr() != nil {
fmt.Println("scan-err:", c.ScanErr())
}
fmt.Println("request:", v)
c.SetStatus(statuses.OK)
}),
))
func main() {
srv := bond.Server{
Addr: ":15080",
Handler: root,
}
go srv.ListenAndServe()
opts := &amo.Options{
Url: os.Getenv("AMO_URL"),
RedirectUrl: os.Getenv("AMO_REDIRECT_URL"),
AccessToken: os.Getenv("AMO_ACCESS"),
RefreshToken: os.Getenv("AMO_REFRESH"),
ClientSecret: os.Getenv("AMO_CLIENT_SECRET"),
ClientId: os.Getenv("AMO_CLIENT_ID"),
AuthCode: os.Getenv("AMO_AUTH_CODE"),
}
fmt.Println(opts)
client, pair, err := amo.NewAmoClient(opts)
if err != nil {
panic(err)
}
if pair != nil {
fmt.Println("%q", pair)
}
company, err := client.GetCompany("80699047", "")
if err != nil {
panic(err)
}
fmt.Println(company)
}