Compare commits

...

106 Commits

Author SHA1 Message Date
Pedro de Oliveira Guedes 07c484d31d Updating packages. 2022-03-04 14:24:58 -03:00
Pedro de Oliveira Guedes cdf0c422a3 Fixing the QueueGetMyJson function by using pointers. 2022-03-04 14:23:27 -03:00
Paulo Simão 18801a7b94 added QueueGetDataBody 2022-03-03 13:34:42 -03:00
Paulo Simão 03930d5821 Merge branch 'master' of ssh://gitea.digitalcircle.com.br:2222/open/replaycli-go 2022-03-03 03:26:18 -03:00
Paulo Simão 60128fb729 add jobalias to cron 2022-03-03 03:24:27 -03:00
Leonardo Domingues c032f74806 FindUrl 2022-03-01 14:35:17 -03:00
Paulo Simão 98605a3f9b Added QueueWData and QueueWDataWait to cli. Added Once prop to cron (these will be removed upon execution) 2022-03-01 08:05:11 -03:00
Leonardo Domingues fa69db55c8 Captcha identifier 2022-02-09 14:26:25 -03:00
Pedro de Oliveira Guedes 62ad6dcb51 Fixing Image2text method. 2022-01-13 11:02:56 -03:00
Leonardo Domingues 0dff7d0d6a Reversão 2022-01-13 09:49:37 -03:00
Leonardo Domingues dea0595735 . 2022-01-13 09:25:07 -03:00
Leonardo Domingues eb9f833027 Hcaptcha 2022-01-12 18:05:08 -03:00
Pedro de Oliveira Guedes 13626dcde9 Fixing recatcha-v2 and image2text methods. 2021-12-28 12:51:01 -03:00
Pedro de Oliveira Guedes d5c986df8e Fixing chromeSend. 2021-12-28 12:49:57 -03:00
Leonardo Domingues 58fbb932aa Merge branch 'master' of ssh://gitea.digitalcircle.com.br:2222/open/replaycli-go 2021-12-16 16:54:16 -03:00
Leonardo Domingues c9f9a37bc3 Type change 2021-12-16 16:54:10 -03:00
Pedro de Oliveira Guedes 216d2a0851 Fixing test method 2021-12-16 15:03:40 -03:00
Leonardo Domingues 18173ed486 Merge branch 'master' of ssh://gitea.digitalcircle.com.br:2222/open/replaycli-go 2021-12-16 11:08:16 -03:00
Leonardo Domingues 7d1b743b27 Api_Key correction 2021-12-16 11:08:10 -03:00
Pedro de Oliveira Guedes adeb3ae60d Fixing do method. 2021-12-16 09:38:12 -03:00
Pedro de Oliveira Guedes cc26a118a4 Fixing test method. 2021-12-16 08:54:53 -03:00
Leonardo Domingues 2e48c5b2a6 Merge branch 'master' of ssh://gitea.digitalcircle.com.br:2222/open/replaycli-go 2021-12-15 10:44:33 -03:00
Leonardo Domingues f951956db5 AHK and Autoit implemented 2021-12-15 10:44:27 -03:00
Pedro de Oliveira Guedes 0b006b8243 Merge branch 'master' of ssh://gitea.digitalcircle.com.br:2222/open/replaycli-go 2021-12-09 10:33:27 -03:00
Pedro de Oliveira Guedes 2257f3f349 Adicionando comentários para as funções. 2021-12-09 10:30:53 -03:00
Leonardo Domingues b727ad8d39 Fixes 2021-12-07 17:43:32 -03:00
Leonardo Domingues f5f555936b Request fixed 2021-12-07 17:33:39 -03:00
Leonardo Domingues bd3bcefcc2 Type correction 2021-12-07 11:00:51 -03:00
Pedro de Oliveira Guedes 05f2b34703 Deleting entry parameters from "ScreenDs" methods. 2021-12-07 08:30:40 -03:00
Pedro de Oliveira Guedes f6853bc03c Merge branch 'master' of ssh://gitea.digitalcircle.com.br:2222/open/replaycli-go 2021-12-06 15:38:39 -03:00
Leonardo Domingues f54514a87a ScreenShot method -> Fixed 2021-12-06 15:37:55 -03:00
Leonardo Domingues b8e5810103 Proc Methods 2021-12-06 15:15:37 -03:00
Pedro de Oliveira Guedes d84ad7763c Fixing the "ScreenShot" method. 2021-12-06 14:51:06 -03:00
Leonardo Domingues 59e4b137c5 Dialog Methods 2021-12-03 18:14:18 -03:00
Leonardo Domingues 7771f50e1b KB methods 2021-12-03 15:54:05 -03:00
Leonardo Domingues 126ef1e289 Screen Methods 2021-12-03 13:31:00 -03:00
Leonardo Domingues 6bc18cedef New screen methods added 2021-12-03 13:04:03 -03:00
Leonardo Domingues 048c8e0b4e clean 2021-12-03 12:30:25 -03:00
Leonardo Domingues 64d94b13f7 Adição da função Capture 2021-12-03 11:44:32 -03:00
Leonardo Domingues 69d0bdf3e8 Correção de tipos 2021-12-03 10:52:39 -03:00
Leonardo Domingues ade994dac8 Bug fix 2021-12-03 10:50:47 -03:00
Leonardo Domingues 6c1c483496 Correção nos tipos 2021-12-03 10:28:21 -03:00
Leonardo Domingues c03689b9fc Alteração nas variáveis de retorno 2021-12-02 18:35:00 -03:00
Leonardo Domingues 6c981f4196 Correção dos tipos de variável 2021-12-01 17:19:03 -03:00
Leonardo Domingues 393154a0ac Att 2021-12-01 17:12:14 -03:00
Leonardo Domingues 4cfbe8f072 Definição de tipo 2021-12-01 17:08:38 -03:00
Leonardo Domingues 9877e1819c Merge branch 'master' of ssh://gitea.digitalcircle.com.br:2222/open/replaycli-go 2021-12-01 15:27:12 -03:00
Leonardo Domingues 0363cfc1bc Window Methods 2021-12-01 15:27:04 -03:00
Pe-Guedss 992fe90efb Merge branch 'master' of ssh://gitea.digitalcircle.com.br:2222/open/replaycli-go 2021-12-01 14:27:35 -03:00
Pe-Guedss ed392fd245 Fixing ClipRead function (from json to raw). 2021-12-01 14:17:18 -03:00
Leonardo Domingues 44f39c7c16 Notify Methods 2021-12-01 11:22:31 -03:00
Leonardo Domingues e0f1a0ddd4 Correção de bugs 2021-11-29 12:11:14 -03:00
Leonardo Domingues ee65505e8f Drawing methods implemented 2021-11-29 12:04:09 -03:00
Leonardo Domingues f3f5e80160 Methods: Get chrome tabs (all, by url, by title) 2021-11-29 12:02:23 -03:00
Paulo Simão 571810c476 add comments 2021-11-29 10:45:25 -03:00
Paulo Simão befca816d5 add printf to log 2021-11-29 10:44:03 -03:00
Paulo Simão bca0854a85 improvements 2021-11-25 16:50:15 -03:00
Paulo Simão d80a2568ac Merge remote-tracking branch 'origin/master'
# Conflicts:
#	api/dataapi/lib_test.go
2021-11-25 16:49:42 -03:00
Paulo Simão aee712a88a improvements 2021-11-25 16:49:24 -03:00
Leonardo Domingues 17d68433dc Eliminação do lib_test e atualização da key 2021-11-25 13:51:25 -03:00
Leonardo Domingues 59f6b2578a Merge branch 'master' of ssh://gitea.digitalcircle.com.br:2222/open/replaycli-go 2021-11-25 10:50:42 -03:00
Leonardo Domingues 3504facc2e Correções 2021-11-25 10:50:33 -03:00
Paulo Simão ccae321dc9 Merge remote-tracking branch 'origin/master' 2021-11-20 09:21:29 -03:00
Paulo Simão 990ac72c52 add apiproxy 2021-11-20 09:21:22 -03:00
Leonardo Domingues eaaa1a6224 Inclusão de erro 2021-11-09 09:43:25 -03:00
Leonardo Domingues 0b6a1179a1 Merge branch 'master' of ssh://gitea.digitalcircle.com.br:2222/open/replaycli-go 2021-11-08 10:32:36 -03:00
Leonardo Domingues a8daeabffb Função para contar execuções mensais de robôs 2021-11-08 10:32:29 -03:00
Paulo Simão 2543c4bf9a added wingui-display cli 2021-11-06 13:55:42 -03:00
Leonardo Domingues f8acbf0c03 Adição da função 2021-11-05 18:09:09 -03:00
Leonardo Domingues 6ef42d1ccb Implementação de Registro simplificado da LCR 2021-11-05 18:03:02 -03:00
Paulo Simão c80d8b1095 added res,setres - fix ScreenWait return (raw, not json) 2021-11-05 13:59:52 -03:00
Paulo Simão 9fcc1cccd7 added dataapi 2021-11-05 10:13:48 -03:00
Paulo Simão 56927666ef fixed prop name 2021-11-05 10:11:04 -03:00
Paulo Simão ac706b9d72 fixed prop name 2021-11-04 17:21:52 -03:00
Paulo Simão a010f26d67 fix ocr 2021-11-04 13:05:27 -03:00
Paulo Simão a1ee372710 fix url 2021-11-03 19:33:25 -03:00
Paulo Simão a58c2b340c fix url 2021-10-31 19:57:02 -03:00
Paulo Simão cfbfdd77d5 Fix getmenus 2021-10-31 19:56:25 -03:00
Paulo Simão e572aae2a2 Fix getmenus 2021-10-31 19:48:31 -03:00
Paulo Simão 74dc132b2b Add OCR 2021-10-31 06:37:05 -03:00
Paulo Simão a9dacee062 Added error 2021-10-16 08:50:00 -03:00
Paulo Simão 6eda8f5249 added pre-cmds 2021-10-16 06:30:29 -03:00
Paulo Simão c573402bc0 Adicionados dados para cron 2021-10-14 13:29:30 -03:00
Paulo Simão 84ddbfbe69 transform log in writer 2021-10-14 06:56:11 -03:00
Paulo Simão 9602c569ec transform log in writer 2021-10-14 06:24:39 -03:00
Paulo Simão a6a48c459b added global config 2021-10-11 19:08:32 -03:00
Paulo Simão d12b549846 added log history 2021-10-11 18:38:44 -03:00
Paulo Simão 392c7940af added getmyjson to replaycli 2021-10-11 18:21:47 -03:00
Paulo Simão f3abaa694d forgot tags on log - lame me. 2021-10-11 15:11:42 -03:00
Paulo Simão 2a9dd021e6 fix path 2021-10-11 15:05:01 -03:00
Paulo Simão 53a53bd1ca add err and stack to log 2021-10-11 14:58:09 -03:00
Paulo Simão 8fb8bb502e added log table 2021-10-11 14:53:32 -03:00
Paulo Simão d06e5bceae fix deps 2021-10-11 13:28:04 -03:00
Paulo Simão 3a7cad4f12 added configgetmap 2021-10-11 12:31:54 -03:00
Paulo Simão bf8aaa2ca0 separated httpcli from replaycli. Added config methods 2021-10-11 11:53:57 -03:00
Paulo Simão 4e142e5300 separated httpcli from replaycli. Added config methods 2021-10-11 11:53:44 -03:00
Paulo Simão 7d8e31240e added public prop 2021-10-10 13:50:12 -03:00
Paulo Simão 5ee19adae4 Update 'types/lib.go' 2021-10-10 16:34:33 +00:00
Paulo Simão 42df57854b fix requests 2021-10-10 13:15:15 -03:00
Paulo Simão e0a0904c90 fix queueadd 2021-10-10 06:05:27 -03:00
Paulo Simão 55bef831c2 Added env access to replaycli 2021-10-10 05:41:47 -03:00
Paulo Simão c4e964e115 closing now properly the connection 2021-10-07 07:48:15 +00:00
Paulo Simão 23d1d9dd1d added close 2021-10-07 04:32:21 -03:00
Paulo Simão 284cc4eb1a Merge pull request 'Ampliação da API Wingui' (#2) from samuel.miranda into master
Reviewed-on: https://gitea.digitalcircle.com.br:443/open/replaycli-go/pulls/2
2021-10-06 16:59:01 +00:00
Samuel Miranda 2bdb994cab Remoção do OCR do processo Wingui 2021-10-06 13:56:21 -03:00
Samuel Miranda 2a959b9938 Teste 2021-10-06 13:46:47 -03:00
20 changed files with 1483 additions and 251 deletions

View File

@ -5,17 +5,19 @@ import (
)
type Cli struct {
cli *api.Cli
*api.ApiCli
//cli *api.Cli
}
func (c *Cli) HttpCli() *api.Cli {
return c.cli
}
//func (c *Cli) HttpCli() *api.Cli {
//
// return c.HttpCli()
//}
type Req struct {
Site string `json:"site"`
Data string `json:"data"`
Img []byte `json:"img"`
Img string `json:"img"`
To int `json:"to"`
}
@ -24,25 +26,37 @@ func (c *Cli) Recaptchav2(site string, data string) (string, error) {
req := &Req{
Site: site,
Data: data,
Img: nil,
Img: "",
To: 300,
}
err := c.cli.HttpJsonPost("/ipc/anticaptcha/recaptchav2", req, &ret)
err := c.HttpCli().JsonPost("/ipc/anticaptcha/recaptchav2", req, &ret)
return ret, err
}
func (c *Cli) Image2text(site string, data []byte) (string, error) {
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) {
ret := ""
req := &Req{
Site: site,
Img: data,
To: 300,
}
err := c.cli.HttpJsonPost("/ipc/anticaptcha/image2text", req, &ret)
err := c.HttpCli().JsonPost("/ipc/anticaptcha/image2text", req, &ret)
return ret, err
}
func NewCli() *Cli {
ret := &Cli{cli: api.NewCli()}
ret := &Cli{ApiCli: api.NewApiCli()}
return ret
}

View File

@ -0,0 +1,34 @@
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

@ -0,0 +1,22 @@
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

@ -0,0 +1,25 @@
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
}

25
api/autoit/cli.go 100644
View File

@ -0,0 +1,25 @@
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,63 +3,108 @@ package chrome
import (
"encoding/json"
"fmt"
"go.digitalcircle.com.br/open/replaycli-go/api"
)
type Cli struct {
cli *api.Cli
*api.ApiCli
}
func (c *Cli) HttpCli() *api.Cli {
return c.cli
type TabMetadata struct {
Description string `json:"description"`
DevtoolsFrontendUrl string `json:"devtoolsFrontendUrl"`
Id string `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
Url string `json:"url"`
WebSocketDebuggerUrl string `json:"webSocketDebuggerUrl"`
}
func (c *Cli) Start(to int) error {
err := c.cli.HttpJsonGet(fmt.Sprintf("/ipc/chrome/start?to=%d", to), nil)
// 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
}
func (c *Cli) StartHeadless() error {
err := c.cli.HttpJsonGet("/ipc/chrome/startHeadless", nil)
err := c.HttpCli().JsonGet("/ipc/chrome/startHeadless", nil)
return err
}
func (c *Cli) Stop() error {
err := c.cli.HttpJsonGet("/ipc/chrome/stop", nil)
err := c.HttpCli().JsonGet("/ipc/chrome/stop", nil)
return err
}
func (c *Cli) New(url string) (string, error) {
// url -> Site no qual se quer iniciar uma nova aba.
ret := ""
err := c.cli.HttpJsonGet(fmt.Sprintf("/ipc/chrome/new?url=%s", url), &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 {
err := c.cli.HttpJsonGet("/ipc/chrome/close/"+id, nil)
// 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.cli.HttpRawPost("/ipc/chrome/eval/"+id, []byte(s))
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.cli.HttpRawPost(fmt.Sprintf("/ipc/chrome/wait/%s?to=%d", id, to), []byte(s))
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{}) (string, error) {
ret := ""
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{}
in := map[string]interface{}{
"method": m,
"params": ps,
}
err := c.cli.HttpJsonPost("/ipc/chrome/eval/"+id, in, &ret)
err := c.HttpCli().JsonPost("/ipc/chrome/send/"+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{cli: api.NewCli()}
ret := &Cli{ApiCli: api.NewApiCli()}
return ret
// ret -> Nova instância do Chrome para utilização.
}

View File

@ -1,144 +1,32 @@
package api
import (
"bytes"
"encoding/json"
"io"
"net/http"
"go.digitalcircle.com.br/open/httpcli"
"go.digitalcircle.com.br/open/replaycli-go/ipcmux"
"go.digitalcircle.com.br/open/replaycli-go/util"
"os"
"strings"
)
type Cli struct {
cli *http.Client
headers map[string]string
type ApiCli struct {
cli *httpcli.Cli
}
func (c *Cli) Addr() string {
ret := os.Getenv("REPLAY_ADDR")
if ret == "" {
ret = "https://localhost:8443"
} else if strings.HasPrefix(ret, ":") {
ret = "https://localhost" + ret
}
return ret
}
func (c *Cli) AddHeader(k string, v string) {
c.headers[k] = v
}
func (c *Cli) DelHeader(k string) {
delete(c.headers, k)
}
func (c *Cli) HttpDo(method string, strurl string, body []byte) (*http.Response, error) {
if !strings.HasPrefix(strurl, "http") {
addr := c.Addr()
if strings.HasSuffix(addr, "/") {
addr = addr[:len(addr)-1]
}
if !strings.HasPrefix(strurl, "") {
strurl = "/" + strurl
}
strurl = addr + strurl
}
req, err := http.NewRequest(method, strurl, bytes.NewReader(body))
if err != nil {
return nil, err
}
if c.headers != nil {
for k, v := range c.headers {
req.Header.Set(k, v)
}
}
if body != nil && len(body) > 0 {
req, err = http.NewRequest(method, strurl, io.NopCloser(bytes.NewReader(body)))
} else {
req, err = http.NewRequest(method, strurl, nil)
}
if err != nil {
return nil, err
}
req.Header.Set("X-API-KEY", apikey)
req.Header.Set("Content-Type", "application/json")
return c.cli.Do(req)
}
func (c *Cli) HttpDoJson(method string, strurl string, i interface{}, o interface{}) (err error) {
bs, err := json.Marshal(i)
if err != nil {
return err
}
res, err := c.HttpDo(method, strurl, bs)
if err != nil {
return
}
defer res.Body.Close()
if o != nil {
err = json.NewDecoder(res.Body).Decode(o)
}
return
}
func (c *Cli) HttpJsonGet(strurl string, o interface{}) error {
return c.HttpDoJson(http.MethodGet, strurl, nil, o)
}
func (c *Cli) HttpJsonDelete(strurl string, o interface{}) error {
return c.HttpDoJson(http.MethodDelete, strurl, nil, o)
}
func (c *Cli) HttpJsonHead(strurl string, o interface{}) error {
return c.HttpDoJson(http.MethodHead, strurl, nil, o)
}
func (c *Cli) HttpJsonPost(strurl string, i interface{}, o interface{}) error {
return c.HttpDoJson(http.MethodPost, strurl, i, o)
}
func (c *Cli) HttpJsonPut(strurl string, i interface{}, o interface{}) error {
return c.HttpDoJson(http.MethodPut, strurl, i, o)
}
func (c *Cli) HttpJsonPatch(strurl string, i interface{}, o interface{}) error {
return c.HttpDoJson(http.MethodPatch, strurl, i, o)
}
func (c *Cli) HttpRawGet(strurl string) ([]byte, error) {
res, err := c.HttpDo(http.MethodGet, strurl, nil)
if err != nil {
return nil, err
}
defer res.Body.Close()
bs, _ := io.ReadAll(res.Body)
return bs, nil
}
func (c *Cli) HttpRawDelete(strurl string) ([]byte, error) {
res, err := c.HttpDo(http.MethodDelete, strurl, nil)
if err != nil {
return nil, err
}
defer res.Body.Close()
bs, _ := io.ReadAll(res.Body)
return bs, nil
}
func (c *Cli) HttpRawPost(strurl string, i []byte) ([]byte, error) {
res, err := c.HttpDo(http.MethodPost, strurl, i)
if err != nil {
return nil, err
}
defer res.Body.Close()
bs, _ := io.ReadAll(res.Body)
return bs, nil
}
func (c *Cli) HttpRawPut(strurl string, i []byte) ([]byte, error) {
res, err := c.HttpDo(http.MethodPut, strurl, i)
if err != nil {
return nil, err
}
defer res.Body.Close()
bs, _ := io.ReadAll(res.Body)
return bs, nil
func (a *ApiCli) HttpCli() *httpcli.Cli {
return a.cli
}
func NewCli() *Cli {
func NewApiCli() *ApiCli {
ret := &ApiCli{cli: httpcli.C()}
ret.cli.SetBasePath(util.Addr())
apikey = os.Getenv("REPLAY_APIKEY")
ret := &Cli{
cli: &http.Client{},
headers: make(map[string]string),
}
ret.AddHeader("X-API-KEY", apikey)
ret.cli.AddHeader("X-API-KEY", apikey)
return ret
}
func NewApiIPCCli() *ApiCli {
ret := &ApiCli{cli: httpcli.NewCli()}
ret.cli.SetCli(ipcmux.NewClient())
apikey = os.Getenv("REPLAY_APIKEY")
ret.cli.AddHeader("X-API-KEY", apikey)
return ret
}

131
api/dataapi/lib.go 100644
View File

@ -0,0 +1,131 @@
package dataapi
import (
"strconv"
"time"
"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 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

@ -0,0 +1,145 @@
package dataapi_test
import (
"log"
"strconv"
"testing"
"time"
"go.digitalcircle.com.br/open/replaycli-go/api/dataapi"
)
func TestAPIRetrieve(t *testing.T) {
c := dataapi.NewCli()
res, err := c.Do(&dataapi.DataAPIRequest{
Col: "teste3",
Op: dataapi.RETRIEVE,
})
if err != nil {
t.Fatal(err.Error())
}
log.Printf("%#v", res)
}
func TestAPIRetrieveWQuery(t *testing.T) {
c := dataapi.NewCli()
res, err := c.Do(&dataapi.DataAPIRequest{
Col: "C1",
Op: dataapi.RETRIEVE,
Q: "@[?ID==`2`]",
})
if err != nil {
t.Fatal(err.Error())
}
log.Printf("%#v", res)
}
func TestAPIUpdate(t *testing.T) {
c := dataapi.NewCli()
res, err := c.Do(&dataapi.DataAPIRequest{
Col: "C1",
Op: dataapi.UPDATE,
Id: "2",
Data: map[string]interface{}{
"F2": "Novo Campo",
},
})
if err != nil {
t.Fatal(err.Error())
}
log.Printf("%#v", res)
}
func TestAPIDelete(t *testing.T) {
c := dataapi.NewCli()
res, err := c.Do(&dataapi.DataAPIRequest{
Col: "C1",
Op: dataapi.DELETE,
Id: "2",
})
if err != nil {
t.Fatal(err.Error())
}
log.Printf("%#v", res)
}
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")
res, err := c.Do(&dataapi.DataAPIRequest{
Col: "teste3",
Op: dataapi.RETRIEVE,
Q: "@[?date=='" + current + "']",
})
if err != nil {
panic(err)
}
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)
}
}
}

View File

@ -5,19 +5,16 @@ import (
)
type Cli struct {
cli *api.Cli
*api.ApiCli
}
func (c *Cli) HttpCli() *api.Cli {
return c.cli
}
func (c *Cli) New(i interface{}) (string, error) {
res := ""
err := c.cli.HttpJsonPost("/ipc/datasyncreportmgr/new", i, &res)
err := c.HttpCli().JsonPost("/ipc/datasyncreportmgr/new", i, &res)
return res, err
}
func NewCli() *Cli {
ret := &Cli{cli: api.NewCli()}
ret := &Cli{ApiCli: api.NewApiCli()}
return ret
}

View File

@ -11,11 +11,7 @@ const (
)
type Cli struct {
cli *api.Cli
}
func (c *Cli) HttpCli() *api.Cli {
return c.cli
*api.ApiCli
}
type Req struct {
@ -32,7 +28,7 @@ func (c *Cli) Read(fname string, sheet string) ([][]string, error) {
Sheet: sheet,
}
res := make([][]string, 0)
err := c.cli.HttpJsonPost("/ipc/excel/read", req, &res)
err := c.HttpCli().JsonPost("/ipc/excel/read", req, &res)
return res, err
}
func (c *Cli) Write(fname string, sheet string, cell string, val string, celtype string) error {
@ -44,21 +40,20 @@ func (c *Cli) Write(fname string, sheet string, cell string, val string, celtype
Celtype: celtype,
}
res := ""
err := c.cli.HttpJsonPost("/ipc/excel/write", req, &res)
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,
Sheet: sheet,
}
res := ""
err := c.cli.HttpJsonPost("/ipc/excel/new", req, &res)
err := c.HttpCli().JsonPost("/ipc/excel/new", req, &res)
return res, err
}
func NewCli() *Cli {
ret := &Cli{cli: api.NewCli()}
ret := &Cli{ApiCli: api.NewApiCli()}
return ret
}

184
api/ocr/cli.go 100644
View File

@ -0,0 +1,184 @@
package ocr
import (
"encoding/xml"
"go.digitalcircle.com.br/open/replaycli-go/api"
"log"
)
const ScreenShot = "ss"
type AltoString struct {
Text string `xml:",chardata"`
ID string `xml:"ID,attr"`
HPOS int `xml:"HPOS,attr"`
VPOS int `xml:"VPOS,attr"`
WIDTH int `xml:"WIDTH,attr"`
HEIGHT int `xml:"HEIGHT,attr"`
WC float64 `xml:"WC,attr"`
CONTENT string `xml:"CONTENT,attr"`
AHPOS int `xml:"AHPOS,attr"`
AVPOS int `xml:"AVPOS,attr"`
AWIDTH int `xml:"AWIDTH,attr"`
AHEIGHT int `xml:"AHEIGHT,attr"`
}
func (a *AltoString) AbsCoords(q *Opts) {
nx := int(float64(a.HPOS)/q.Proportion) + q.X
ny := int(float64(a.VPOS)/q.Proportion) + q.Y
nw := int(float64(a.WIDTH) / q.Proportion)
nh := int(float64(a.HEIGHT) / q.Proportion)
log.Printf("Mapping: x: %v=>%v; y:%v=>%v; w:%v=>%v; h:%v=>%v;(Prop: %v,qx: %v, qy: %v)", a.HPOS, nx, a.VPOS, ny, a.WIDTH, nw, a.HEIGHT, nh, q.Proportion, q.X, q.Y)
a.AHPOS = nx
a.AVPOS = ny
a.AWIDTH = nw
a.AHEIGHT = nh
return
}
type AltoSP struct {
Text string `xml:",chardata"`
WIDTH int `xml:"WIDTH,attr"`
VPOS int `xml:"VPOS,attr"`
HPOS int `xml:"HPOS,attr"`
}
type AltoTextLine struct {
Text string `xml:",chardata"`
ID string `xml:"ID,attr"`
HPOS string `xml:"HPOS,attr"`
VPOS string `xml:"VPOS,attr"`
WIDTH string `xml:"WIDTH,attr"`
HEIGHT string `xml:"HEIGHT,attr"`
String []*AltoString `xml:"String"`
SP []*AltoSP `xml:"SP"`
}
type AltoTextBlock struct {
Text string `xml:",chardata"`
ID string `xml:"ID,attr"`
HPOS int `xml:"HPOS,attr"`
VPOS int `xml:"VPOS,attr"`
WIDTH int `xml:"WIDTH,attr"`
HEIGHT int `xml:"HEIGHT,attr"`
TextLine []*AltoTextLine `xml:"TextLine"`
}
type AltoComposedBlock struct {
Text string `xml:",chardata"`
ID string `xml:"ID,attr"`
HPOS int `xml:"HPOS,attr"`
VPOS int `xml:"VPOS,attr"`
WIDTH int `xml:"WIDTH,attr"`
HEIGHT int `xml:"HEIGHT,attr"`
TextBlock []*AltoTextBlock `xml:"TextBlock"`
}
type AltoPrintSpace struct {
Text string `xml:",chardata"`
HPOS int `xml:"HPOS,attr"`
VPOS int `xml:"VPOS,attr"`
WIDTH int `xml:"WIDTH,attr"`
HEIGHT int `xml:"HEIGHT,attr"`
ComposedBlock []*AltoComposedBlock `xml:"ComposedBlock"`
}
type AltoPage struct {
Text string `xml:",chardata"`
WIDTH int `xml:"WIDTH,attr"`
HEIGHT int `xml:"HEIGHT,attr"`
PHYSICALIMGNR string `xml:"PHYSICAL_IMG_NR,attr"`
ID string `xml:"ID,attr"`
PrintSpace *AltoPrintSpace `xml:"PrintSpace"`
}
type AltoDescription struct {
Text string `xml:",chardata"`
MeasurementUnit string `xml:"MeasurementUnit"`
SourceImageInformation struct {
Text string `xml:",chardata"`
FileName string `xml:"fileName"`
} `xml:"sourceImageInformation"`
OCRProcessing *struct {
Text string `xml:",chardata"`
ID string `xml:"ID,attr"`
OcrProcessingStep struct {
Text string `xml:",chardata"`
ProcessingSoftware struct {
Text string `xml:",chardata"`
SoftwareName string `xml:"softwareName"`
} `xml:"processingSoftware"`
} `xml:"ocrProcessingStep"`
} `xml:"OCRProcessing"`
}
type AltoLayout struct {
Text string `xml:",chardata"`
Page *AltoPage `xml:"Page"`
}
type Alto struct {
XMLName xml.Name `xml:"alto"`
Text string `xml:",chardata"`
Xmlns string `xml:"xmlns,attr"`
Xlink string `xml:"xlink,attr"`
Xsi string `xml:"xsi,attr"`
SchemaLocation string `xml:"schemaLocation,attr"`
Description *AltoDescription `xml:"Description"`
Layout *AltoLayout `xml:"Layout"`
}
func (a *Alto) Strings() []*AltoString {
ret := make([]*AltoString, 0)
for _, v := range a.Layout.Page.PrintSpace.ComposedBlock {
for _, v1 := range v.TextBlock {
for _, v2 := range v1.TextLine {
for _, v3 := range v2.String {
ret = append(ret, v3)
}
}
}
}
return ret
}
func (a *Alto) CalcAbsolute(q *Opts) {
for _, v := range a.Layout.Page.PrintSpace.ComposedBlock {
for _, v1 := range v.TextBlock {
for _, v2 := range v1.TextLine {
for _, v3 := range v2.String {
v3.AbsCoords(q)
}
}
}
}
}
type Opts struct {
Ver string `json:"ver,omitempty"`
X int `json:"x"`
Y int `json:"y"`
H int `json:"h"`
W int `json:"w"`
Blur float64 `json:"blur"`
Sharpen float64 `json:"sharpen"`
Resizew int `json:"resizew"`
Resizeh int `json:"resizeh"`
Lang string `json:"lang"`
Tempfile string `json:"tempfile"`
Dispid int `json:"d"`
Gray bool `json:"gray"`
Src string `json:"src"`
Bytes []byte `json:"bytes"`
AddRects bool `json:"add_rects"`
Proportion float64 `json:"proportion"`
Encoding string `json:"encoding"`
Absolute bool `json:"absolute"`
}
type Cli struct {
*api.ApiCli
}
func (c *Cli) OCR(opts *Opts) (*Alto, error) {
res := &Alto{}
err := c.HttpCli().JsonPost("/ipc/ocr/", opts, res)
return res, err
}
func NewCli() *Cli {
ret := &Cli{ApiCli: api.NewApiCli()}
return ret
}

View File

@ -0,0 +1,27 @@
package ocr_test
import (
"go.digitalcircle.com.br/open/replaycli-go/api/ocr"
"log"
"testing"
)
func TestCli_OCR(t *testing.T) {
c := ocr.NewCli()
a, err := c.OCR(&ocr.Opts{
X: 0,
Y: 0,
H: 400,
W: 400,
Resizew: 1200,
Sharpen: 1,
Tempfile: "some_test.jpg",
Src: "ss",
AddRects: true,
Gray: true,
})
if err != nil {
t.Fatal(err.Error())
}
log.Printf("#%v", a)
}

View File

@ -1,8 +1,11 @@
package replay
import (
"encoding/json"
"fmt"
"os"
"runtime"
"time"
"go.digitalcircle.com.br/open/replaycli-go/api"
"go.digitalcircle.com.br/open/replaycli-go/types"
@ -10,63 +13,168 @@ import (
)
type Cli struct {
cli *api.Cli
*api.ApiCli
}
func (c *Cli) HttpCli() *api.Cli {
return c.cli
//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()
ret.Dtlog = time.Now()
return ret
}
func (c *Cli) ReplayEnvQueueId() string {
return os.Getenv("REPLAY_QUEUEID")
}
func (c *Cli) ReplayEnvAlias() string {
return os.Getenv("REPLAY_ALIAS")
}
func (c *Cli) ReplayEnvFeatureDir() string {
return os.Getenv("REPLAY_FEATUREDIR")
}
func (c *Cli) ReplayEnvRoot() string {
return os.Getenv("REPLAY_ROOT")
}
func (c *Cli) ReplayEnvAddr() string {
return os.Getenv("REPLAY_ADDR")
}
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")
}
func (c *Cli) ReplayEnvVer() string {
return os.Getenv("REPLAY_VER")
}
func (c *Cli) ReplayEnvRepoDir() string {
return os.Getenv("REPLAY_REPODIR")
}
func (c *Cli) ReplayEnvDataDir() string {
return os.Getenv("REPLAY_DATADIR")
}
func (c *Cli) ReplayEnvInstanceAlias() string {
return os.Getenv("REPLAY_INSTANCE_ALIAS")
}
func (c *Cli) ReplayEnvApiKey() string {
return os.Getenv("REPLAY_APIKEY")
}
func (c *Cli) OpenApp(id uint) error {
err := c.cli.HttpJsonGet(fmt.Sprintf("/api/v1/app/run/%d", id), nil)
err := c.HttpCli().JsonGet(fmt.Sprintf("/api/v1/app/run/%d", id), nil)
return err
}
func (c *Cli) ConfigGet(k string) (ret string, err error) {
err = c.cli.HttpJsonGet("/api/v1/config/byrepo/"+util.Repo()+"/"+k, &ret)
err = c.HttpCli().JsonGet("/api/v1/config/byrepo/"+util.Repo()+"/"+k, &ret)
return
}
func (c *Cli) ConfigGetGlobal(k string) (ret string, err error) {
err = c.HttpCli().JsonGet("/api/v1/config/global/"+k, &ret)
return
}
func (c *Cli) ConfigGetAll() (ret []types.Config, err error) {
ret = make([]types.Config, 0)
err = c.cli.HttpJsonGet("/api/v1/config/byrepo/"+util.Repo(), &ret)
err = c.HttpCli().JsonGet("/api/v1/config/byrepo/"+util.Repo(), &ret)
return
}
func (c *Cli) ConfigGetMap() (ret map[string]types.Config, err error) {
cfgs, err := c.ConfigGetAll()
if err != nil {
return
}
ret = make(map[string]types.Config)
for _, v := range cfgs {
ret[v.K] = v
}
return
}
func (c *Cli) CronReload() error {
return c.cli.HttpJsonGet("/ipc/cron/reload", nil)
return c.HttpCli().JsonGet("/ipc/cron/reload", nil)
}
func (c *Cli) Exit() error {
err := c.cli.HttpJsonGet("/api/v1/exit", nil)
err := c.HttpCli().JsonGet("/api/v1/exit", nil)
return err
}
func (c *Cli) MenuGetAllEnabled() (ret []types.Menu, err error) {
ret = make([]types.Menu, 0)
err = c.cli.HttpJsonGet("/api/v1/menu/enabled", nil)
err = c.HttpCli().JsonGet("/api/v1/menu/enabled", &ret)
return ret, err
}
func (c *Cli) QueueAdd(job string, bs []byte) error {
return c.cli.HttpJsonGet("/api/v1/queue/add/"+job, bs)
_, err := c.HttpCli().RawPost("/api/v1/queue/add/"+job, bs)
return err
}
func (c *Cli) QueueGetData(id string) (ret []byte, err error) {
ret, err = c.cli.HttpRawGet("/api/v1/queue/getrequest/" + id)
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 {
bs, err := c.QueueGetData(os.Getenv("REPLAY_QUEUEID"))
if err != nil {
return err
}
err = json.Unmarshal(bs, &i)
return err
}
func (c *Cli) QueueAbort() error {
return c.cli.HttpJsonGet("/api/v1/queue/abort", nil)
return c.HttpCli().JsonGet("/api/v1/queue/abort", nil)
}
func (c *Cli) QueueEnqueue(id uint) error {
return c.cli.HttpJsonGet(fmt.Sprintf("/api/v1/robots/op/enqueue/%d", id), nil)
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.cli.HttpJsonGet("/api/v1/service/op/stopall", nil)
return c.HttpCli().JsonGet("/api/v1/service/op/stopall", nil)
}
func (c *Cli) Err(err string, desc string) error {
bs := make([]byte, 4096)
n := runtime.Stack(bs, false)
cd, _ := c.QueueGetMyData()
e := &types.Error{
Feature: c.ReplayEnvAlias(),
Err: err,
When: time.Time{},
Stack: string(bs[:n]),
InputData: string(cd),
Details: desc,
}
return c.HttpCli().JsonPost("/api/v1/err", e, nil)
}
type SQLReturn struct {
@ -79,11 +187,11 @@ func (c *Cli) SQL(s string) (*SQLReturn, error) {
Sql string `json:"sql"`
}{s}
out := &SQLReturn{}
err := c.cli.HttpJsonPost("/api/v1/sql", in, &out)
err := c.HttpCli().JsonPost("/api/v1/sql", in, &out)
return out, err
}
func NewCli() *Cli {
ret := &Cli{cli: api.NewCli()}
ret := &Cli{ApiCli: api.NewApiCli()}
return ret
}

View File

@ -2,85 +2,541 @@ package wingui
import (
"fmt"
"go.digitalcircle.com.br/open/replaycli-go/api"
)
type Cli struct {
cli *api.Cli
*api.ApiCli
}
func (c *Cli) HttpCli() *api.Cli {
return c.cli
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) ClipRead() (string, error) {
ret := ""
err := c.cli.HttpJsonGet(fmt.Sprintf("/ipc/wingui/clip/read"), &ret)
return ret, err
bs, err := c.HttpCli().RawGet("/ipc/wingui/clip/read")
return string(bs), err
}
func (c *Cli) ClipWrite(site string) error {
err := c.cli.HttpJsonGet(fmt.Sprintf("/ipc/wingui/clip/write?str=%s", site), nil)
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.cli.HttpJsonGet(fmt.Sprintf("/ipc/wingui/mouse/click"), nil)
err := c.HttpCli().JsonGet("/ipc/wingui/mouse/click", nil)
return err
}
func (c *Cli) MouseMove(x, y int) error {
err := c.cli.HttpJsonGet(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.cli.HttpJsonGet(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.cli.HttpJsonGet(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.cli.HttpJsonGet(fmt.Sprintf("/ipc/wingui/mouse/clickat?x=%d&y=%d", x, y), nil)
return err
}
func (c *Cli) ScreenClick(f string) error {
err := c.cli.HttpJsonGet(fmt.Sprintf("/ipc/wingui/screen/click?f=%s", f), nil)
return err
}
func (c *Cli) ScreenClickCenter(f string) error {
err := c.cli.HttpJsonGet(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.cli.HttpJsonGet(fmt.Sprintf("/ipc/wingui/screen/find?f=%s", f), &ret)
return
}
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)
return err
}
/***************** KB Functions *****************/
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
Em caso de teclas alteradoras, elas devem ser sempre posicionadas apos a tecla alvo.
Dessa forma, para enviar ALT+d, vc envia o string "d,alt". Para enviar C maiusculo, vc utiiliza
"c,shift".
Referencia das teclas e respectivos strings:
"`": 41,
"1": 2,
"2": 3,
"3": 4,
"4": 5,
"5": 6,
"6": 7,
"7": 8,
"8": 9,
"9": 10,
"0": 11,
"-": 12,
"+": 13,
//
"q": 16,
"w": 17,
"e": 18,
"r": 19,
"t": 20,
"y": 21,
"u": 22,
"i": 23,
"o": 24,
"p": 25,
"[": 26,
"]": 27,
"\\": 43,
//
"a": 30,
"s": 31,
"d": 32,
"f": 33,
"g": 34,
"h": 35,
"j": 36,
"k": 37,
"l": 38,
";": 39,
"'": 40,
//
"z": 44,
"x": 45,
"c": 46,
"v": 47,
"b": 48,
"n": 49,
"m": 50,
",": 51,
".": 52,
"/": 53,
//
"f1": 59,
"f2": 60,
"f3": 61,
"f4": 62,
"f5": 63,
"f6": 64,
"f7": 65,
"f8": 66,
"f9": 67,
"f10": 68,
"f11": 69,
"f12": 70,
// more
"esc": 1,
"delete": 14,
"tab": 15,
"ctrl": 29,
"control": 29,
"alt": 56,
"space": 57,
"shift": 42,
"rshift": 54,
"enter": 28,
//
"cmd": 3675,
"command": 3675,
"rcmd": 3676,
"ralt": 3640,
//
"up": 57416,
"down": 57424,
"left": 57419,
"right": 57421,
*/
ret := make(map[string]interface{})
err := c.cli.HttpJsonGet(fmt.Sprintf("/ipc/wingui/kb/tap?str=%s", t), &ret)
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/kb/tap?str=%s", t), &ret)
return ret, err
}
func (c *Cli) ScreenWait(f string, m int) (ret map[string]interface{}, err error) {
ret = make(map[string]interface{})
err = c.cli.HttpJsonGet(fmt.Sprintf("/ipc/wingui/screen/wait?f=%s&m=%d", f, m), &ret)
return
func (c *Cli) KBType(t string) (map[string]interface{}, error) {
/* Semelhante a tap, mas envia textos completos.
***ATENCAO*** Esse metodo usa urlencoding, dessa forma caracteres serao codificados para envio. # virará %23
por exemplo. Ao chegar no robo passrão pelo decoding análogo. */
ret := make(map[string]interface{})
err := c.HttpCli().JsonGet(fmt.Sprintf("/ipc/wingui/kb/type?str=%s", t), &ret)
return ret, err
}
func (c *Cli) ScreenWaitClick(f string, m int) (ret map[string]interface{}, err error) {
ret = make(map[string]interface{})
err = c.cli.HttpJsonGet(fmt.Sprintf("/ipc/wingui/screen/waitclick?f=%s&m=%d", f, m), &ret)
return
func (c *Cli) KBToggle(str string) error {
err := c.HttpCli().JsonGet("/ipc/wingui/kb/toggle?str="+str, nil)
return err
}
func (c *Cli) ScreenWaitClickCenter(f string, m int) (ret map[string]interface{}, err error) {
ret = make(map[string]interface{})
err = c.cli.HttpJsonGet(fmt.Sprintf("/ipc/wingui/screen/waitclickcenter?f=%s&m=%d", f, m), &ret)
/***************** 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)
ret, err := c.HttpCli().RawGet(url)
if err != nil {
fmt.Printf(err.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)
ret, err := c.HttpCli().RawGet(url)
if err != nil {
fmt.Printf(err.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)
ret, err := c.HttpCli().RawGet(url)
if err != nil {
fmt.Printf(err.Error())
}
fmt.Println(ret)
return ret, err
}
func (c *Cli) ScreenRes() ([]byte, error) {
url := "/ipc/wingui/screen/res"
ret, err := c.HttpCli().RawGet(url)
if err != nil {
fmt.Printf(err.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{cli: api.NewCli()}
ret := &Cli{ApiCli: api.NewApiCli()}
return ret
}

View File

@ -75,4 +75,5 @@ const (
ENV_REPLAY_ALIAS = "REPLAY_ALIAS"
ENV_REPLAY_VER = "REPLAY_VER"
ENV_REPLAY_QUEUEID = "REPLAY_QUEUEID"
ENV_REPLAY_PRECMDS = "REPLAY_PRECMDS"
)

8
go.mod
View File

@ -2,9 +2,13 @@ module go.digitalcircle.com.br/open/replaycli-go
go 1.17
//replace (
// go.digitalcircle.com.br/open/httpcli => ../httpcli
//)
require (
github.com/Microsoft/go-winio v0.5.0
github.com/Microsoft/go-winio v0.5.2
github.com/gorilla/websocket v1.4.2
github.com/mitchellh/go-ps v1.0.0
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect
go.digitalcircle.com.br/open/httpcli v0.0.0-20211031093505-ecf33aed8afb
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
)

20
go.sum
View File

@ -1,5 +1,9 @@
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/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
@ -9,9 +13,17 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
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/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210921065528-437939a70204 h1:JJhkWtBuTQKyz2bd5WG9H8iUsJRU3En/KRfN8B2RnDs=
golang.org/x/sys v0.0.0-20210921065528-437939a70204/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 h1:foEbQz/B0Oz6YIqu/69kfXPYeFQAuuMYFkjaqXzl5Wo=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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-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=

View File

@ -56,7 +56,7 @@ func (p *PSCli) GetConn() *websocket.Conn {
p.con = con
p.con.SetCloseHandler(func(code int, text string) error {
log.Printf("Connection closed: %d: %s", code, text)
p.con = nil
p.Close()
return nil
})
break
@ -95,6 +95,17 @@ func (p *PSCli) Read(i interface{}) error {
return json.Unmarshal(bs, i)
}
func (p *PSCli) Close() error {
if !p.closed {
p.closed = true
if p.ch != nil {
close(p.ch)
}
return p.con.Close()
}
return nil
}
func NewCli(q string) (*PSCli, error) {
ret := &PSCli{}
ret.q = q

View File

@ -1,6 +1,10 @@
package types
import (
"encoding/json"
"fmt"
"os"
"strconv"
"time"
)
@ -66,6 +70,7 @@ type Service struct {
Pid int `json:"pid" yaml:"-"`
Hostname string `json:"hostname" yaml:"hostname"`
Gui bool `json:"gui" yaml:"gui"`
Public bool `json:"public" yaml:"public"`
}
type Runtime struct {
@ -106,6 +111,7 @@ type ReplayDescriptor struct {
Hostname string `json:"hostname" yaml:"hostname"`
Ipcid string `json:"ipcid"`
Gui bool `json:"gui" yaml:"gui"`
Public bool `json:"public" yaml:"public"`
Link string `json:"link" yaml:"link"` //This prop allows redirect of repos
}
@ -138,6 +144,55 @@ type Config struct {
Repo uint `json:"repo"`
}
func (c *Config) AsInt64() int64 {
i, err := strconv.ParseInt(c.V, 10, 64)
if err != nil {
return 0
}
return i
}
func (c *Config) AsInt32() int32 {
i, err := strconv.ParseInt(c.V, 10, 32)
if err != nil {
return 0
}
return int32(i)
}
func (c *Config) AsUint() uint {
i, err := strconv.ParseInt(c.V, 10, 32)
if err != nil {
return 0
}
return uint(i)
}
func (c *Config) AsInt() int {
i, err := strconv.ParseInt(c.V, 10, 16)
if err != nil {
return 0
}
return int(i)
}
func (c *Config) AsFloat64() float64 {
i, err := strconv.ParseFloat(c.V, 64)
if err != nil {
return 0
}
return i
}
func (c *Config) AsFloat32() float32 {
i, err := strconv.ParseFloat(c.V, 32)
if err != nil {
return 0
}
return float32(i)
}
func (c *Config) AsBool() bool {
return c.V == "true" || c.V == "1" || c.V == "t"
}
func (c *Config) AsJson(i interface{}) error {
return json.Unmarshal([]byte(c.V), i)
}
type Credentials struct {
Model
Name string `json:"name"`
@ -148,7 +203,47 @@ type Credentials struct {
type Log struct {
Model
Log []byte
Alias string `json:"alias,omitempty"`
Title string `json:"title,omitempty"`
Tags string `json:"tags,omitempty"`
Dtlog time.Time `json:"dtlog"`
Dtlogend time.Time `json:"dtlogend"`
Data []byte `json:"data,omitempty"`
Err string `json:"err,omitempty"`
History string `json:"history,omitempty"`
}
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
}
l.AddHistory(string(p))
return len(p), nil
}
func (l *Log) AddHistory(s string) {
s = fmt.Sprintf("* %s: %s", time.Now().Format("02/01/06 - 15:04:05"), s)
if l.History == "" {
l.History = s
} else {
l.History = l.History + "\n" + s
}
}
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"`
Limit int `json:"limit"`
Title string `json:"title"`
Alias string `json:"alias"`
Tags string `json:"tags"`
}
type Job struct {
@ -215,9 +310,13 @@ type Options struct {
type Cron struct {
Model
Cron string `json:"cron"`
JobCode uint `json:"job"`
Enabled *bool `json:"enabled"`
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 {
@ -338,6 +437,15 @@ type Series struct {
Year int `json:"year"`
}
type Error struct {
Feature string `json:"feature,omitempty"`
When time.Time `json:"when"`
Err string `json:"err,omitempty"`
Stack string `json:"stack,omitempty"`
InputData string `json:"input_data,omitempty"`
Details string `json:"details,omitempty"`
}
func (s *Series) SetTime(t time.Time) {
s.When = t
s.Day = t.Day()