httpapi

package
v0.0.0-...-cc3858d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeMessageFunc

func MakeMessageFunc(c *gin.Context, service, method string) (req proto.Message, resp proto.Message, err error)

通用消息构造逻辑,前提是已经import了pb代码,如:import _ "github.com/fixkme/protoc-gen-gom/example/pbout/go/game"

func Response

func Response(c *gin.Context, httpStatus int, response *ResponseResult)

func ResponseError

func ResponseError(c *gin.Context, httpStatus int, err error)

func ResponseSuccess

func ResponseSuccess(c *gin.Context, data any)

Types

type MakeMessageHandler

type MakeMessageHandler func(c *gin.Context, serviceName, methodName string) (req proto.Message, resp proto.Message, err error)

type Options

type Options struct {
	// 版本号,可以为空
	ApiVersion string
	// Middlewares 里可以添加鉴权的逻辑
	Middlewares []gin.HandlerFunc
	// 构造消息的方法, 必须提供
	MakeMessage MakeMessageHandler
}

type ResponseResult

type ResponseResult struct {
	Ecode int         `json:"ecode"` // 业务状态码,0为成功,其他表示失败
	Error string      `json:"error"` // 业务消息提示,不参与逻辑,仅用于ui展示,默认为空字符串
	Data  interface{} `json:"data"`  // 业务数据,如果不设置时默认为json空对象{}
}

返回格式

type Server

type Server struct {
	Addr   string
	Ln     net.Listener
	Router *gin.Engine
	// contains filtered or unexported fields
}

func NewWeb

func NewWeb(network, addr string, rpcClient rpc.RpcClient, opt *Options) (*Server, error)

func (*Server) Run

func (s *Server) Run() (err error)

func (*Server) Start

func (s *Server) Start()

func (*Server) Stop

func (s *Server) Stop()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL