aurora

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2022 License: Apache-2.0 Imports: 26 Imported by: 4

README

Aurora Web Framework

Stars Go Version Go Report Card License

Aurora 是用 Go(Golang) 编写的 Web 框架 ,将是 Golang 自诞生以来最好用的 Web 开发生产工具。路由处理灵活,集中式依赖管理,让项目代码结构更加优雅,专注于业务编码。

go version

go1.16+

start

package main

import "gitee.com/aurora-engine/aurora"

func main() {
	//创建 实例
	a := aurora.NewAurora()
	//注册接口
	a.Get("/", func() {
		a.Info("hello web")
	})
	//启动服务器
	aurora.Run(a)
}

document

document

about the author

作者: Awen

联系: [email protected]

thanks

该框架参考了,HttpRouter 的字典树 方式来构建路由信息

感谢 JetBrains 支持了该开源项目, 并提供了一年开发工具的支持

该项目签署了Apache授权许可,详情请参阅 LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(app Application) error

func Use

func Use(app Application, components ...Component)

Use 提供一个全局的注册器,把参数 components 加载到 Aurora实例中

Types

type Application

type Application interface {
	Use(...interface{})
	Run() error
}

type ArgsAnalysisError

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

ArgsAnalysisError 参数解析错误

func (ArgsAnalysisError) Error

func (a ArgsAnalysisError) Error() string

type Aurora

type Aurora struct {
	// 日志
	Log
	// 文件上传大小配置
	MaxMultipartMemory int64
	// contains filtered or unexported fields
}

func NewAurora

func NewAurora(option ...Option) *Aurora

func (*Aurora) Catch

func (a *Aurora) Catch(err Error)

func (*Aurora) Delete

func (a *Aurora) Delete(url string, control Controller, middleware ...Middleware)

Delete 请求

func (*Aurora) Get

func (a *Aurora) Get(url string, control Controller, middleware ...Middleware)

Get 请求

func (*Aurora) GetConfig

func (a *Aurora) GetConfig() Config

GetConfig 获取 Aurora 配置实例 对配置文件内容的读取都是协程安全的

func (*Aurora) Group

func (a *Aurora) Group(url string, middleware ...Middleware) *Group

Group 路由分组 必须以 “/” 开头分组 Group 和 Aurora 都有 相同的 http 方法注册

func (*Aurora) Head

func (a *Aurora) Head(url string, control Controller, middleware ...Middleware)

Head 请求

func (*Aurora) Post

func (a *Aurora) Post(url string, control Controller, middleware ...Middleware)

Post 请求

func (*Aurora) Put

func (a *Aurora) Put(url string, control Controller, middleware ...Middleware)

Put 请求

func (*Aurora) Run

func (a *Aurora) Run() error

Run 启动服务器

func (*Aurora) ServeHTTP

func (a *Aurora) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP 一切的开始

func (*Aurora) SysVariable

func (a *Aurora) SysVariable(v interface{}, constructor Constructor)

func (*Aurora) Url

func (a *Aurora) Url(url string, control Controller, middleware ...Middleware)

Url 结构体专属 注册器

func (*Aurora) Use

func (a *Aurora) Use(Configuration ...interface{})

Use 使用组件,把组件加载成为对应的配置

type Component

type Component map[string]interface{}

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{})

type Constructor

type Constructor func(*Proxy) interface{}

type ContentType

type ContentType map[string]string

ContentType 定义一个静态资源头类型

type Controller

type Controller = interface{}

type Ctx

type Ctx map[string]interface{}

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

func (Ctx) AddHeader

func (c Ctx) AddHeader(name, value string)

AddHeader 添加一个头

func (Ctx) Clear

func (c Ctx) Clear()

func (Ctx) DelHeader

func (c Ctx) DelHeader(name string)

DelHeader 删除一个指定的name 的头

func (Ctx) FormFile

func (c Ctx) FormFile(name string) (*multipart.FileHeader, error)

FormFile 获取文件

func (Ctx) GetHeader

func (c Ctx) GetHeader(name string) string

GetHeader 根据 name 查找一个

func (Ctx) GetPostFormArray

func (c Ctx) GetPostFormArray(key string) ([]string, bool)

func (Ctx) GetPostFormMap

func (c Ctx) GetPostFormMap(key string) (map[string]string, bool)

func (Ctx) GetQuery

func (c Ctx) GetQuery(key string) (string, bool)

func (Ctx) GetQueryArray

func (c Ctx) GetQueryArray(key string) ([]string, bool)

func (Ctx) GetQueryMap

func (c Ctx) GetQueryMap(key string) (map[string]string, bool)

func (Ctx) MultipartForm

func (c Ctx) MultipartForm() (*multipart.Form, error)

func (Ctx) PostFormMap

func (c Ctx) PostFormMap(key string) map[string]string

func (Ctx) Query

func (c Ctx) Query(key string) string

func (Ctx) QueryMap

func (c Ctx) QueryMap(key string) map[string]string

func (Ctx) Ref

func (c Ctx) Ref(ref string) interface{}

Ref 获取容器中的依赖项

func (Ctx) Request

func (c Ctx) Request() *http.Request

Request 返回元素 Request

func (Ctx) Response

func (c Ctx) Response() http.ResponseWriter

Response 返回元素 ResponseWriter

func (Ctx) Return

func (c Ctx) Return(value ...interface{})

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

func (Ctx) SetCookie

func (c Ctx) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)

SetCookie 设置一个 Cookie

type Error

type Error = interface{}

Error 错误类型 类型设计 是一个函数 接收一个 实现了 error 接口的参数

type ErrorResponse

type ErrorResponse struct {
	UrlPath      string `json:"url"`
	Status       int    `json:"code"`
	ErrorMessage string `json:"error"`
	Time         string `json:"time"`
}

type Formatter

type Formatter struct {
	*logrus.TextFormatter
}

func (*Formatter) Format

func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error)

type Group

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

group 路由分组 初始化的 分组变量不会携带全局的Use group 可以设定局部的全局Use

func (*Group) Delete

func (g *Group) Delete(url string, control Controller, middleware ...Middleware)

Delete 请求

func (*Group) Get

func (g *Group) Get(url string, control Controller, middleware ...Middleware)

Get 请求

func (*Group) Group

func (g *Group) Group(url string, middleware ...Middleware) *Group

Group 路由分组 必须以 “/” 开头分组

func (*Group) Head

func (g *Group) Head(url string, control Controller, middleware ...Middleware)

Head 请求

func (*Group) Post

func (g *Group) Post(url string, control Controller, middleware ...Middleware)

Post 请求

func (*Group) Put

func (g *Group) Put(url string, control Controller, middleware ...Middleware)

Put 请求

func (*Group) Url

func (g *Group) Url(url string, control Controller, middleware ...Middleware)

func (*Group) Use

func (g *Group) Use(middleware ...Middleware)

Use 基于 group 的分组添加 Middleware

type Log

type Log interface {
	Info(...interface{})
	Error(...interface{})
	Debug(...interface{})
	Panic(...interface{})
	Warn(...interface{})
}

Log 自定义Log需要实现的借口

type Middleware

type Middleware func(Ctx) bool

Middleware 中间件类型

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 Option

type Option func(*Aurora)

func ConfigFile

func ConfigFile(configPath string) Option

ConfigFile 指定Aurora加载配置文件

func Debug

func Debug() Option

Debug 开启debug日志

func ViperConfiguration

func ViperConfiguration(path string) Option

ViperConfiguration 配置指定配置文件

type Proxy

type Proxy struct {
	*Aurora
	Rew http.ResponseWriter
	Req *http.Request

	Ctx  Ctx
	File *MultipartFile

	UrlVariable []string
	// contains filtered or unexported fields
}

Proxy 主要完成 接口调用 和 处理响应

type UseConfiguration

type UseConfiguration func(interface{}) UseOption

type UseOption

type UseOption func(*Aurora)

UseOption 配置项 对 *Aurora 的指定属性进行 配置

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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