Compare commits

..

5 Commits
master ... nats

Author SHA1 Message Date
Paulo Simão 6aae4a5cdb nats migration 2021-11-14 10:31:07 -03:00
Paulo Simão 429580c010 wip 2021-11-13 21:35:07 +00:00
Paulo Simão c79c476473 fronted + nats 2021-11-13 16:30:02 -03:00
Paulo Simão 581b4def8a nats migration 2021-11-11 11:07:20 -03:00
Paulo Simão 5b590ab31b start nats migration 2021-11-11 05:56:07 -03:00
20 changed files with 519 additions and 742 deletions

View File

@ -5,58 +5,41 @@ import (
)
type Cli struct {
*api.ApiCli
//cli *api.Cli
}
//func (c *Cli) HttpCli() *api.Cli {
//
// return c.HttpCli()
//}
type Req struct {
Site string `json:"site"`
Data string `json:"data"`
Img string `json:"img"`
Img []byte `json:"img"`
To int `json:"to"`
}
func (c *Cli) Recaptchav2(site string, data string) (string, error) {
func (c *Cli) Recaptchav2(site string, data string, copts ...*api.CallOpts) (string, error) {
ret := ""
req := &Req{
Site: site,
Data: data,
Img: "",
Img: nil,
To: 300,
}
err := c.HttpCli().JsonPost("/ipc/anticaptcha/recaptchav2", req, &ret)
err := api.Call("anticaptcha.recaptchav2", req, &ret, copts...)
return ret, err
}
func (c *Cli) Hcaptcha(site string, data string) (string, error) {
ret := ""
req := &Req{
Site: site,
Data: data,
Img: "",
To: 300,
}
err := c.HttpCli().JsonPost("/ipc/anticaptcha/hcaptcha", req, &ret)
return ret, err
}
func (c *Cli) Image2text(site string, data string) (string, error) {
func (c *Cli) Image2text(site string, data []byte, copts ...*api.CallOpts) (string, error) {
ret := ""
req := &Req{
Site: site,
Img: data,
To: 300,
}
err := c.HttpCli().JsonPost("/ipc/anticaptcha/image2text", req, &ret)
err := api.Call("anticaptcha.image2text", req, &ret, copts...)
return ret, err
}
func NewCli() *Cli {
ret := &Cli{ApiCli: api.NewApiCli()}
ret := &Cli{}
return ret
}

View File

@ -1,34 +0,0 @@
package apiproxy
import "go.digitalcircle.com.br/open/replaycli-go/api"
type APIProxyRequest struct {
Name string `json:"name,omitempty"`
Method string `json:"method,omitempty"`
Url string `json:"url,omitempty"`
Header map[string]string `json:"header,omitempty"`
Body []byte `json:"body,omitempty"`
Readonly bool `json:"readonly"`
}
type APIProxyResponse struct {
Status string `json:"status"`
StatusCode int `json:"status_code"`
Header map[string]string `json:"header,omitempty"`
Body []byte `json:"body,omitempty"`
}
type Cli struct {
*api.ApiCli
}
func (c *Cli) Do(req *APIProxyRequest) (*APIProxyResponse, error) {
res := &APIProxyResponse{}
err := c.HttpCli().JsonPost("/ipc/apiproxy/do", req, res)
return res, err
}
func NewCli() *Cli {
ret := &Cli{ApiCli: api.NewApiCli()}
return ret
}

View File

@ -1,22 +0,0 @@
package apiproxy
import (
"log"
"os"
"testing"
)
func TestCli_Do(t *testing.T) {
os.Setenv("REPLAY_APIKEY", "DONTBOTHER")
os.Setenv("REPLAY_ADDR", "https://localhost:8443")
c := NewCli()
res, err := c.Do(&APIProxyRequest{
Method: "GET",
Url: "https://www.slashdot.org",
})
if err != nil {
t.Fatal(err.Error())
}
log.Printf("%#v", res)
}

View File

@ -1,25 +0,0 @@
package autohotkey
import (
"go.digitalcircle.com.br/open/replaycli-go/api"
)
type Cli struct {
*api.ApiCli
}
func NewCli() *Cli {
ret := &Cli{ApiCli: api.NewApiCli()}
return ret
}
func (c *Cli) Test() (ret []byte, err error) {
ret, err = c.HttpCli().RawPost("/ipc/ahk/test", nil)
return ret, err
}
func (c *Cli) Do(data string) (ret []byte, err error) {
i := []byte(data)
ret, err = c.HttpCli().RawPost("/ipc/ahk/do", i)
return ret, err
}

View File

@ -1,25 +0,0 @@
package autoit
import (
"go.digitalcircle.com.br/open/replaycli-go/api"
)
type Cli struct {
*api.ApiCli
}
func NewCli() *Cli {
ret := &Cli{ApiCli: api.NewApiCli()}
return ret
}
func (c *Cli) Test() (ret []byte, err error) {
ret, err = c.HttpCli().RawPost("/ipc/autoit/test", nil)
return ret, err
}
func (c *Cli) Do(data string) (ret []byte, err error) {
i := []byte(data)
ret, err = c.HttpCli().RawPost("/ipc/autoit/do", i)
return ret, err
}

View File

@ -3,12 +3,22 @@ package chrome
import (
"encoding/json"
"fmt"
"go.digitalcircle.com.br/open/replaycli-go/api"
)
type Cli struct {
*api.ApiCli
type Req struct {
To int
Url string
Id string
Eval string
Title string
Msg map[string]interface{}
}
type Res struct {
Id string
TabMetadata []TabMetadata
Ret map[string]interface{}
Raw []byte
}
type TabMetadata struct {
@ -21,8 +31,15 @@ type TabMetadata struct {
WebSocketDebuggerUrl string `json:"webSocketDebuggerUrl"`
}
type Cli struct {
*api.ApiCli
}
//func (c *Cli) HttpCli() *httpcli.Cli {
// return c.ApiCli.HttpCli()
//}
func (c *Cli) Start(to int) error {
// to -> Time out para a conexão com o Chrome. Dado em segundos.
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/chrome/start?to=%d", to), nil)
return err
}
@ -35,76 +52,39 @@ func (c *Cli) Stop() error {
return err
}
func (c *Cli) New(url string) (string, error) {
// url -> Site no qual se quer iniciar uma nova aba.
ret := ""
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/chrome/new?url=%s", url), &ret)
return ret, err
// ret -> ID do Websocket criado para navegação na "url" informada.
}
func (c *Cli) Close(id string) error {
// id -> ID do websocket ativo. É o primeiro retorno do método "New".
err := c.HttpCli().JsonGet("/ipc/chrome/close/"+id, nil)
return err
}
func (c *Cli) Eval(id string, s string) (map[string]interface{}, error) {
// id -> ID do websocket no qual se quer fazer um comando JavaScript.
// s -> Comando JavaScript a ser executado no terminal web do WebSocket informado.
ret := make(map[string]interface{})
bs, err := c.HttpCli().RawPost("/ipc/chrome/eval/"+id, []byte(s))
json.Unmarshal(bs, &ret)
return ret, err
// ret -> O valor retornado pelo comando JavaScript executado.
}
func (c *Cli) Wait(id string, s string, to int) (string, error) {
// id -> ID do websocket no qual se quer fazer um comando JavaScript.
// s -> Comando JavaScript a ser executado no terminal web do WebSocket informado. Deve ser uma expressão que retorne um valor booleano para, por exemplo, verificar se um elemento já foi carregado.
// to -> TimeOut de espera para retorno "true" da expressão JavaScript informada. Informado em segundos.
ret := ""
bs, err := c.HttpCli().RawPost(fmt.Sprintf("/ipc/chrome/wait/%s?to=%d", id, to), []byte(s))
json.Unmarshal(bs, &ret)
return ret, err
}
func (c *Cli) Send(id string, m string, ps map[string]interface{}) (interface{}, error) {
// id -> ID do Websocket no qual se deseja realizar a alteração.
var ret interface{}
func (c *Cli) Send(id string, m string, ps map[string]interface{}) (string, error) {
ret := ""
in := map[string]interface{}{
"method": m,
"params": ps,
}
err := c.HttpCli().JsonPost("/ipc/chrome/send/"+id, in, &ret)
err := c.HttpCli().JsonPost("/ipc/chrome/eval/"+id, in, &ret)
return ret, err
// ret -> Retorno do comando (Referência em: https://chromedevtools.github.io/devtools-protocol/)
}
func (c *Cli) OpenTabs() (ret []map[string]string, err error) {
err = c.HttpCli().JsonGet("/ipc/chrome/opentabs", &ret)
return ret, err
// ret -> Array contendo as abas abertas e metadados sobre as mesmas.
}
func (c *Cli) FindTabByUrl(url string) (ret string, err error) {
// url -> URL ativa em uma das abas abertas.
err = c.HttpCli().JsonGet("/ipc/chrome/findtabbyurl/"+url, &ret)
return ret, err
// ret -> ID do WebSocket contendo a aba encontrada.
}
func (c *Cli) FindUrlById(id string) (ret string, err error) {
// url -> URL ativa em uma das abas abertas.
err = c.HttpCli().JsonGet("/ipc/chrome/findurlbyid/"+id, &ret)
return ret, err
// ret -> Url da aba encontrada.
}
func (c *Cli) FindTabByTitle(title string) (ret string, err error) {
// title -> Título de uma das abas abertas.
err = c.HttpCli().JsonGet("/ipc/chrome/findtabbytitle/"+title, &ret)
return ret, err
// ret -> ID do WebSocket contendo a aba encontrada.
}
func NewCli() *Cli {
ret := &Cli{ApiCli: api.NewApiCli()}
return ret
// ret -> Nova instância do Chrome para utilização.
}

View File

@ -1,9 +1,6 @@
package dataapi
import (
"strconv"
"time"
"go.digitalcircle.com.br/open/httpcli"
)
@ -46,86 +43,3 @@ func NewCli(apikey string) *Cli {
ret.Httpcli.SetBasePath("https://dataapi.digitalcircle.com.br")
return ret
}
func RegistrarExec(table, apikey string, check bool, checkC bool) {
//Para robôs, age como contador e registra cada repetição no mês
c := NewCli(apikey)
var registros int
var erro int
captReg := 0
current := time.Now().Format("2006-01")
res, err := c.Do(&DataAPIRequest{
Col: table,
Op: RETRIEVE,
Q: "@[?date=='" + current + "']",
})
if err != nil {
panic(err)
}
if len(res.Data) > 0 {
if check {
result := res.Data[0].(map[string]interface{})
registros = int(result["exec"].(float64))
registros = registros + 1
captReg = int(result["capt"].(float64))
if checkC {
captReg = captReg + 1
}
ident := strconv.Itoa(int(result["ID"].(float64)))
_, err = c.Do(&DataAPIRequest{
Col: table,
Op: UPDATE,
Id: ident,
Data: map[string]interface{}{
"exec": registros,
"capt": captReg,
},
})
if err != nil {
panic(err)
}
} else {
result := res.Data[0].(map[string]interface{})
registros = int(result["err"].(float64))
registros = registros + 1
ident := strconv.Itoa(int(result["ID"].(float64)))
_, err = c.Do(&DataAPIRequest{
Col: table,
Op: UPDATE,
Id: ident,
Data: map[string]interface{}{
"err": registros,
},
})
if err != nil {
panic(err)
}
}
} else {
if check {
registros = 1
erro = 0
if checkC {
captReg = 1
}
} else {
registros = 0
erro = 1
}
_, err = c.Do(&DataAPIRequest{
Col: table,
Op: CREATE,
Data: map[string]interface{}{
"date": current,
"exec": registros,
"err": erro,
"capt": captReg,
},
})
if err != nil {
panic(err)
}
}
}

View File

@ -1,18 +1,15 @@
package dataapi_test
import (
"log"
"strconv"
"testing"
"time"
"go.digitalcircle.com.br/open/replaycli-go/api/dataapi"
"log"
"testing"
)
func TestAPIRetrieve(t *testing.T) {
c := dataapi.NewCli()
c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo")
res, err := c.Do(&dataapi.DataAPIRequest{
Col: "teste3",
Col: "C1",
Op: dataapi.RETRIEVE,
})
if err != nil {
@ -23,7 +20,7 @@ func TestAPIRetrieve(t *testing.T) {
}
func TestAPIRetrieveWQuery(t *testing.T) {
c := dataapi.NewCli()
c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo")
res, err := c.Do(&dataapi.DataAPIRequest{
Col: "C1",
Op: dataapi.RETRIEVE,
@ -37,7 +34,7 @@ func TestAPIRetrieveWQuery(t *testing.T) {
}
func TestAPIUpdate(t *testing.T) {
c := dataapi.NewCli()
c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo")
res, err := c.Do(&dataapi.DataAPIRequest{
Col: "C1",
Op: dataapi.UPDATE,
@ -54,7 +51,7 @@ func TestAPIUpdate(t *testing.T) {
}
func TestAPIDelete(t *testing.T) {
c := dataapi.NewCli()
c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo")
res, err := c.Do(&dataapi.DataAPIRequest{
Col: "C1",
Op: dataapi.DELETE,
@ -68,78 +65,18 @@ func TestAPIDelete(t *testing.T) {
}
func TestAPICreate(t *testing.T) {
if true {
print("a")
print("b")
}
c := dataapi.NewCli()
var registros int
var erro int
current := time.Now().Format("2006-01")
c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo")
res, err := c.Do(&dataapi.DataAPIRequest{
Col: "teste3",
Op: dataapi.RETRIEVE,
Q: "@[?date=='" + current + "']",
Col: "C1",
Op: dataapi.CREATE,
Data: map[string]interface{}{
"MSG": "OI LEO",
},
})
if err != nil {
panic(err)
t.Fatal(err.Error())
}
check := false
if len(res.Data) > 0 {
if check {
result := res.Data[0].(map[string]interface{})
registros = int(result["exec"].(float64))
registros = registros + 1
ident := strconv.Itoa(int(result["ID"].(float64)))
_, err = c.Do(&dataapi.DataAPIRequest{
Col: "teste3",
Op: dataapi.UPDATE,
Id: ident,
Data: map[string]interface{}{
"exec": registros,
},
})
if err != nil {
panic(err)
}
} else {
result := res.Data[0].(map[string]interface{})
registros = int(result["err"].(float64))
registros = registros + 1
ident := strconv.Itoa(int(result["ID"].(float64)))
_, err = c.Do(&dataapi.DataAPIRequest{
Col: "teste3",
Op: dataapi.UPDATE,
Id: ident,
Data: map[string]interface{}{
"err": registros,
},
})
if err != nil {
panic(err)
}
}
} else {
if check {
registros = 1
erro = 0
} else {
registros = 0
erro = 1
}
_, err = c.Do(&dataapi.DataAPIRequest{
Col: "teste3",
Op: dataapi.CREATE,
Data: map[string]interface{}{
"date": current,
"exec": registros,
"err": erro,
},
})
if err != nil {
panic(err)
}
}
log.Printf("%#v", res)
}

View File

@ -43,6 +43,7 @@ func (c *Cli) Write(fname string, sheet string, cell string, val string, celtype
err := c.HttpCli().JsonPost("/ipc/excel/write", req, &res)
return err
}
func (c *Cli) New(fname string, sheet string) (string, error) {
req := &Req{
File: fname,

View File

@ -0,0 +1,29 @@
package frontend
import "go.digitalcircle.com.br/open/replaycli-go/api"
type Cli struct {
}
type HttpRes struct {
Headers map[string]string
Body []byte
}
type HttpReq struct {
Url string
Headers map[string]string
Body []byte
}
func (c *Cli) Get(req *HttpReq, copts ...*api.CallOpts) (*HttpRes, error) {
res := &HttpRes{}
//err := c.HttpCli().JsonPost("/ipc/ocr/", opts, res)
err := api.Call("frontend.handle", req, &res, copts...)
return res, err
}
func NewCli() *Cli {
ret := &Cli{}
return ret
}

12
api/http/lib.go 100644
View File

@ -0,0 +1,12 @@
package http
type HttpRes struct {
Headers map[string]string
Body []byte
}
type HttpReq struct {
Url string
Headers map[string]string
Body []byte
}

145
api/nats.go 100644
View File

@ -0,0 +1,145 @@
package api
import (
"encoding/json"
"errors"
"fmt"
"github.com/nats-io/nats.go"
"log"
"os"
"time"
)
var nc *nats.Conn
type CallOpts struct {
To int
}
func NC() (nc *nats.Conn, err error) {
if nc == nil {
apikey = os.Getenv("REPLAY_APIKEY")
if apikey == "" {
log.Printf("Connecting to NATS Server w/o TK.")
nc, err = nats.Connect(nats.DefaultURL)
} else {
log.Printf("Connecting to NATS Server w TK: " + apikey)
nc, err = nats.Connect(nats.DefaultURL, nats.Token(apikey))
}
if err != nil {
return nil, err
}
}
return nc, nil
}
func Call(s string, in interface{}, out interface{}, opts ...*CallOpts) error {
var err error
opt := &CallOpts{}
if opts != nil && len(opts) > 1 {
opt = opts[0]
}
if opt.To == 0 {
opt.To = 60
}
defer func() {
if nc != nil && err != nil {
err1 := nc.Publish("err", []byte(fmt.Sprintf("Error calling nats: %s: \nIN: %v\nOUT: %v", s, err.Error(), in, out)))
if err1 != nil {
log.Printf("Error calling nats: %s: \nIN: %v\nOUT: %v", s, err.Error(), in, out)
log.Printf("Inner error: %s", err1.Error())
}
} else if nc == nil && err != nil {
log.Printf("Error calling nats: %s: \nIN: %v\nOUT: %v\n(nc is nil)", s, err.Error(), in, out)
}
}()
if nc == nil {
apikey = os.Getenv("REPLAY_APIKEY")
if apikey == "" {
log.Printf("Connecting to NATS Server w/o TK.")
nc, err = nats.Connect(nats.DefaultURL)
} else {
log.Printf("Connecting to NATS Server w TK: " + apikey)
nc, err = nats.Connect(nats.DefaultURL, nats.Token(apikey))
}
if err != nil {
return err
}
}
var bs []byte
if in != nil {
bs, err = json.Marshal(in)
if err != nil {
return err
}
} else {
bs = []byte("{}")
}
msg, err := nc.Request(s, bs, time.Second+time.Duration(opt.To))
if err != nil {
return err
}
if out != nil {
err = json.Unmarshal(msg.Data, out)
if err != nil {
out = bs
return err
}
}
errstr := msg.Header.Get("ERR")
if errstr != "" {
return errors.New(errstr)
}
return nil
}
func Close() error {
return nc.Drain()
}
func Pub(s string, in interface{}) error {
var err error
defer func() {
if nc != nil && err != nil {
err1 := nc.Publish("err", []byte(fmt.Sprintf("Error calling nats: %s: \nIN: %v", s, err.Error(), in)))
if err1 != nil {
log.Printf("Error calling nats: %s: \nIN: %v", s, err.Error(), in)
log.Printf("Inner error: %s", err1.Error())
}
} else if nc == nil && err != nil {
log.Printf("Error calling nats: %s: \nIN: %v\n(nc is nil)", s, err.Error(), in)
}
}()
bs, err := json.Marshal(in)
if err != nil {
return err
}
err = nc.Publish(s, bs)
return err
}
func Init() error {
var err error
nc, err = NC()
if err != nil {
return err
}
nc.Subscribe("exit", func(msg *nats.Msg) {
log.Printf("Exit Required")
os.Exit(0)
})
return nil
}
func Err(e error) {
Pub("err", e.Error())
}
func Dbg(e string) {
Pub("dbg", e)
}

View File

@ -169,16 +169,16 @@ type Opts struct {
}
type Cli struct {
*api.ApiCli
//*api.ApiCli
}
func (c *Cli) OCR(opts *Opts) (*Alto, error) {
func (c *Cli) OCR(opts *Opts, copts ...*api.CallOpts) (*Alto, error) {
res := &Alto{}
err := c.HttpCli().JsonPost("/ipc/ocr/", opts, res)
err := api.Call("ocr.ocr", opts, &res, copts...)
return res, err
}
func NewCli() *Cli {
ret := &Cli{ApiCli: api.NewApiCli()}
ret := &Cli{}
return ret
}

View File

@ -16,15 +16,11 @@ type Cli struct {
*api.ApiCli
}
//Log saves log to database after populated
func (c *Cli) Log(l *types.Log) error {
l.Alias = c.ReplayEnvAlias()
l.Dtlogend = time.Now()
return c.HttpCli().JsonPost("/api/v1/log/add", l, nil)
}
//NewLog creates a new log instance in the client, capable of collecting data in memory for later saving it to the
//database by calling Log
func (c *Cli) NewLog() *types.Log {
ret := &types.Log{}
ret.Alias = c.ReplayEnvAlias()
@ -50,11 +46,6 @@ func (c *Cli) ReplayEnvAddr() string {
func (c *Cli) ReplayEnvHomeDir() string {
return os.Getenv("REPLAY_HOMEDIR")
}
func (c *Cli) ReplayPort() string {
return os.Getenv("REPLAY_PORT")
}
func (c *Cli) ReplayEnvRepo() string {
return os.Getenv("REPLAY_REPO")
}
@ -127,20 +118,15 @@ func (c *Cli) QueueGetData(id string) (ret []byte, err error) {
ret, err = c.HttpCli().RawGet("/api/v1/queue/getrequest/" + id)
return
}
func (c *Cli) QueueGetDataBody(id string) (ret []byte, err error) {
ret, err = c.HttpCli().RawGet("/api/v1/queue/getrequestbody/" + id)
return
}
func (c *Cli) QueueGetMyData() ([]byte, error) {
return c.QueueGetData(os.Getenv("REPLAY_QUEUEID"))
}
func (c *Cli) QueueGetMyJson(i *interface{}) error {
func (c *Cli) QueueGetMyJson(i interface{}) error {
bs, err := c.QueueGetData(os.Getenv("REPLAY_QUEUEID"))
if err != nil {
return err
}
err = json.Unmarshal(bs, &i)
err = json.Unmarshal(bs, i)
return err
}
func (c *Cli) QueueAbort() error {
@ -150,14 +136,6 @@ func (c *Cli) QueueEnqueue(id uint) error {
return c.HttpCli().JsonGet(fmt.Sprintf("/api/v1/robots/op/enqueue/%d", id), nil)
}
func (c *Cli) QueueEnqueueWData(id string, bs []byte) ([]byte, error) {
return c.HttpCli().RawPost(fmt.Sprintf("api/v1/queue/add/%s", id), bs)
}
func (c *Cli) QueueEnqueueWDataWait(id string, bs []byte) ([]byte, error) {
return c.HttpCli().RawPost(fmt.Sprintf("api/v1/queue/addwait?job=%s", id), bs)
}
func (c *Cli) ServiceStopAll() error {
return c.HttpCli().JsonGet("/api/v1/service/op/stopall", nil)
}

View File

@ -10,99 +10,56 @@ type Cli struct {
*api.ApiCli
}
const (
CCHDEVICENAME = 32
CCHFORMNAME = 32
ENUM_CURRENT_SETTINGS uint32 = 0xFFFFFFFF
ENUM_REGISTRY_SETTINGS uint32 = 0xFFFFFFFE
DISP_CHANGE_SUCCESSFUL uint32 = 0
DISP_CHANGE_RESTART uint32 = 1
DISP_CHANGE_FAILED uint32 = 0xFFFFFFFF
DISP_CHANGE_BADMODE uint32 = 0xFFFFFFFE
)
type DEVMODE struct {
DmDeviceName [CCHDEVICENAME]uint16
DmSpecVersion uint16
DmDriverVersion uint16
DmSize uint16
DmDriverExtra uint16
DmFields uint32
DmOrientation int16
DmPaperSize int16
DmPaperLength int16
DmPaperWidth int16
DmScale int16
DmCopies int16
DmDefaultSource int16
DmPrintQuality int16
DmColor int16
DmDuplex int16
DmYResolution int16
DmTTOption int16
DmCollate int16
DmFormName [CCHFORMNAME]uint16
DmLogPixels uint16
DmBitsPerPel uint32
DmPelsWidth uint32
DmPelsHeight uint32
DmDisplayFlags uint32
DmDisplayFrequency uint32
DmICMMethod uint32
DmICMIntent uint32
DmMediaType uint32
DmDitherType uint32
DmReserved1 uint32
DmReserved2 uint32
DmPanningWidth uint32
DmPanningHeight uint32
}
/***************** Clip Functions *****************/
//func (c *Cli) HttpCli() *api.Cli {
// return c.cli
//}
func (c *Cli) ClipRead() (string, error) {
bs, err := c.HttpCli().RawGet("/ipc/wingui/clip/read")
return string(bs), err
ret := ""
err := api.Call("wingui.clip.read", nil, &ret)
//err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/clip/read"), &ret)
return ret, err
}
func (c *Cli) ClipWrite(site string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/clip/write?str=%s", site), nil)
func (c *Cli) ClipWrite(in string) error {
var out interface{}
err := api.Call("wingui.clip.read", in, &out)
//err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/clip/write?str=%s", site), nil)
return err
}
/***************** Mouse Functions *****************/
func (c *Cli) MouseClick() error {
err := c.HttpCli().JsonGet("/ipc/wingui/mouse/click", nil)
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/mouse/click"), nil)
return err
}
func (c *Cli) MouseMove(x, y int) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/mouse/move?x=%d&y=%d", x, y), nil)
return err
}
func (c *Cli) MouseMoveRelative(x, y int) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/mouse/moverelative?x=%d&y=%d", x, y), nil)
return err
}
func (c *Cli) MouseClickRelative(x, y int) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/mouse/clickatrelative?x=%d&y=%d", x, y), nil)
return err
}
func (c *Cli) MouseClickAt(x, y int) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/mouse/clickat?x=%d&y=%d", x, y), nil)
return err
}
func (c *Cli) MouseDrag(x, y int, btn string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/mouse/drag?x=%d&y=%d&btn=%s", x, y, btn), nil)
func (c *Cli) ScreenClick(f string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/screen/click?f=%s", f), nil)
return err
}
/***************** KB Functions *****************/
func (c *Cli) ScreenClickCenter(f string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/screen/clickcenter?f=%s", f), nil)
return err
}
func (c *Cli) ScreenFind(f string) (ret map[string]interface{}, err error) {
ret = make(map[string]interface{})
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/screen/find?f=%s", f), &ret)
return
}
func (c *Cli) KBTap(t string) (map[string]interface{}, error) {
/*Envia uma tecla ou teclas para serem clicadas no componente com foco onde o robo é executado
@ -213,147 +170,6 @@ func (c *Cli) KBType(t string) (map[string]interface{}, error) {
return ret, err
}
func (c *Cli) KBToggle(str string) error {
err := c.HttpCli().JsonGet("/ipc/wingui/kb/toggle?str="+str, nil)
return err
}
/***************** Display Functions *****************/
func (c *Cli) DisplayRes() (*DEVMODE, error) {
ret := &DEVMODE{}
err := c.HttpCli().JsonGet("/ipc/wingui/display/res", ret)
return ret, err
}
func (c *Cli) DisplaySetRes(d *DEVMODE) error {
err := c.HttpCli().JsonPost("/ipc/wingui/display/setres", d, nil)
return err
}
/***************** Draw Functions *****************/
func (c *Cli) DrawCLear() error {
err := c.HttpCli().JsonGet("/ipc/draw/clear", nil)
return err
}
func (c *Cli) DrawBox(x, y, w, h, t int) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/draw/addbox?x=%d&y=%d&w=%d&h=%d&t=%d", x, y, w, h, t), nil)
return err
}
func (c *Cli) DrawRect(x, y, w, h int) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/draw/addrect?x=%d&y=%d&w=%d&h=%d", x, y, w, h), nil)
return err
}
func (c *Cli) DrawAddText(t string, x, y int) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/draw/addtext?t=%s&x=%d&y=%d", t, x, y), nil)
return err
}
/***************** Notify Functions *****************/
func (c *Cli) NotifyAlert(msg, title string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/notify/alert?msg=%s&title=%s", msg, title), nil)
return err
}
func (c *Cli) NotifyBeep(msg, title string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/notify/notify?msg=%s&title=%s", msg, title), nil)
return err
}
/***************** Window Functions *****************/
func (c *Cli) WindowList(s string) (ret []map[string]interface{}, err error) {
err = c.HttpCli().JsonGet("/ipc/wingui/window/list?s="+s, &ret)
return ret, err
}
func (c *Cli) WindowHwnd(s string) (ret []int, err error) {
err = c.HttpCli().JsonGet("/ipc/wingui/window/hwnd?s="+s, &ret)
return ret, err
}
func (c *Cli) WindowActivate(Hwnd string) error {
err := c.HttpCli().JsonGet("/ipc/wingui/window/activate?Hwnd="+Hwnd, nil)
return err
}
func (c *Cli) WindowClose(Hwnd string) error {
err := c.HttpCli().JsonGet("/ipc/wingui/window/close?Hwnd="+Hwnd, nil)
return err
}
func (c *Cli) WindowMax(Hwnd string) error {
err := c.HttpCli().JsonGet("/ipc/wingui/window/max?Hwnd="+Hwnd, nil)
return err
}
func (c *Cli) WindowMin(Hwnd string) error {
err := c.HttpCli().JsonGet("/ipc/wingui/window/min?Hwnd="+Hwnd, nil)
return err
}
func (c *Cli) WindowActiveHwnd() (ret int, err error) {
err = c.HttpCli().JsonGet("/ipc/wingui/window/activehwnd", &ret)
return ret, err
}
func (c *Cli) WindowWaitActiveTitle(t string, m int) (ret map[string]interface{}, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/window/waitactivetitle?t=%s&m=%d", t, m), &ret)
return ret, err
}
func (c *Cli) WindowActiveTitle() (ret string, err error) {
err = c.HttpCli().JsonGet("/ipc/wingui/window/activetitle", &ret)
return ret, err
}
/*func (c *Cli) WindowWinfo(w int) (ret interface{}, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/window/winfo?w=%d", w), &ret)
return ret, err
}
func (c *Cli) WindowSendMsg(w, m string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/window/sendmsg?w=%s&m=%s", w, m), nil)
return err
}
func (c *Cli) WindowPostMsg(w, m string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/window/postmsg?w=%s&m=%s", w, m), nil)
return err
}*/
/***************** Screen Functions *****************/
func (c *Cli) ScreenCapture(x, y, w, h int, f string) (ret interface{}, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/screen/capture?x=%d&y=%d&w=%d&h=%d&f=%s", x, y, w, h, f), &ret)
return ret, err
}
func (c *Cli) ScreenFindAll(f string) (ret map[string]int, err error) {
err = c.HttpCli().JsonGet("/ipc/wingui/screen/findall?f="+f, &ret)
return ret, err
}
func (c *Cli) ScreenClick(f string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/screen/click?f=%s", f), nil)
return err
}
func (c *Cli) ScreenClickCenter(f string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/screen/clickcenter?f=%s", f), nil)
return err
}
func (c *Cli) ScreenFind(f string) (ret []interface{}, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/screen/find?f=%s", f), &ret)
return
}
func (c *Cli) ScreenWait(f string, m int) ([]byte, error) {
url := fmt.Sprintf("/ipc/wingui/screen/wait?f=%s&m=%d", f, m)
@ -364,7 +180,6 @@ func (c *Cli) ScreenWait(f string, m int) ([]byte, error) {
fmt.Println(ret)
return ret, err
}
func (c *Cli) ScreenWaitClick(f string, m int) ([]byte, error) {
url := fmt.Sprintf("/ipc/wingui/screen/waitclick?f=%s&m=%d", f, m)
@ -375,7 +190,6 @@ func (c *Cli) ScreenWaitClick(f string, m int) ([]byte, error) {
fmt.Println(ret)
return ret, err
}
func (c *Cli) ScreenWaitClickCenter(f string, m int) ([]byte, error) {
url := fmt.Sprintf("/ipc/wingui/screen/waitclickcenter?f=%s&m=%d", f, m)
@ -388,7 +202,7 @@ func (c *Cli) ScreenWaitClickCenter(f string, m int) ([]byte, error) {
}
func (c *Cli) ScreenRes() ([]byte, error) {
url := "/ipc/wingui/screen/res"
url := fmt.Sprintf("/ipc/wingui/screen/res")
ret, err := c.HttpCli().RawGet(url)
if err != nil {
@ -396,146 +210,11 @@ func (c *Cli) ScreenRes() ([]byte, error) {
}
return ret, err
}
func (c *Cli) ScreenSetRes(x, y, cor int) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/screen/setres?x=%d&y=%d&c=%d", x, y, cor), nil)
return err
}
func (c *Cli) ScreenScale() (ret []int, err error) {
err = c.HttpCli().JsonGet("/ipc/wingui/screen/scale", &ret)
return ret, err
}
func (c *Cli) ScreenSize() (ret []int, err error) {
err = c.HttpCli().JsonGet("/ipc/wingui/screen/size", &ret)
return ret, err
}
func (c *Cli) ScreenShot(frmt string) (ret []byte, err error) {
url := fmt.Sprintf("/ipc/wingui/screen/shot?fmt=%s", frmt)
ret, err = c.HttpCli().RawGet(url)
if err != nil {
fmt.Print(err.Error())
}
return ret, err
}
func (c *Cli) ScreenDsInternal() error {
err := c.HttpCli().JsonGet("/ipc/wingui/screen/dsinternal", nil)
return err
}
func (c *Cli) ScreenDsExternal() error {
err := c.HttpCli().JsonGet("/ipc/wingui/screen/dsexternal", nil)
return err
}
func (c *Cli) ScreenDsClone() error {
err := c.HttpCli().JsonGet("/ipc/wingui/screen/dsclone", nil)
return err
}
func (c *Cli) ScreenDsExtend() error {
err := c.HttpCli().JsonGet("/ipc/wingui/screen/dsextend", nil)
return err
}
/***************** Dialog Functions *****************/
func (c *Cli) DialogColor(t, d string) (ret map[string]int, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/dialog/color?t=%s&d=%s", t, d), &ret)
return ret, err
}
func (c *Cli) DialogDate(t, m, d, f string) (ret string, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/dialog/date?t=%s&m=%s&d=%s&f=%s", t, m, d, f), &ret)
return ret, err
}
func (c *Cli) DialogEntry(t, m, d string) (ret string, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/dialog/entry?t=%s&m=%s&d=%s", t, m, d), &ret)
return ret, err
}
func (c *Cli) DialogError(t, m string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/dialog/error?t=%s&m=%s", t, m), nil)
return err
}
func (c *Cli) DialogFile(t, f, d string) (ret string, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/dialog/file?t=%s&f=%s&d=%s", t, f, d), &ret)
return ret, err
}
func (c *Cli) DialogFileMulti(t, f string) (ret []string, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/dialog/filemulti?t=%s&f=%s", t, f), &ret)
return ret, err
}
func (c *Cli) DialogInfo(t, m string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/dialog/info?t=%s&m=%s", t, m), nil)
return err
}
func (c *Cli) DialogList(t, m, f string) (ret string, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/dialog/list?t=%s&m=%s&f=%s", t, m, f), &ret)
return ret, err
}
func (c *Cli) DialogListMulti(t, m, f string) (ret []string, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/dialog/listmulti?t=%s&m=%s&f=%s", t, m, f), &ret)
return ret, err
}
func (c *Cli) DialogPassword(t, m string) (ret string, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/dialog/password?t=%s&m=%s", t, m), &ret)
return ret, err
}
func (c *Cli) DialogQuestion(t, m string) (ret bool, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/dialog/question?t=%s&m=%s", t, m), &ret)
return ret, err
}
func (c *Cli) DialogWarn(t, m string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/dialog/warn?t=%s&m=%s", t, m), nil)
return err
}
/***************** Process Functions *****************/
func (c *Cli) ProcAll() (ret []map[string]interface{}, err error) {
err = c.HttpCli().JsonGet("/ipc/wingui/proc/all", &ret)
return ret, err
}
func (c *Cli) ProcPids() (ret []int, err error) {
err = c.HttpCli().JsonGet("/ipc/wingui/proc/pids", &ret)
return ret, err
}
func (c *Cli) ProcKill(cmd int) (ret string, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/proc/kill?cmd=%d", cmd), &ret)
return ret, err
}
func (c *Cli) ProcExec(cmd string) error {
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/proc/exec?cmd=%s", cmd), nil)
return err
}
func (c *Cli) ProcName(pid int) (ret string, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/proc/name?pid=%d", pid), &ret)
return ret, err
}
func (c *Cli) ProcPath(pid int) (ret string, err error) {
err = c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/proc/path?pid=%d", pid), &ret)
return ret, err
}
func NewCli() *Cli {
ret := &Cli{ApiCli: api.NewApiCli()}
return ret

15
go.mod
View File

@ -6,9 +6,20 @@ go 1.17
// go.digitalcircle.com.br/open/httpcli => ../httpcli
//)
require (
github.com/Microsoft/go-winio v0.5.2
github.com/Microsoft/go-winio v0.5.1
github.com/gorilla/websocket v1.4.2
github.com/mitchellh/go-ps v1.0.0
github.com/nats-io/nats.go v1.13.1-0.20211018182449-f2416a8b1483
go.digitalcircle.com.br/open/httpcli v0.0.0-20211031093505-ecf33aed8afb
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
golang.org/x/sys v0.0.0-20211031064116-611d5d643895 // indirect
)
require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/nats-io/nats-server/v2 v2.6.4 // indirect
github.com/nats-io/nkeys v0.3.0 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
golang.org/x/mod v0.5.1 // indirect
google.golang.org/protobuf v1.27.1 // indirect
)

65
go.sum
View File

@ -1,29 +1,70 @@
github.com/Microsoft/go-winio v0.5.0 h1:Elr9Wn+sGKPlkaBvwu4mTrxtmOp3F3yV9qhaHbXGjwU=
github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s=
github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0=
github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
github.com/nats-io/jwt/v2 v2.1.0 h1:1UbfD5g1xTdWmSeRV8bh/7u+utTiBsRtWhLl1PixZp4=
github.com/nats-io/jwt/v2 v2.1.0/go.mod h1:0tqz9Hlu6bCBFLWAASKhE5vUA4c24L9KPUUgvwumE/k=
github.com/nats-io/nats-server/v2 v2.6.4 h1:WjR1ylV/5Urth88K8U78wEEnWFYEJ9DNM0Q5DTlTx0g=
github.com/nats-io/nats-server/v2 v2.6.4/go.mod h1:LlMieumxNUnCloOTVFv7Wog0YnasScxARUMXVXv9/+M=
github.com/nats-io/nats.go v1.13.1-0.20211018182449-f2416a8b1483 h1:GMx3ZOcMEVM5qnUItQ4eJyQ6ycwmIEB/VC/UxvdevE0=
github.com/nats-io/nats.go v1.13.1-0.20211018182449-f2416a8b1483/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
go.digitalcircle.com.br/open/httpcli v0.0.0-20211010235458-74d201454158 h1:vFm0G1b4hBDJ7y/s2NqRuX99lwuI8/sxxH3XLUOdi0o=
go.digitalcircle.com.br/open/httpcli v0.0.0-20211010235458-74d201454158/go.mod h1:e/6vw7F4vgfs+ThQoLeBbYCYLTH1b5thzFwkFixi+oA=
go.digitalcircle.com.br/open/httpcli v0.0.0-20211031093505-ecf33aed8afb h1:gv0FO26InL2ctmhCqthsOFEooi0FvA1rFT6VXzgveJE=
go.digitalcircle.com.br/open/httpcli v0.0.0-20211031093505-ecf33aed8afb/go.mod h1:e/6vw7F4vgfs+ThQoLeBbYCYLTH1b5thzFwkFixi+oA=
golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac h1:oN6lz7iLW/YC7un8pq+9bOLyXrprv2+DKfkJY+2LJJw=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211031064116-611d5d643895 h1:iaNpwpnrgL5jzWS0vCNnfa8HqzxveCFpFx3uC/X4Tps=
golang.org/x/sys v0.0.0-20211031064116-611d5d643895/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211106132015-ebca88c72f68 h1:Ywe/f3fNleF8I6F6qv3MeFoSZ6CTf2zBMMa/7qVML8M=
golang.org/x/sys v0.0.0-20211106132015-ebca88c72f68/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 h1:nhht2DYV/Sn3qOayu8lM+cU1ii9sTLUeBQwQQfUHtrs=
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI=
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=

154
svc/lib.go 100644
View File

@ -0,0 +1,154 @@
package svc
import (
"encoding/json"
"errors"
"fmt"
"github.com/nats-io/nats.go"
"log"
"os"
"reflect"
"strings"
"time"
"unicode"
)
var nc *nats.Conn
var compname string
func Init(s string) error {
var err error
compname = s
var apikey string
if nc == nil {
apikey = os.Getenv("REPLAY_APIKEY")
if apikey == "" {
log.Printf("Connecting to NATS Server w/o TK.")
nc, err = nats.Connect(nats.DefaultURL, nats.Name(compname))
} else {
log.Printf("Connecting to NATS Server w TK: " + apikey)
nc, err = nats.Connect(nats.DefaultURL, nats.Name(compname), nats.Token(apikey))
}
if err != nil {
return err
}
}
return err
}
func Close() error {
err := nc.Drain()
chEnd <- struct{}{}
return err
}
var chEnd chan struct{}
func Serve() {
chEnd = make(chan struct{})
<-chEnd
}
func NormalizeName(s string) string {
sb := strings.Builder{}
for i, v := range s {
if unicode.IsUpper(v) && i != 0 {
sb.WriteString(".")
}
sb.WriteRune(unicode.ToLower(v))
}
return sb.String()
}
func Register(h interface{}) {
var err error
tp := reflect.TypeOf(h)
for i := 0; i < tp.NumMethod(); i++ {
mtd := tp.Method(i)
mtdt := mtd.Type
intp := mtdt.In(1)
isPtr := false
if intp.Kind() == reflect.Ptr {
isPtr = true
intp = intp.Elem()
}
mn := NormalizeName(compname) + "." + NormalizeName(mtd.Name)
err = nc.Publish("sub", []byte(mn))
if err != nil {
log.Printf(err.Error())
}
_, err = nc.Subscribe(mn, func(msg *nats.Msg) {
ni := reflect.New(intp).Interface()
var err error
if intp.Kind() == reflect.Ptr {
err = json.Unmarshal(msg.Data, ni)
} else {
err = json.Unmarshal(msg.Data, &ni)
}
if err != nil {
log.Printf(err.Error())
}
var rawret []reflect.Value
if isPtr {
rawret = mtd.Func.Call([]reflect.Value{reflect.ValueOf(h), reflect.ValueOf(ni)})
} else {
rawret = mtd.Func.Call([]reflect.Value{reflect.ValueOf(h), reflect.ValueOf(ni).Elem()})
}
ret := rawret[0].Interface()
err1 := rawret[1].Interface()
//if err1 != nil {
// log.Printf(err1.(error).Error())
//}
var bs []byte
rmsg := &nats.Msg{}
rmsg.Data = bs
bs, err = json.Marshal(ret)
if err1 != nil {
rmsg.Header = nats.Header{}
rmsg.Header.Set("ERR", fmt.Sprintf("%#v", err1))
}
if err != nil {
log.Printf(err.Error())
}
rmsg.Data = bs
err = msg.RespondMsg(rmsg)
if err != nil {
log.Printf(err.Error())
}
})
if err != nil {
log.Printf(err.Error())
}
if err != nil {
nc.Publish("err", []byte(err.Error()))
}
}
}
func Nc() *nats.Conn {
return nc
}
func Call(s string, in interface{}, out interface{}) error {
bs, err := json.Marshal(in)
if err != nil {
return err
}
msg, err := nc.Request(s, bs, time.Minute)
if err != nil {
return err
}
err = json.Unmarshal(msg.Data, out)
if err != nil {
return err
}
errstr := msg.Header.Get("ERR")
if errstr != "" {
return errors.New(errstr)
}
return nil
}

View File

@ -214,11 +214,7 @@ type Log struct {
}
func (l *Log) Write(p []byte) (n int, err error) {
_, err = os.Stdout.Write([]byte(fmt.Sprintf("- %s\n", string(p))))
if err != nil {
println(fmt.Sprintf("Log.Write:: Error writing log: %s", err.Error()))
return 0, err
}
os.Stdout.Write([]byte(fmt.Sprintf("- %s\n", string(p))))
l.AddHistory(string(p))
return len(p), nil
}
@ -232,11 +228,6 @@ func (l *Log) AddHistory(s string) {
}
}
func (l *Log) Printf(s string, i ...interface{}) {
l.AddHistory(fmt.Sprintf(s, i...))
s = fmt.Sprintf("* %s: %s", time.Now().Format("02/01/06 - 15:04:05"), s)
}
type LogQuery struct {
From time.Time `json:"from"`
Until time.Time `json:"until"`
@ -312,11 +303,9 @@ type Cron struct {
Model
Cron string `json:"cron"`
JobCode uint `json:"job"`
JobAlias string `json:"jobalias" gorm:"-"`
Enabled *bool `json:"enabled"`
Data string `json:"data"`
Comments string `json:"comments"`
Once bool `json:"once"`
}
//type Resource struct {

30
ver/lib.go 100644
View File

@ -0,0 +1,30 @@
package ver
import (
"golang.org/x/mod/semver"
"log"
"os"
)
var Ver string
func EnsureVer(v string) {
build := os.Getenv("BUILD_VER")
if build == "" {
log.Printf("No BUILD_VER found - skipping verification")
return
}
if semver.Compare(build, v) < 0 {
log.Printf("Replay version is %s, lower than required. Should be minimum %s - aborting", build, v)
os.Exit(0)
}
if semver.Major(build) != semver.Major(v) {
log.Printf("Replay major version is %s, different from feature requirement: %s - aborting", build, v)
}
}
func Get() string {
if Ver == "" {
Ver = os.Getenv("BUILD_VER")
}
return Ver
}