goserver

package
v1.2.181 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP added in v1.2.95

func ClientIP(c *gin.Context) string

客户端IP

func CreateToken added in v1.2.95

func CreateToken(appId string, openid int64) (tokenStr string, err error)

func GrpcContext added in v1.2.95

func GrpcContext(c *gin.Context) context.Context

func Handler added in v1.2.95

func Handler(controller iController) gin.HandlerFunc

定义控制器调用实现

func LoadJsonConfig added in v1.2.95

func LoadJsonConfig(jsonFile string, conf interface{}) (err error)

func LoadYamlConfig added in v1.2.95

func LoadYamlConfig(yamlFile string, conf interface{}) (err error)

func RequestBody added in v1.2.95

func RequestBody(c *gin.Context) interface{}

请求数据

func RequestId added in v1.2.95

func RequestId(c *gin.Context) string

唯一ID

func ValidationMessage added in v1.2.95

func ValidationMessage(err error, messages map[string]string) string

Types

type Config added in v1.2.95

type Config struct {
	Env goio.Environment `yaml:"env"`

	Server struct {
		Addr string `yaml:"addr"`
		Name string `yaml:"name"`
	} `yaml:"server"`

	Prometheus  prometheusx.Config  `yaml:"prometheus"`
	MongoDB     gomongo.Config      `yaml:"mongodb"`
	Mysql       gogorm.Config       `yaml:"mysql"`
	Postgres    gogorm.Config       `yaml:"postgres"`
	Sqlite      gogorm.Config       `yaml:"sqlite"`
	Clickhouse1 gogorm.Config       `yaml:"clickhouse1"`
	Redis       goredis.Config      `yaml:"redis"`
	Kafka       gokafka.Config      `yaml:"kafka"`
	Clickhouse  goclickhouse.Config `yaml:"clickhouse"`
	Es          goes.Config         `yaml:"es"`

	Etcd goetcd.Config `yaml:"etcd"`

	FeiShu string `yaml:"feishu"`
}

type Encryption added in v1.2.95

type Encryption struct {
	Key    string
	Secret string
}

func (*Encryption) Decode added in v1.2.95

func (enc *Encryption) Decode(str string) (b []byte, err error)

func (*Encryption) Encode added in v1.2.95

func (enc *Encryption) Encode(b []byte) (str string, err error)

type LocalUpload added in v1.2.95

type LocalUpload struct {
}

func (LocalUpload) Upload added in v1.2.95

func (lu LocalUpload) Upload(c *gin.Context, uploadDir string) *Response

type Option added in v1.2.95

type Option interface {
	// contains filtered or unexported methods
}

func CorsHeaderOption added in v1.2.95

func CorsHeaderOption(corsHeaders ...string) Option

跨域

func EnableEncryptionOption added in v1.2.95

func EnableEncryptionOption(encryptKey, encryptSecret string, excludeUris ...string) Option

启用加密传输

func EnvOption added in v1.2.95

func EnvOption(env goio.Environment) Option

运行环境

func NoAccessPathsOption added in v1.2.95

func NoAccessPathsOption(noAccessPaths ...string) Option

禁止访问的path

func NoLogPathsOption added in v1.2.95

func NoLogPathsOption(noLogPaths ...string) Option

不记录日志的path

func PProfEnableOption added in v1.2.95

func PProfEnableOption(pprofEnable bool) Option

开启分析

func ServerNameOption added in v1.2.95

func ServerNameOption(serverName string) Option

服务名称

type Response added in v1.2.95

type Response struct {
	Success      bool   `json:"success"`
	Data         any    `json:"data"`
	ErrorCode    string `json:"errorCode"`
	ErrorMessage string `json:"errorMessage"`
	ShowType     uint32 `json:"showType"`
	TraceId      string `json:"traceId"`
	Host         string `json:"host"`
}

func Error added in v1.2.95

func Error(code int32, message string, v ...interface{}) *Response

Error 创建带格式化错误消息的错误响应

func ErrorResponse added in v1.2.177

func ErrorResponse(err *goerror.CodeError) *Response

func ErrorResponseX added in v1.2.179

func ErrorResponseX(errorCode string, errorMessage string, showType ...uint32) *Response

便捷方法: 快速创建错误响应

func ErrorWithValidate added in v1.2.95

func ErrorWithValidate(err error, messages map[string]string) *Response

func HttpBadRequest added in v1.2.178

func HttpBadRequest(msg string, showType ...uint32) *Response

请求格式错误,比如参数格式、参数字段名等 不正确

func HttpFailForCode added in v1.2.178

func HttpFailForCode(code int64, msg string, showType ...uint32) *Response

如需返回特殊错误码,调用此接口

func HttpForbidden added in v1.2.178

func HttpForbidden(msg string, showType ...uint32) *Response

用户已进行身份认证,但权限不够

func HttpNotFound added in v1.2.178

func HttpNotFound(msg string, showType ...uint32) *Response

接口不存在

func HttpServerError added in v1.2.178

func HttpServerError(msg string, showType ...uint32) *Response

服务器内部错误

func HttpSuccess added in v1.2.178

func HttpSuccess(data interface{}) *Response

请求成功

func HttpUnauthorized added in v1.2.178

func HttpUnauthorized(msg string, showType ...uint32) *Response

用户没有访问权限,需要进行身份认证

func SuccessResponse added in v1.2.177

func SuccessResponse(data any) *Response

便捷方法: 快速创建成功响应

func (*Response) Copy added in v1.2.95

func (rsp *Response) Copy() *Response

func (*Response) String added in v1.2.95

func (rsp *Response) String() string

type ResponseBuilder added in v1.2.177

type ResponseBuilder struct {
	// contains filtered or unexported fields
}

ResponseBuilder 是 Response 的构建器

func NewResponseBuilder added in v1.2.177

func NewResponseBuilder() *ResponseBuilder

NewResponseBuilder 创建一个新的 Response 构建器

func (*ResponseBuilder) Build added in v1.2.177

func (b *ResponseBuilder) Build() *Response

Build 构建并返回最终的 Response 对象

func (*ResponseBuilder) WithData added in v1.2.177

func (b *ResponseBuilder) WithData(data any) *ResponseBuilder

WithData 设置数据

func (*ResponseBuilder) WithErrorCode added in v1.2.177

func (b *ResponseBuilder) WithErrorCode(errorCode string) *ResponseBuilder

WithErrorCode 设置错误代码

func (*ResponseBuilder) WithErrorMessage added in v1.2.177

func (b *ResponseBuilder) WithErrorMessage(errorMessage string) *ResponseBuilder

WithErrorMessage 设置错误信息

func (*ResponseBuilder) WithHost added in v1.2.177

func (b *ResponseBuilder) WithHost(host string) *ResponseBuilder

WithHost 设置主机信息

func (*ResponseBuilder) WithShowType added in v1.2.177

func (b *ResponseBuilder) WithShowType(showType uint32) *ResponseBuilder

WithShowType 设置显示类型

func (*ResponseBuilder) WithSuccess added in v1.2.177

func (b *ResponseBuilder) WithSuccess(success bool) *ResponseBuilder

WithSuccess 设置成功状态

func (*ResponseBuilder) WithTraceId added in v1.2.177

func (b *ResponseBuilder) WithTraceId(traceId string) *ResponseBuilder

WithTraceId 设置追踪ID

type Server added in v1.2.95

type Server struct {
	*gin.Engine
}

自己定义web服务

func NewServer added in v1.2.95

func NewServer(opt ...Option) *Server

func (*Server) Run added in v1.2.95

func (s *Server) Run(addr string)

启动服务

type Token added in v1.2.95

type Token struct {
	AppId     string `json:"app_id"`
	OpenId    int64  `json:"data"`
	NonceStr  string `json:"nonce"`
	Timestamp int64  `json:"ts"`
}

func ParseToken added in v1.2.95

func ParseToken(tokenStr, appId string) (token *Token, err error)

func (*Token) Bytes added in v1.2.95

func (t *Token) Bytes() []byte

func (*Token) String added in v1.2.95

func (t *Token) String() string

Jump to

Keyboard shortcuts

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