Preliminary Commit with fixes
- Sorted imports - Fixed nested if block - Added special nolint (goerr113) argument for error initialization - Edited port in main.go - Deleted swagger.json
This commit is contained in:
1 parent
9092acc8bf
commit
abd54bf180
8 files changed
+32
-274
No files matched your search
+13
-13
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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...)
|
||||
|
||||
+5
-5
@@ -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)
|
||||
|
||||
+1
-1
@@ -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()
|
||||
|
||||
+3
-2
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user