replaycli-go/api/dataapi/lib.go

46 lines
993 B
Go

package dataapi
import (
"go.digitalcircle.com.br/open/httpcli"
)
type DataApiOp string
const (
RETRIEVE DataApiOp = "R"
CREATE DataApiOp = "C"
DELETE DataApiOp = "D"
UPDATE DataApiOp = "U"
)
type DataAPIRequest struct {
Col string `json:"col"`
Q string `json:"q"`
Op DataApiOp `json:"op"`
Id string `json:"id"`
Data map[string]interface{} `json:"data"`
}
type DataAPIResponse struct {
Msg string `json:"msg"`
Id string `json:"id"`
Data []interface{} `json:"data"`
}
type Cli struct {
Httpcli *httpcli.Cli
}
func (c *Cli) Do(request *DataAPIRequest) (response *DataAPIResponse, err error) {
response = &DataAPIResponse{}
err = c.Httpcli.JsonPost("/", request, response)
return
}
func NewCli(apikey string) *Cli {
ret := &Cli{Httpcli: httpcli.NewCli()}
ret.Httpcli.AddHeader("X-API-KEY", apikey)
ret.Httpcli.SetBasePath("https://dataapi.digitalcircle.com.br")
return ret
}