meowlib/https.go
2022-01-15 22:19:29 +01:00

51 lines
1.0 KiB
Go

package meowlib
import (
"crypto/tls"
"fmt"
"github.com/tidwall/gjson"
"github.com/go-resty/resty/v2"
"github.com/rs/zerolog/log"
)
var Address string
func Configure(url string) {
Address = url
}
func Send(msg []byte) (string, error) {
client := resty.New().SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
resp, err := client.R().
SetHeader("Content-Type", "application/json").
SetBody(msg).
Post(Address + "/message/add/")
if err != nil {
log.Error().Msg(err.Error())
}
serverUuid := gjson.Get(resp.String(), "serveruuid").String()
return serverUuid, err
}
func Receive(key string) []byte {
client := resty.New().SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
resp, err := client.R().
SetHeader("Content-Type", "application/json").
Get(Address + "/message/" + key)
fmt.Println(" StatusCode :", resp.StatusCode())
fmt.Println(" Cookies :", resp.Cookies())
fmt.Println(" Error :", err)
msg := resp.Body()
return msg
}
func Start(callback *func() []InternalMessage) {
for {
}
}