htp

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxRemoteIpGet

func CtxRemoteIpGet(c *gin.Context) string

CtxRemoteIpGet get remote_ip from Context

func CtxRemoteIpSet

func CtxRemoteIpSet(c *gin.Context, ip string)

CtxRemoteIpSet set remote_ip to Context (业务层设置)

func CtxRequestGet

func CtxRequestGet(c *gin.Context) any

CtxRequestGet get request from Context

func CtxRequestSet

func CtxRequestSet(c *gin.Context, req any)

CtxRequestSet set request to Context (系统内部或中间件设置)

func CtxResponseSet

func CtxResponseSet(c *gin.Context, rsp *Response)

CtxGetResponse set response to Context (系统内部或中间件设置)

func CtxUserIdGet

func CtxUserIdGet(c *gin.Context) core.TUserID

CtxUserIdGet 获取user_id

func CtxUserIdSet

func CtxUserIdSet(c *gin.Context, uid core.TUserID)

CtxUserIdSet 设置user_id (业务层设置)

func CtxUserNameGet

func CtxUserNameGet(c *gin.Context) string

CtxUserNameGet 获取user_name

func CtxUserNameSet

func CtxUserNameSet(c *gin.Context, name string)

CtxUserNameSet 设置user_name (业务层设置)

func GetRunMode

func GetRunMode() string

func Install

func Install(conf *Config) ctl.IControler

安装控制器

func Observe

func Observe(callback TObserveCallBack)

添加观察者(当调用API时回调)

func Register

func Register(r IGroupRouter)

注册路由组对象

func RegisterRender

func RegisterRender(r IRender)

func Service

func Service(c *gin.Context, s IService)

API服务

func SetRunMode

func SetRunMode(mode string)

设置gin运行模式

Types

type Config

type Config struct {
	RunMode      string    `json:"runMode"` // debug release
	ListenAddr   string    `json:"listenAddr"`
	WriteTimeout int       `json:"writeTimeout"` // second
	ReadTimeout  int       `json:"readTimeout"`  // second
	ListnTls     ListenTLS `json:"listnTls"`
}

> 配置项

type ECode

type ECode int //

> 错误码类型

const (
	ECodeSucessed  ECode = 0   // http.StatusOK
	ECodeSysError  ECode = 501 // 系统错误
	ECodeParamErr  ECode = 502 // 参数错误
	ECodeMDBError  ECode = 503 // 数据库错误
	ECodeRDBError  ECode = 504 // 缓存库错误
	ECodeCodeCrypt ECode = 505 // 编码加密错误
	ECodeLogicErr  ECode = 506 // 逻辑错误

	ECodeExtendBegin1000 ECode = 1000 // 业务扩展起始编号
)

func (ECode) String

func (e ECode) String() string

type ESRenderMode

type ESRenderMode int //

> 路由服务渲染模式

const (
	ESRender_None ESRenderMode = iota // 以xml数据格式返回
	ESRender_Xml                      // 以xml数据格式返回
	ESRender_Yaml                     // 以yaml数据格式返回
	ESRender_Json                     // 以JSON数据格式返回
	ESRender_Pbuf                     // 以Protobuf数据格式返回
)

func (ESRenderMode) String

func (e ESRenderMode) String() string

type GinLogger

type GinLogger struct{} //

-------- GinLogger

func (GinLogger) Write

func (this GinLogger) Write(p []byte) (n int, err error)

type GinRecover

type GinRecover struct{} //

-------- GinRecover

func (GinRecover) Write

func (this GinRecover) Write(p []byte) (n int, err error)

type GroupRouter

type GroupRouter struct {
	*gin.RouterGroup
}

> GroupRouter

func (*GroupRouter) API

func (gr *GroupRouter) API(group *gin.RouterGroup, relativePath string, service IService, otherHandlers ...gin.HandlerFunc)

注册API接口服务(GET|POST)

func (*GroupRouter) Base

func (gr *GroupRouter) Base() *gin.RouterGroup

返回自身的RouterGroup

type IContrler

type IContrler interface {
	ctl.IControler
}

> 控制器接口

var (
	Ctl IContrler // 默认htp控制器

)

func Controller

func Controller(conf *Config) IContrler

type IGroupRouter

type IGroupRouter interface {

	// 模块名称
	Name() string // 返回["", ".", "/"], 则表示 root router

	// 初始化路由
	Init(group *GroupRouter)
}

> 路由接口

type IRender

type IRender interface {

	// 模式
	Mode() ESRenderMode

	// 渲染
	Render(c *gin.Context, status int, rsp *Response)
}

> render接口

func MakeRender

func MakeRender(mode ESRenderMode) IRender

type ISRenderModer

type ISRenderModer interface {
	RenderMode() ESRenderMode
}

API服务接口+(渲染模式)

type IService

type IService interface {
	Handle(meta metactx.IContext) Response // 处理器
}

API服务接口(基本)

type ListenTLS

type ListenTLS struct {
	Enable  bool   `json:"enable"`
	CrtFile string `json:"crtFile"`
	KeyFile string `json:"keyFile"`
}

type Response

type Response struct {
	Code  int    `json:"code" xml:"code" yaml:"code"`
	Data  any    `json:"data,omitempty" xml:"data,omitempty" yaml:"data,omitempty"`
	Msg   string `json:"msg" xml:"msg" yaml:"msg"`
	Error string `json:"err,omitempty" xml:"err,omitempty" yaml:"err,omitempty"` // code_string : error_info
	// contains filtered or unexported fields
}

Response 基础序列化器

func CtxResponseGet

func CtxResponseGet(c *gin.Context) *Response

CtxResponseGet get response from Context

func RespData

func RespData[T util.IntStringer](code T, msg string, data any) Response

通用错误with数据

func RespErr

func RespErr[T util.IntStringer](code T, msg string, err error) Response

通用错误处理

func RespFile

func RespFile(c *gin.Context, filePath string) Response

文件返回

func RespLogicErr

func RespLogicErr(msg string, err error) Response

功能逻辑错误

func RespMDBErr

func RespMDBErr(msg string, err error) Response

数据库操作失败

func RespOK

func RespOK(msg string, data any) Response

成功返回

func RespParamErr

func RespParamErr(msg string, err error) Response

各种参数错误

func RespRDBErr

func RespRDBErr(msg string, err error) Response

缓存库操作失败

func RespSysErr

func RespSysErr(msg string, err error) Response

数据库操作失败

func (*Response) Sucessed

func (r *Response) Sucessed() bool

是否成功处理请求

type TObserveCallBack

type TObserveCallBack func(path string, service IService)

> API注册观察回调函数

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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