epuiment
CI / changes (push) Successful in 37s
CI / ad (push) Successful in 44s
CI / admin (push) Successful in 39s
CI / bff (push) Successful in 32s
CI / chore (push) Successful in 38s
CI / express (push) Successful in 42s
CI / product (push) Successful in 43s
CI / sale (push) Successful in 42s
CI / task (push) Successful in 42s
CI / user (push) Successful in 42s
CI / wecom (push) Successful in 41s
CI / changes (push) Successful in 37s
CI / ad (push) Successful in 44s
CI / admin (push) Successful in 39s
CI / bff (push) Successful in 32s
CI / chore (push) Successful in 38s
CI / express (push) Successful in 42s
CI / product (push) Successful in 43s
CI / sale (push) Successful in 42s
CI / task (push) Successful in 42s
CI / user (push) Successful in 42s
CI / wecom (push) Successful in 41s
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
equipment "lone-services/rpc/equipment/pb"
|
||||
"reflect"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
type BaseLogic struct {
|
||||
}
|
||||
|
||||
func (l *BaseLogic) checkParams(in interface{}, v validate.IValidator) *equipment.Response {
|
||||
rv := reflect.ValueOf(in)
|
||||
if rv.Kind() != reflect.Ptr || rv.IsNil() {
|
||||
return &equipment.Response{
|
||||
Code: utils.ErrorParams.Code,
|
||||
Msg: "request must be non‑nil proto pointer",
|
||||
}
|
||||
}
|
||||
|
||||
resp := validate.ValidateFromProto(in, v)
|
||||
if resp != utils.StringEmpty {
|
||||
return &equipment.Response{
|
||||
Code: utils.ErrorParams.Code,
|
||||
Msg: resp,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *BaseLogic) fail(status utils.Status) (*equipment.Response, error) {
|
||||
return l.out(status, status.Msg)
|
||||
}
|
||||
func (l *BaseLogic) out(status utils.Status, msg string) (*equipment.Response, error) {
|
||||
return &equipment.Response{Code: status.Code, Msg: msg}, nil
|
||||
}
|
||||
|
||||
func (l *BaseLogic) ok(data any) (*equipment.Response, error) {
|
||||
buf, _ := jsoniter.Marshal(data)
|
||||
return &equipment.Response{Code: utils.Ok.Code, Msg: utils.Ok.Msg, Data: string(buf)}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user