| 12345678910111213141516171819202122232425262728293031323334353637 |
- package reply
- import (
- "github.com/go-kratos/kratos/v2/transport/http"
- )
- type SuccessReply struct {
- Code int32 `json:"code"`
- Message string `json:"message"`
- Data interface{} `json:"data"`
- }
- type ReplyFunc func(ctx http.Context, req any) (any, error)
- var reply = DefaultFunc
- func DefaultFunc(ctx http.Context, out any) (any, error) {
- success := &SuccessReply{
- Code: 0,
- }
- if out != nil {
- success.Data = out
- }
- return success, nil
- }
- func SetReplyFunc(f ReplyFunc) {
- reply = f
- }
- func GetReplyFunc() ReplyFunc {
- if reply == nil {
- reply = DefaultFunc
- }
- return reply
- }
|