web

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 14 Imported by: 8

Documentation

Index

Constants

View Source
const (
	AuroraMultipartFile = "AuroraMultipartFile" //文件解析
	AuroraRequest       = "AuroraRequest"       //go 原生请求
	AuroraResponse      = "AuroraResponse"      //go 原生响应
	AuroraValues        = "AuroraValues"
	HttpStatus          = "httpStatus20230516"
)
View Source
const (
	AccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	AccessControlAllowMethods     = "Access-Control-Allow-Methods"
	AccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	AccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	AccessControlAllowCredentials = "Access-Control-Allow-Credentials"
)

Variables

This section is empty.

Functions

func ErrRecover

func ErrRecover(w http.ResponseWriter)

ErrRecover 全局错误 panic 处理

func View

func View(fullPath, relative string, static embed.FS, rew http.ResponseWriter, data Context)

Types

type Component

type Component map[string]any

Component 命名组件

type Config

type Config interface {
	SetConfigFile(string)
	SetConfigType(string)
	ReadConfig(io.Reader) error
	Set(string, interface{})
	SetDefault(string, interface{})
	GetStringMapString(string) map[string]string
	Get(string) interface{}
	GetStringSlice(string) []string
	GetStringMap(string) map[string]interface{}
	GetString(string) string
	GetStringMapStringSlice(string) map[string][]string
}

type ConfigCenter

type ConfigCenter struct {
	*viper.Viper
	*sync.RWMutex
}

ConfigCenter 配置中心 的读写锁主要用来解决分布式配置的动态刷新配置,和以后存在的并发读取配置和修改, 对于修改配置数据库连接信息或者需要重新初始化的配置项这些无法起到同步更新的效果只能保持配置信息是最新的(需要重新初始化的配置建议重启服务), 对被配置的使用实例没有并发安全的效果。

func (*ConfigCenter) Get

func (c *ConfigCenter) Get(key string) interface{}

func (*ConfigCenter) GetString

func (c *ConfigCenter) GetString(key string) string

func (*ConfigCenter) GetStringMap

func (c *ConfigCenter) GetStringMap(key string) map[string]interface{}

func (*ConfigCenter) GetStringMapString

func (c *ConfigCenter) GetStringMapString(key string) map[string]string

func (*ConfigCenter) GetStringMapStringSlice

func (c *ConfigCenter) GetStringMapStringSlice(key string) map[string][]string

func (*ConfigCenter) GetStringSlice

func (c *ConfigCenter) GetStringSlice(key string) []string

func (*ConfigCenter) ReadConfig

func (c *ConfigCenter) ReadConfig(in io.Reader) error

func (*ConfigCenter) ReadInConfig

func (c *ConfigCenter) ReadInConfig() error

func (*ConfigCenter) Set

func (c *ConfigCenter) Set(key string, value interface{})

func (*ConfigCenter) SetConfigFile

func (c *ConfigCenter) SetConfigFile(in string)

func (*ConfigCenter) SetConfigType

func (c *ConfigCenter) SetConfigType(in string)

func (*ConfigCenter) SetDefault

func (c *ConfigCenter) SetDefault(key string, value interface{})

func (*ConfigCenter) WatchRemoteConfig

func (c *ConfigCenter) WatchRemoteConfig() error

type Constructor

type Constructor func() any

Constructor 用于加载 匿名组件的构造器类型 Aurora 会执行这个函数 并把得到的变量加载到容器中

type Context

type Context map[string]interface{}

Context 上下文参数,主要用于在业务之间传递 数据使用 上下文参数中获取请求参数需要依赖于传递的参数名称 Ctx 不是线程安全的,在请求中出现多线程操作需要使用锁来保证安全性

func (Context) Clear

func (ctx Context) Clear()

func (Context) MultipartFile

func (ctx Context) MultipartFile() *MultipartFile

MultipartFile 获取POST文件上传

func (Context) Request

func (ctx Context) Request() *http.Request

Request 返回元素 Request

func (Context) Response

func (ctx Context) Response() http.ResponseWriter

Response 返回元素 ResponseWriter

func (Context) Return

func (ctx Context) Return(value ...interface{})

Return 设置中断处理,多次调用会覆盖之前设置的值

func (Context) SetStatus

func (ctx Context) SetStatus(status int)

SetStatus 设置Http响应状态码 此 api 会覆盖控制器解析 返回值中 error 的默认状态码

func (Context) Status

func (ctx Context) Status() int

Status 获取 http 响应状态 响应状态来自于解析处理器执行结果,默认值为 200 执行结果有错误返回 Status 状态将会发送改变 改变的后的状态 在 拦截器的After阶段能够获取得到

type ControlInfo

type ControlInfo struct {
	Path        string
	Control     any
	Interceptor []Interceptor
}

ControlInfo 用于存储在服务器启动之前注册的接口信息,需要在加载完配置项之后进行统一注册

type CorsHandle

type CorsHandle func(r *http.Request, w http.ResponseWriter) bool

CorsHandle 跨域处理器

type Default

type Default struct {
	Method           map[string][]string //运行跨域的 HTTP请求类型
	Host             map[string][]string //允许跨域的主机
	AllowOrigin      []string
	AllowMethods     []string
	AllowHeaders     []string
	AllowCredentials []string
	ExposeHeaders    []string
	// contains filtered or unexported fields
}

func NewDefaultCors

func NewDefaultCors() *Default

func (*Default) Domain

func (d *Default) Domain(method string, url ...string)

Domain 添加跨域路径

func (*Default) Handle

func (d *Default) Handle() CorsHandle

Handle 返回一个跨域处理器

func (*Default) Origin

func (d *Default) Origin(host string, method ...string)

Origin 配置可跨域主机

type Interceptor

type Interceptor interface {
	Before(ctx Context, handler any) (bool, error)

	Complete(ctx Context, handler any) error

	After(ctx Context, handler any) error
}

Interceptor 拦截器

type MultipartFile

type MultipartFile struct {
	File map[string][]*multipart.FileHeader
}

func (*MultipartFile) SaveUploadedFile

func (m *MultipartFile) SaveUploadedFile(file *multipart.FileHeader, dst string) error

SaveUploadedFile 保存文件

type Recover

type Recover func(w http.ResponseWriter)

Recover 用于处理服务器中出现的 panic 消息自定义

type Response

type Response interface {
	SetMessage(msg string)
	SetError(err error)
	SetCode(code string)
	SetData(data any)
	String() string
}

type Variate

type Variate func(ctx Context) any

Variate 用于配置web系统变量函数

type Verify

type Verify func(value any) error

type ViewHandle

type ViewHandle func(string, string, embed.FS, http.ResponseWriter, Context)

ViewHandle 是整个服务器对视图渲染的核心函数,开发者实现改接口对需要展示的页面进行自定义处理

Jump to

Keyboard shortcuts

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