Files
lone-services/services/chore/internal/logic/base.go
T
gjs 38e040af07
CI / changes (push) Successful in 37s
CI / ad (push) Successful in 29s
CI / admin (push) Successful in 17s
CI / bff (push) Successful in 13s
CI / chore (push) Successful in 15s
CI / equipment (push) Successful in 14s
CI / express (push) Successful in 14s
CI / product (push) Successful in 13s
CI / record (push) Successful in 13s
CI / sale (push) Successful in 13s
CI / task (push) Successful in 13s
CI / user (push) Successful in 14s
CI / wecom (push) Successful in 13s
订单下载。jd下单。。
2026-09-09 17:52:07 +08:00

45 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package logic
import (
"lone-services/pkg/utils"
"lone-services/pkg/validate"
chore "lone-services/rpc/chore/pb"
"reflect"
jsoniter "github.com/json-iterator/go"
)
type BaseLogic struct {
}
func (l *BaseLogic) checkParams(in interface{}, v validate.IValidator) *chore.Response {
rv := reflect.ValueOf(in)
if rv.Kind() != reflect.Ptr || rv.IsNil() {
return &chore.Response{
Code: utils.ErrorParams.Code,
Msg: "request must be non‑nil proto pointer",
}
}
resp := validate.ValidateFromProto(in, v)
if resp != utils.StringEmpty {
return &chore.Response{
Code: utils.ErrorParams.Code,
Msg: resp,
}
}
return nil
}
func (l *BaseLogic) fail(status utils.Status) (*chore.Response, error) {
return l.out(status, status.Msg)
}
func (l *BaseLogic) out(status utils.Status, msg string) (*chore.Response, error) {
return &chore.Response{Code: status.Code, Msg: msg}, nil
}
func (l *BaseLogic) ok(data any) (*chore.Response, error) {
buf, _ := jsoniter.Marshal(data)
return &chore.Response{Code: utils.Ok.Code, Msg: utils.Ok.Msg, Data: string(buf)}, nil
}