04402a8bdf
CI / changes (push) Successful in 36s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 18s
CI / chore (push) Successful in 0s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 0s
CI / product (push) Successful in 0s
CI / record (push) Successful in 20s
CI / sale (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 0s
CI / wecom (push) Successful in 1s
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package logic
|
||
|
||
import (
|
||
"lone-services/pkg/utils"
|
||
"lone-services/pkg/validate"
|
||
"lone-services/rpc/record/pb"
|
||
"reflect"
|
||
|
||
jsoniter "github.com/json-iterator/go"
|
||
)
|
||
|
||
type BaseLogic struct {
|
||
}
|
||
|
||
func (l *BaseLogic) checkParams(in interface{}, v validate.IValidator) *record.Response {
|
||
rv := reflect.ValueOf(in)
|
||
if rv.Kind() != reflect.Ptr || rv.IsNil() {
|
||
return &record.Response{
|
||
Code: utils.ErrorParams.Code,
|
||
Msg: "request must be non‑nil proto pointer",
|
||
}
|
||
}
|
||
|
||
resp := validate.ValidateFromProto(in, v)
|
||
if resp != utils.StringEmpty {
|
||
return &record.Response{
|
||
Code: utils.ErrorParams.Code,
|
||
Msg: resp,
|
||
}
|
||
}
|
||
return nil
|
||
}
|
||
|
||
func (l *BaseLogic) fail(status utils.Status) (*record.Response, error) {
|
||
return l.out(status, status.Msg)
|
||
}
|
||
func (l *BaseLogic) out(status utils.Status, msg string) (*record.Response, error) {
|
||
return &record.Response{Code: status.Code, Msg: msg}, nil
|
||
}
|
||
|
||
func (l *BaseLogic) ok(data any) (*record.Response, error) {
|
||
buf, _ := jsoniter.Marshal(data)
|
||
return &record.Response{Code: utils.Ok.Code, Msg: utils.Ok.Msg, Data: string(buf)}, nil
|
||
}
|