lib_ws

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

README

lib-ws

web service library

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenNotFound                  = errors.New("token not found")
	ErrInvalidHttpAuthorizationHeader = errors.New("invalid http authorization header")
)
View Source
var (
	HttpContentTypes = map[MimeType]string{
		MimeTypeBinary: "application/octet-stream",
		MimeTypePDF:    "application/pdf",
		MimeTypeMSWord: "application/msword",
		MimeTypeJPEG:   "image/jpeg",
	}
)

Functions

func AddMetaKvs

func AddMetaKvs(c *gin.Context, kvs ...string)

AddMetaKvs 添加信息到meta

func Download

func Download(c *gin.Context, mimeType MimeType, filename string, content []byte) error

Download a mime file

func Error

func Error(c *gin.Context, code int, msg string)

func Failure

func Failure(c *gin.Context, err error)

Failure grpc http错误

func Forbidden

func Forbidden(c *gin.Context, err error)

func GetAuthorizationToken

func GetAuthorizationToken(c *gin.Context) (string, error)

GetAuthorizationToken get bearer token or other token from http header

func GetMetaKvs

func GetMetaKvs(c *gin.Context) []string

GetMetaKvs 获取meta的kv pairs

func GetRealIP

func GetRealIP(c *gin.Context) string

GetRealIP 获取真实IP

func InvalidRequest

func InvalidRequest(c *gin.Context, err error)

func IsPrivateIp

func IsPrivateIp(ipStr string) bool

IsPrivateIp 检查是否是内网ip

func NewGinModule

func NewGinModule(moduleObject any, app string, functions map[string]gin.HandlerFunc) error

func PermanentRedirect

func PermanentRedirect(c *gin.Context, location string)

func Redirect

func Redirect(c *gin.Context, location string)

func Success

func Success(c *gin.Context, args ...interface{})

Success respond with data empty args respond with 'ok' message args[0] is the response data

func SuccessPages

func SuccessPages(c *gin.Context, total int64, pages interface{})

SuccessPages respond with pagination data

func SuccessRaw

func SuccessRaw(c *gin.Context, result interface{})

SuccessRaw respond with raw data

func Unauthorized

func Unauthorized(c *gin.Context, err error)

Types

type GinModule

type GinModule interface {
	Module
	RegisterHandlers(functions map[string]gin.HandlerFunc) error // 注册Handlers
	GetHandlers() map[string]gin.HandlerFunc                     // 获取handlers
}

func GetModules

func GetModules() []GinModule

type MimeType

type MimeType int
const (
	MimeTypeBinary MimeType
	MimeTypeJPEG
	MimeTypePDF
	MimeTypeMSWord
)

type Module

type Module interface {
	GetApp() string
	GetInfo() *ModuleInfo
}

type ModuleInfo

type ModuleInfo struct {
	ApiVersion int    // API版本
	Name       string // 规范化的模块名
	Dir        string // 模块所在目录
}

func ParseModuleInfo

func ParseModuleInfo(pkgPath, moduleName string) (*ModuleInfo, error)

ParseModuleInfo 合法的包路径可能为以下格式: * /path/to/v1 * /path/to/v1/pc * /path/to/v2/wxmp

type Option

type Option func(s *baseServer)

func WithGracefulShutdownWaitTime

func WithGracefulShutdownWaitTime(waitTime time.Duration) Option

func WithProviders

func WithProviders(providers ...provider.Provider) Option

type PageResponse

type PageResponse struct {
	Response
	Total int64 `json:"total"`
}

type Response

type Response struct {
	Code int         `json:"code"`
	Data interface{} `json:"data"`
	Msg  string      `json:"msg"`
}

type Route

type Route struct {
	Method  string
	Path    string
	Handler gin.HandlerFunc
}

type RouterGroup

type RouterGroup struct {
	UrlPrefix string
	// contains filtered or unexported fields
}

func (*RouterGroup) AddRoute

func (rg *RouterGroup) AddRoute(routes ...*Route) error

func (*RouterGroup) Use

func (rg *RouterGroup) Use(middlewares ...gin.HandlerFunc) *RouterGroup

type Server

type Server interface {
	Start() error
	Stop() error
	SetMode(mode string)
	GracefulStop(ctx context.Context) error
	AddRoutes(routes []*Route) error
	NewRouterGroup(urlPrefix string) *RouterGroup
}

func NewHttpServer

func NewHttpServer(address string, options ...Option) (Server, error)

Jump to

Keyboard shortcuts

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