37 lines
789 B
Go
37 lines
789 B
Go
package client
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"git.sr.ht/~cco/go-scopes/config"
|
|
"git.sr.ht/~cco/go-scopes/lib"
|
|
"git.sr.ht/~cco/go-scopes/logging"
|
|
)
|
|
|
|
type Cfg struct {
|
|
*config.BaseCfg
|
|
Url string
|
|
}
|
|
|
|
var GlobalCookieJar http.CookieJar
|
|
|
|
func Send(act lib.Action) bool {
|
|
ctx, spec, msg := act.Context(), act.Spec(), act.Message()
|
|
_ = spec
|
|
cfg := lib.GetCfg[*Cfg](ctx)
|
|
url, _ := url.JoinPath(cfg.Url, msg.Action())
|
|
req, _ := http.NewRequest("GET", url, nil)
|
|
client := http.DefaultClient
|
|
client.Jar = GlobalCookieJar
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
logging.ErrorA(act).Err(err).Msg("client.Send")
|
|
return true
|
|
}
|
|
body, _ := ioutil.ReadAll(resp.Body)
|
|
bodyStr := string(body)
|
|
logging.InfoA(act).Str("data", bodyStr).Msg("client.Send")
|
|
return true
|
|
}
|