web

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 8, 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 NotFoundError = errors.New("404 page not found")
View Source
var (
	WebNotResponse = new(any) // 接口 返回该结果 表示 web 框架 不输出 结果
)

Functions

func AppendWebApi added in v1.0.4

func AppendWebApi(webName string, webApi *WebApi)

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 FormatContext added in v1.0.4

func FormatContext(context string) string

func FormatTime

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

func GetFullPath added in v1.0.4

func GetFullPath(context string, path string) string

Types

type ApiRouter

type ApiRouter struct {
	*WebApiRouter
	*MatchRule
}

type Assets added in v1.0.4

type Assets struct {
	Open    bool   `json:"open,omitempty" yaml:"open,omitempty"`
	Context string `json:"context,omitempty" yaml:"context,omitempty"`
	Dir     string `json:"dir,omitempty" yaml:"dir,omitempty"`

	// PathSuffix 请求路径前缀
	PathPrefix string `json:"pathPrefix,omitempty" yaml:"pathPrefix,omitempty"`
	Index      string `json:"index,omitempty" yaml:"index,omitempty"`

	Cache *AssetsCache `json:"cache,omitempty" yaml:"cache,omitempty"`
	// contains filtered or unexported fields
}

func (*Assets) Init added in v1.0.4

func (this_ *Assets) Init()

type AssetsCache added in v1.0.4

type AssetsCache struct {
	Types []string `json:"types,omitempty" yaml:"types,omitempty"`
	// max-age 缓存 过期时间 秒为单位
	MaxAge int `json:"maxAge,omitempty" yaml:"maxAge,omitempty"`
	// contains filtered or unexported fields
}

type Config

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

	Host    string `json:"host,omitempty" yaml:"host,omitempty"`
	Port    int    `json:"port,omitempty" yaml:"port,omitempty"`
	Context string `json:"context,omitempty" yaml:"context,omitempty"`

	Assets     *Assets   `json:"assets,omitempty" yaml:"assets,omitempty"`
	AssetsList []*Assets `json:"assetsList,omitempty" yaml:"assetsList,omitempty"`

	Files     *Files   `json:"files,omitempty" yaml:"files,omitempty"`
	FilesList []*Files `json:"filesList,omitempty" yaml:"filesList,omitempty"`

	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 Files added in v1.0.4

type Files struct {
	Open    bool   `json:"open,omitempty" yaml:"open,omitempty"`
	Context string `json:"context,omitempty" yaml:"context,omitempty"`
	Dir     string `json:"dir,omitempty" yaml:"dir,omitempty"`

	// PathSuffix 请求路径前缀
	PathPrefix string `json:"pathPrefix,omitempty" yaml:"pathPrefix,omitempty"`
	// contains filtered or unexported fields
}

func (*Files) Init added in v1.0.4

func (this_ *Files) Init()

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
	GetFiles(name string, request *WebRequest) (res []*UploadFile, err error)
	GetWriter(request *WebRequest) io.Writer
}

type Interceptor

type Interceptor struct {
	WebInterceptor
	*MatchRule
}

type MatchRule

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

type Option

type Option func(*WebServer)

type UploadFile added in v1.0.4

type UploadFile struct {
	Filename string
	Size     int64
	io.ReadCloser
}

type WebApi

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

func GetWebApiList added in v1.0.4

func GetWebApiList(webName string) []*WebApi

func NewWebApi

func NewWebApi(path string) *WebApi

func (*WebApi) Add

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

func (*WebApi) AddFilter added in v1.0.4

func (this_ *WebApi) AddFilter(filter WebFilter) *WebApi

func (*WebApi) AddInterceptor added in v1.0.4

func (this_ *WebApi) AddInterceptor(interceptor WebInterceptor) *WebApi

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"`

	FullPath string `json:"fullPath,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) GetFiles added in v1.0.4

func (this_ *WebRequest) GetFiles(name string) (res []*UploadFile, err error)

func (*WebRequest) GetHeader

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

func (*WebRequest) GetParam

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

func (*WebRequest) GetPathParam added in v1.0.3

func (this_ *WebRequest) GetPathParam() string

func (*WebRequest) GetRequestCtx

func (this_ *WebRequest) GetRequestCtx() any

func (*WebRequest) GetWriter added in v1.0.4

func (this_ *WebRequest) GetWriter() io.Writer

func (*WebRequest) RawQuery

func (this_ *WebRequest) RawQuery() string

func (*WebRequest) RequestJSON

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

func (*WebRequest) SetHeader added in v1.0.4

func (this_ *WebRequest) SetHeader(key string, value string)

func (*WebRequest) SetStatus added in v1.0.4

func (this_ *WebRequest) SetStatus(status int)

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) AddWebApi added in v1.0.2

func (this_ *WebServer) AddWebApi(webApi *WebApi) *WebServer

func (*WebServer) AddWebApiRouters added in v1.0.2

func (this_ *WebServer) AddWebApiRouters(webApiRouters ...*WebApiRouter) *WebServer

func (*WebServer) AddWebApis added in v1.0.2

func (this_ *WebServer) AddWebApis(webApis ...*WebApi) *WebServer

func (*WebServer) AddWebFilters added in v1.0.2

func (this_ *WebServer) AddWebFilters(webFilters ...WebFilter) *WebServer

func (*WebServer) AddWebInterceptors added in v1.0.2

func (this_ *WebServer) AddWebInterceptors(webInterceptors ...WebInterceptor) *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