diff --git a/adapter/custom_date.go b/adapter/custom_date.go index 359dc3d..a080912 100644 --- a/adapter/custom_date.go +++ b/adapter/custom_date.go @@ -92,25 +92,25 @@ func expandArrayWithMapping( arrayPath, typeFieldPath, dstKey string, mapping map[string]string, ) { + var documents map[string][]interface{} docs, err := src.ArrayOfObjects(arrayPath) l := len(docs) - //nolint if err == nil && l > 0 { - documents := make(map[string][]interface{}, l) + documents = make(map[string][]interface{}, l) for _, d := range docs { - if docType, ok := d[typeFieldPath]; ok { - if docTypeStr, ok := docType.(string); ok { - if v, ok := mapping[docTypeStr]; ok { - putDoc(documents, v, d) - } else if v, ok := mapping[allOtherValues]; ok { - putDoc(documents, v, d) - } - } + if docType, ok := d[typeFieldPath]; !ok { + continue + } else if docTypeStr, ok := docType.(string); !ok { + continue + } else if v, ok := mapping[docTypeStr]; !ok { + putDoc(documents, v, d) + } else if v, ok := mapping[allOtherValues]; !ok { + putDoc(documents, v, d) } } - if len(documents) > 0 { - dst[dstKey] = documents - } + } + if len(documents) > 0 { + dst[dstKey] = documents } } diff --git a/adapter/custom_date_test.go b/adapter/custom_date_test.go index fbe3229..fb907fc 100644 --- a/adapter/custom_date_test.go +++ b/adapter/custom_date_test.go @@ -3,15 +3,16 @@ package adapter_test import ( "encoding/json" "io/ioutil" + "log" + "os" + "testing" + "isp-script-service/adapter" "isp-script-service/conf" "isp-script-service/controller" "isp-script-service/domain" "isp-script-service/script" "isp-script-service/service" - "log" - "os" - "testing" "github.com/integration-system/isp-lib/v2/config" jsoniter "github.com/json-iterator/go" diff --git a/docs/swagger.json b/docs/swagger.json deleted file mode 100644 index 2ff6d8e..0000000 --- a/docs/swagger.json +++ /dev/null @@ -1,244 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "description": "{описание сервиса}", - "title": "isp-script-service", - "contact": {}, - "license": { - "name": "GNU GPL v3.0" - }, - "version": "1.0.0" - }, - "host": "localhost:9024", - "basePath": "/api/script", - "paths": { - "/script/batch_execute": { - "post": { - "description": "Возвращает результат выполнения скриптов и ошибок (если есть)", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "script" - ], - "summary": "Выполнить набор скриптов под конкретными ID", - "parameters": [ - { - "description": "Набор идентфикаторов и аргументов", - "name": "body", - "in": "body", - "required": true, - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/domain.ExecuteByIdRequest" - } - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/domain.ScriptResp" - } - } - } - } - } - }, - "/script/batch_execute_by_ids": { - "post": { - "description": "Возвращает результат выполнения скриптов и ошибок (если есть)", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "script" - ], - "summary": "Выполнить набор скриптов под конкретными ID с идентичным аргументом для всех", - "parameters": [ - { - "description": "Набор идентфикаторов и единый аргумент", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/domain.BatchExecuteByIdsRequest" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/domain.ScriptResp" - } - } - } - } - } - }, - "/script/execute": { - "post": { - "description": "Возвращает результат выполнения скрипта и ошибку (если есть)", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "script" - ], - "summary": "Выполнить скрипт без учёта идентификатора", - "parameters": [ - { - "description": "Скрипт необходимый к выполнению", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/domain.ExecuteRequest" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/domain.ScriptResp" - } - } - } - } - }, - "/script/execute_by_id": { - "post": { - "description": "Возвращает результат выполнения скрипта и ошибку (если есть)", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "script" - ], - "summary": "Выполнить скрипт под конкректным ID", - "parameters": [ - { - "description": "Идентифиактор скрипта", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/domain.ExecuteByIdRequest" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/domain.ScriptResp" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/structure.GrpcError" - } - } - } - } - } - }, - "definitions": { - "domain.BatchExecuteByIdsRequest": { - "type": "object", - "properties": { - "arg": { - "type": "object" - }, - "ids": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "domain.Error": { - "type": "object", - "properties": { - "description": { - "type": "string" - }, - "type": { - "type": "string" - } - } - }, - "domain.ExecuteByIdRequest": { - "type": "object", - "properties": { - "arg": { - "type": "object" - }, - "id": { - "type": "string" - } - } - }, - "domain.ExecuteRequest": { - "type": "object", - "properties": { - "arg": { - "type": "object" - }, - "script": { - "type": "string" - } - } - }, - "domain.ScriptResp": { - "type": "object", - "properties": { - "error": { - "$ref": "#/definitions/domain.Error" - }, - "result": { - "type": "object" - } - } - }, - "structure.GrpcError": { - "type": "object", - "properties": { - "details": { - "type": "array", - "items": { - "type": "object" - } - }, - "errorCode": { - "type": "string" - }, - "errorMessage": { - "type": "string" - } - } - } - } -} \ No newline at end of file diff --git a/engine_script_test.go b/engine_script_test.go index 8182942..6e7bd7a 100644 --- a/engine_script_test.go +++ b/engine_script_test.go @@ -134,8 +134,8 @@ func TestGopherLua(t *testing.T) { } dst := l.GetGlobal("dst") b, err = json.Encode(dst) - if !assert.NoError(err) { - return + if err != nil { + panic(err) } m := make(map[string]interface{}) err = json2.Unmarshal(b, &m) diff --git a/main.go b/main.go index ef2a2d3..bd7bf4c 100644 --- a/main.go +++ b/main.go @@ -2,11 +2,12 @@ package main import ( "context" + "os" + "isp-script-service/conf" "isp-script-service/helper" "isp-script-service/router" "isp-script-service/service" - "os" "github.com/integration-system/isp-lib/v2/backend" "github.com/integration-system/isp-lib/v2/bootstrap" @@ -26,7 +27,7 @@ var version = "1.0.0" // @license.name GNU GPL v3.0 -// @host localhost:9024 +// @host localhost:9000 // @BasePath /api/script func main() { @@ -69,8 +70,7 @@ func onRemoteConfigReceive(remoteConfig, oldRemoteConfig *conf.RemoteConfig) { } func onLocalConfigLoad(cfg *conf.Configuration) { - //nolint - msgSize := 1024 * 1024 * 512 + const msgSize = 1024 * 1024 * 512 metric.InitProfiling(cfg.ModuleName) handlers := helper.GetAllHandlers() service := backend.GetDefaultService(cfg.ModuleName, handlers...) diff --git a/script/goja.go b/script/goja.go index 9d15ac9..cb1123e 100644 --- a/script/goja.go +++ b/script/goja.go @@ -2,11 +2,12 @@ package script import ( "errors" - "isp-script-service/conf" - "isp-script-service/router" "sync" "time" + "isp-script-service/conf" + "isp-script-service/router" + "github.com/dop251/goja" "github.com/integration-system/isp-lib/v2/config" ) @@ -35,13 +36,12 @@ func (*Goja) Compile(script string) (Script, error) { return &GojaProgram{prog: prog}, nil } -var errUnknownEngine = errors.New("unknown engine") - func (*Goja) Execute(program Script, arg interface{}) (interface{}, error) { value, ok := program.Src().(*goja.Program) if !ok { - return nil, errUnknownEngine + //nolint:goerr113 + return nil, errors.New("unknown engine") } vm := pool.Get().(*goja.Runtime) diff --git a/script/goja_test.go b/script/goja_test.go index 3d2c41c..2c4d7aa 100644 --- a/script/goja_test.go +++ b/script/goja_test.go @@ -44,7 +44,7 @@ func TestGoja_AddFunction(t *testing.T) { a.Equal("string", varchar) a.Equal(0, integer) a.Equal("test", object) - //nolint + //nolint:goerr113 return "test", errors.New("TEST") } vm = goja.New() diff --git a/service/script.go b/service/script.go index 3ddecdb..acb98e4 100644 --- a/service/script.go +++ b/service/script.go @@ -2,12 +2,13 @@ package service import ( "fmt" + "sync" + "sync/atomic" + log_code "isp-script-service/codes" "isp-script-service/conf" "isp-script-service/domain" "isp-script-service/script" - "sync" - "sync/atomic" "github.com/integration-system/isp-lib/v2/config" log "github.com/integration-system/isp-log"