web

package
v1.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	WebDefaultWriter    = &webDefaultWriter{outLog: true}
	WebDefaultNotWriter = &webDefaultWriter{outLog: false}

	WebErrorWriter    = &webErrorWriter{outLog: true}
	WebErrorNotWriter = &webErrorWriter{outLog: false}
)
View Source
var (
	WebNotResponse = new(any) // 接口 返回该结果 表示 web 框架 不输出 结果
)

Functions

func AppendWebApiRouter

func AppendWebApiRouter(webName string, webApiRouter *WebApiRouter, handle WebApiHandleFunc)

func AppendWebFilter

func AppendWebFilter(webName string, webFilter WebFilter)

func AppendWebInterceptor

func AppendWebInterceptor(webName string, webInterceptor WebInterceptor)

func FormatTime

func FormatTime(t time.Time) (res string)

Types

type ApiRouter

type ApiRouter struct {
	*WebApiRouter
	*MatchRule
}

type Config

type Config struct {
	// Disabled 禁用 上层 初始化服务时候 可以判断该属性 如果为 配置 true 则不去初始化服务
	Disabled bool `json:"disabled,omitempty" yaml:"disabled,omitempty"`

	Host           string `json:"host,omitempty"`
	Port           int    `json:"port,omitempty"`
	Context        string `json:"context,omitempty"`
	AssetsDir      string `json:"assetsDir,omitempty"`
	AssetsSeparate string `json:"assetsSeparate,omitempty"` // assets 分割字符 默认 assets/
	FilesDir       string `json:"filesDir,omitempty"`
	FilesSeparate  string `json:"filesSeparate,omitempty"` // files 分割字符 默认 files/

	MaxMultipartMemory int64 `json:"maxMultipartMemory,omitempty"`

	Tls *ConfigTls `json:"tls,omitempty"`

	Locations     []*ConfigLocation         `json:"locations,omitempty"`
	Replaces      map[string]*ConfigReplace `json:"replaces,omitempty"`
	GinDefaultLog bool                      `json:"ginDefaultLog,omitempty"`
	GinErrorLog   bool                      `json:"ginErrorLog,omitempty"`
}

func (*Config) Init

func (this_ *Config) Init()

type ConfigLocation

type ConfigLocation struct {
	Path string `json:"path,omitempty"`
	To   string `json:"to,omitempty"`
}

type ConfigReplace

type ConfigReplace struct {
	Path        string `json:"path,omitempty"`
	ContentType string `json:"contentType,omitempty"`
	Content     string `json:"content,omitempty"`
	Append      string `json:"append,omitempty"`
}

type ConfigTls

type ConfigTls struct {
	Open     bool   `json:"open,omitempty"`
	CertFile string `json:"certFile,omitempty"`
	KeyFile  string `json:"keyFile,omitempty"`
}

type Filter

type Filter struct {
	WebFilter
	*MatchRule
}

type IWebService

type IWebService interface {
	Init() (err error)
	Serve() (err error)
	RequestRead(request *WebRequest) []byte
	SetStatus(request *WebRequest, status int)
	GetHeader(request *WebRequest, key string) string
	SetHeader(request *WebRequest, key, value string)
	ResponseWrite(request *WebRequest, data []byte)
	ResponseWriteByReader(request *WebRequest, reader io.Reader) (written int64, err error)
	GetParam(request *WebRequest, key string) string
	RawQuery(request *WebRequest) string
	ClientIP(request *WebRequest) string
	UserAgent(request *WebRequest) string
}

type Interceptor

type Interceptor struct {
	WebInterceptor
	*MatchRule
}

type MatchRule

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

type Option

type Option func(*WebServer)

type WebApi

type WebApi struct {
	Path   string // 路由
	Method string // HTTP 方法 GET、POST 等
	// contains filtered or unexported fields
}

func NewWebApi

func NewWebApi(path string) *WebApi

func (*WebApi) Add

func (this_ *WebApi) Add(path string, handle WebApiHandleFunc) *WebApiRouter

func (*WebApi) Router

func (this_ *WebApi) Router(router *WebApiRouter) *WebApi

func (*WebApi) SetMethod

func (this_ *WebApi) SetMethod(method string) *WebApi

type WebApiHandleFunc

type WebApiHandleFunc func(request *WebRequest) (res any, err error)

type WebApiRouter

type WebApiRouter struct {
	Path     string // 路由
	Method   string // HTTP 方法 GET、POST 等
	Comment  string // 说明
	NotLogin bool   // 不需要登录
	NotLog   bool   // 不需要日志
	// contains filtered or unexported fields
}

func GetWebApiRouterList

func GetWebApiRouterList(webName string) []*WebApiRouter

func NewApiRouter

func NewApiRouter(path string) *WebApiRouter

func (*WebApiRouter) GetHandle

func (this_ *WebApiRouter) GetHandle() WebApiHandleFunc

func (*WebApiRouter) SetComment

func (this_ *WebApiRouter) SetComment(comment string) *WebApiRouter

func (*WebApiRouter) SetGet

func (this_ *WebApiRouter) SetGet() *WebApiRouter

func (*WebApiRouter) SetHandle

func (this_ *WebApiRouter) SetHandle(handle WebApiHandleFunc) *WebApiRouter

func (*WebApiRouter) SetMethod

func (this_ *WebApiRouter) SetMethod(method string) *WebApiRouter

func (*WebApiRouter) SetNotLog

func (this_ *WebApiRouter) SetNotLog() *WebApiRouter

func (*WebApiRouter) SetNotLogin

func (this_ *WebApiRouter) SetNotLogin() *WebApiRouter

func (*WebApiRouter) SetPost

func (this_ *WebApiRouter) SetPost() *WebApiRouter

type WebFilter

type WebFilter interface {
	GetName() string           // 定义名称
	Order() int                // 顺序 正序 排序 值越小 则优先
	GetMatch() WebRequestMatch // 请求 匹配 配置
	DoFilter(request *WebRequest, chain WebFilterChain) (err error)
}

func GetWebFilterList

func GetWebFilterList(webName string) []WebFilter

type WebFilterChain

type WebFilterChain func(request *WebRequest) (err error)

type WebInterceptor

type WebInterceptor interface {
	GetName() string           // 定义名称
	Order() int                // 顺序 正序 排序 值越小 则优先
	GetMatch() WebRequestMatch // 请求 匹配 配置
	Before(request *WebRequest) (toContinue bool, err error)
	After(request *WebRequest) (toContinue bool, err error)
}

func GetWebInterceptorList

func GetWebInterceptorList(webName string) []WebInterceptor

type WebRequest

type WebRequest struct {
	Path            string        `json:"path,omitempty"`
	Method          string        `json:"method,omitempty"`
	WebSession      *WebSession   `json:"webSession,omitempty"`
	StartTime       time.Time     `json:"startTime,omitempty"`
	EndTime         time.Time     `json:"endTime,omitempty"`
	HandleStartTime time.Time     `json:"handleStartTime,omitempty"`
	HandleEndTime   time.Time     `json:"handleEndTime,omitempty"`
	Response        any           `json:"response,omitempty"`
	WebApiRouter    *WebApiRouter `json:"webApiRouter,omitempty"`

	Body []byte `json:"-"`
	// contains filtered or unexported fields
}

func NewWebRequest

func NewWebRequest(requestCtx any) *WebRequest

func (*WebRequest) ClientIP

func (this_ *WebRequest) ClientIP() string

func (*WebRequest) GetData

func (this_ *WebRequest) GetData() []byte

func (*WebRequest) GetHeader

func (this_ *WebRequest) GetHeader(key string) string

func (*WebRequest) GetParam

func (this_ *WebRequest) GetParam(key string) string

func (*WebRequest) GetRequestCtx

func (this_ *WebRequest) GetRequestCtx() any

func (*WebRequest) RawQuery

func (this_ *WebRequest) RawQuery() string

func (*WebRequest) RequestJSON

func (this_ *WebRequest) RequestJSON(data any) (err error)

func (*WebRequest) UserAgent

func (this_ *WebRequest) UserAgent() string

type WebRequestMatch

type WebRequestMatch struct {
	Includes []string // 包含路径 表达式 匹配 路径
	Excludes []string // 忽略路径 表达式 匹配 路径
	Methods  []string // HTTP 方法 GET、POST 等
}

type WebResponse

type WebResponse struct {
	Code string      `json:"code"`
	Msg  string      `json:"msg,omitempty"`
	Data interface{} `json:"data,omitempty"`
}

type WebServer

type WebServer struct {
	IWebService

	framework.Logger
	// contains filtered or unexported fields
}

func New

func New(name string, webConfig *Config, opts ...Option) *WebServer

func (*WebServer) Bin

func (this_ *WebServer) Bin(apiRouters ...*WebApiRouter)

func (*WebServer) Close

func (this_ *WebServer) Close()

func (*WebServer) DoRequest

func (this_ *WebServer) DoRequest(request *WebRequest)

func (*WebServer) GetAddr

func (this_ *WebServer) GetAddr() string

func (*WebServer) GetConfig

func (this_ *WebServer) GetConfig() *Config

func (*WebServer) GetListener

func (this_ *WebServer) GetListener() net.Listener

func (*WebServer) GetServerUrl

func (this_ *WebServer) GetServerUrl() string

func (*WebServer) GetServerUrls

func (this_ *WebServer) GetServerUrls() []string

func (*WebServer) GetWebDefaultWriter

func (this_ *WebServer) GetWebDefaultWriter() io.Writer

func (*WebServer) GetWebErrorWriter

func (this_ *WebServer) GetWebErrorWriter() io.Writer

func (*WebServer) ResponseJsonData

func (this_ *WebServer) ResponseJsonData(request *WebRequest, data any, err error)

func (*WebServer) Start

func (this_ *WebServer) Start() (err error)

type WebSession

type WebSession struct {
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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