yl

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2022 License: MIT Imports: 25 Imported by: 0

README

yl

v.1.0.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorMsg

func ErrorMsg(err error, msg ...string)

func Run

func Run(app Application) error

func Use

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

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

Types

type Application

type Application interface {
	// Use 加载配置
	Use(...interface{})

	// Server 服务器初始化
	// 依赖加载 等操作在这个函数中进行
	Server()

	// Router 路由加载函数
	Router()
	// contains filtered or unexported methods
}

Application YL应用程序接口 通过继承YL 实例来完成web服务的构建

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

func (*ConfigCenter) WatchRemoteConfig

func (c *ConfigCenter) WatchRemoteConfig() error

type Constructor

type Constructor func(*Proxy) interface{}

type Constructors

type Constructors func() interface{}

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

type Controller

type Controller = interface{}

type Ctx

type Ctx map[string]interface{}

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

func (Ctx) Clear

func (c Ctx) Clear()

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 设置中断处理,多次调用会覆盖之前设置的值

type Engine

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

func New

func New(option ...Option) *Engine

func (*Engine) Catch

func (engine *Engine) Catch(err Error)

func (*Engine) Delete

func (engine *Engine) Delete(url string, control Controller, middleware ...Middleware)

Delete 请求

func (*Engine) Get

func (engine *Engine) Get(url string, control Controller, middleware ...Middleware)

Get 请求

func (*Engine) GetConfig

func (engine *Engine) GetConfig() Config

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

func (*Engine) Group

func (engine *Engine) Group(url string, middleware ...Middleware) *Group

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

func (*Engine) Head

func (engine *Engine) Head(url string, control Controller, middleware ...Middleware)

Head 请求

func (*Engine) Post

func (engine *Engine) Post(url string, control Controller, middleware ...Middleware)

Post 请求

func (*Engine) Put

func (engine *Engine) Put(url string, control Controller, middleware ...Middleware)

Put 请求

func (*Engine) Root

func (engine *Engine) Root() string

func (*Engine) ServeHTTP

func (engine *Engine) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP 一切的开始

func (*Engine) SysVariable

func (engine *Engine) SysVariable(v interface{}, constructor Constructor)

func (*Engine) Use

func (engine *Engine) Use(Configuration ...interface{})

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

type Error

type Error = interface{}

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

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
}

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) 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(*Engine)

func ConfigFile

func ConfigFile(configPath string) Option

ConfigFile 指定YL加载配置文件

func Debug

func Debug() Option

Debug 开启debug日志

type Proxy

type Proxy struct {
	*Engine
	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(engine *Engine)

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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