nats migration

nats
Paulo Simão 2021-11-14 10:31:07 -03:00
parent 429580c010
commit 6aae4a5cdb
5 changed files with 75 additions and 17 deletions

View File

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

View File

@ -6,6 +6,31 @@ import (
"go.digitalcircle.com.br/open/replaycli-go/api" "go.digitalcircle.com.br/open/replaycli-go/api"
) )
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 {
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"`
}
type Cli struct { type Cli struct {
*api.ApiCli *api.ApiCli
} }

View File

@ -16,6 +16,23 @@ type CallOpts struct {
To int 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 { func Call(s string, in interface{}, out interface{}, opts ...*CallOpts) error {
var err error var err error
opt := &CallOpts{} opt := &CallOpts{}
@ -108,3 +125,21 @@ func Pub(s string, in interface{}) error {
return err 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,17 +169,16 @@ type Opts struct {
} }
type Cli struct { type Cli struct {
*api.ApiCli //*api.ApiCli
} }
func (c *Cli) OCR(opts *Opts, copts ...*api.CallOpts) (*Alto, error) { func (c *Cli) OCR(opts *Opts, copts ...*api.CallOpts) (*Alto, error) {
res := &Alto{} res := &Alto{}
//err := c.HttpCli().JsonPost("/ipc/ocr/", opts, res)
err := api.Call("ocr.ocr", opts, &res, copts...) err := api.Call("ocr.ocr", opts, &res, copts...)
return res, err return res, err
} }
func NewCli() *Cli { func NewCli() *Cli {
ret := &Cli{ApiCli: api.NewApiCli()} ret := &Cli{}
return ret return ret
} }

View File

@ -6,6 +6,8 @@ import (
"os" "os"
) )
var Ver string
func EnsureVer(v string) { func EnsureVer(v string) {
build := os.Getenv("BUILD_VER") build := os.Getenv("BUILD_VER")
if build == "" { if build == "" {
@ -21,6 +23,8 @@ func EnsureVer(v string) {
} }
} }
func Get() string { func Get() string {
build := os.Getenv("BUILD_VER") if Ver == "" {
return build Ver = os.Getenv("BUILD_VER")
}
return Ver
} }