61 lines
1.2 KiB
Go
61 lines
1.2 KiB
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
|
|
}
|
|
|
|
func LCR_Create() {
|
|
c := NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo")
|
|
|
|
_, err := c.Do(&DataAPIRequest{
|
|
Col: "LCR_Bot",
|
|
Op: CREATE,
|
|
Data: map[string]interface{}{
|
|
"Registro": "1",
|
|
},
|
|
})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|