package query import ( "context" "encoding/json" "fmt" "adm-data/errors" "adm-data/model" v1 "adm-data/pb/v1" jsoniter "github.com/json-iterator/go" "git.getensh.com/common/gopkgsv2/database" "git.getensh.com/common/gopkgsv2/logger" "go.uber.org/zap" "google.golang.org/grpc/status" ) type p09Reqeust struct { StyleId string `json:"style_id"` } type p09Config struct { Useage string `json:"useage"` Detail string `json:"detail"` AttributeRule string `json:"attribute_rule"` } type p09Data struct { Config p09Config `json:"config"` C2Name string `json:"c2_name"` C2Id int64 `json:"c2_id"` } type p09Response struct { List []p09Data `json:"list"` } func p09(ctx context.Context, params string) (reply *v1.QueryResponse, err error) { reply = &v1.QueryResponse{} // 捕获各个task中的异常并返回给调用者 defer func() { if r := recover(); r != nil { err = fmt.Errorf("%+v", r) e := &status.Status{} if er := json.Unmarshal([]byte(err.Error()), e); er != nil { logger.Error("err", zap.String("system_err", err.Error()), zap.Stack("stacktrace")) } } }() var req p09Reqeust err = jsoniter.UnmarshalFromString(params, &req) if err != nil && req.StyleId == "" { return nil, errors.ParamsError } list, err := model.NewAds14Model().List(database.DB().Where("style_id = ?", req.StyleId)) if err != nil { return reply, errors.DataNotExistError } res := p09Response{ List: make([]p09Data, 0, len(list)), } for _, v := range list { res.List = append(res.List, p09Data{ C2Name: v.C2Name, C2Id: v.C2Id, Config: p09Config{ Useage: v.Useage, Detail: v.Detail, AttributeRule: v.AttributeRule, }, }) } reply.Data, _ = jsoniter.MarshalToString(res) return reply, nil }