ws

package
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: MPL-2.0 Imports: 14 Imported by: 0

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 (
	ErrDuplicateRouterGroup = errors.New("duplicate router group")
)
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, key, value 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的[key, value] slice

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 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 MimeType

type MimeType int
const (
	MimeTypeBinary MimeType
	MimeTypeJPEG
	MimeTypePDF
	MimeTypeMSWord
)

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 ServerOption

type ServerOption func(param *ServerParam)

func WithGracefulShutdownWaitTime

func WithGracefulShutdownWaitTime(waitTime time.Duration) ServerOption

type ServerParam

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

type WebServer

type WebServer 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(logger intf.LoggerProvider, address string, options ...ServerOption) (WebServer, error)

func NewHttpsServer

func NewHttpsServer(logger intf.LoggerProvider, address, certPath, keyPath string, options ...ServerOption) (WebServer, error)

Jump to

Keyboard shortcuts

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