Files
lone-services/services/message/internal/logic/base.go
T
gjs 7939917ba0
CI / changes (push) Successful in 39s
CI / ad (push) Successful in 1s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 48s
CI / chore (push) Successful in 0s
CI / equipment (push) Failing after 10s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / payment (push) Successful in 1s
CI / product (push) Successful in 0s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 1s
CI / task (push) Successful in 0s
CI / user (push) Successful in 0s
CI / wecom (push) Successful in 1s
message
2026-09-21 15:50:44 +08:00

49 lines
1.2 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"
message "lone-services/rpc/message/pb"
"reflect"
jsoniter "github.com/json-iterator/go"
)
type BaseLogic struct {
}
func (l *BaseLogic) checkParams(in interface{}, v validate.IValidator) *message.Response {
rv := reflect.ValueOf(in)
if rv.Kind() != reflect.Ptr || rv.IsNil() {
return &message.Response{
Code: utils.ErrorParams.Code,
Msg: "request must be non‑nil proto pointer",
}
}
resp := validate.ValidateFromProto(in, v)
if resp != utils.StringEmpty {
return &message.Response{
Code: utils.ErrorParams.Code,
Msg: resp,
}
}
return nil
}
func (l *BaseLogic) fail(status utils.Status) (*message.Response, error) {
return l.out(status, status.Msg)
}
func (l *BaseLogic) out(status utils.Status, msg string) (*message.Response, error) {
return &message.Response{Code: status.Code, Msg: msg}, nil
}
func (l *BaseLogic) outData(status utils.Status, msg, data string) (*message.Response, error) {
return &message.Response{Code: status.Code, Msg: msg, Data: data}, nil
}
func (l *BaseLogic) ok(data any) (*message.Response, error) {
buf, _ := jsoniter.Marshal(data)
return &message.Response{Code: utils.Ok.Code, Msg: utils.Ok.Msg, Data: string(buf)}, nil
}