ignition

package module
v0.0.0-...-4645e4b Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2019 License: MIT Imports: 16 Imported by: 0

README

Ignition

Ignite your passion to build a golang web application.

Features

  • Database connection pool
  • Abstract request data and validation rules to entity
  • Introduce getters to enable clients to get what they need
  • Easier validation and regulation
  • Configuration with YAML file
  • Authorization with token

Requirements

  • go1.11 or above

Examples

examples

Inspired by

Thanks to

and more.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPoolExhausted = errors.New("connection pool exhausted")
View Source
var Response = response{}

Functions

This section is empty.

Types

type Config

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

func (*Config) Load

func (c *Config) Load(file string, conf interface{}) error

Load YAML file into configuration variable

func (*Config) NeedReload

func (c *Config) NeedReload(file string) bool

Check if the configuration file need reload. If the file have been loaded and be modified since then, return true

type Conn

type Conn interface {
	Close() error
}

连接接口

type Errors

type Errors map[string][]string

type Getter

type Getter interface {
	// Since getters may be related with each other,
	// one getter may need another one to do something for it e.g.,
	// this method need to be aware of all getters.
	// Ctx should holds the data which would be passed through all getters.
	// allGetters is type of map[string]bool for easier checking if a getter exists.
	Get(ctx interface{}, allGetters map[string]bool) interface{}
}

type Model

type Model struct{}

Model holds CRUD functions

type ModelEntity

type ModelEntity struct{}

Entity defines the schema

type Pool

type Pool struct {
	ID string
	// 创建连接对象
	Dial func() (Conn, error)
	// 可存在的最大连接数
	MaxActive int
	// 最大空闲连接数
	MaxIdle         int
	IdleTimeout     time.Duration
	MaxConnLifetime time.Duration
	// 是否等待
	Wait bool
	// contains filtered or unexported fields
}

func (*Pool) Close

func (p *Pool) Close() error

关闭连接池

func (*Pool) Get

func (p *Pool) Get() (*PooledConn, error)

从池中获取连接

func (*Pool) Stat

func (p *Pool) Stat() utils.MapStr

type PooledConn

type PooledConn struct {
	Conn Conn
	// contains filtered or unexported fields
}

池中连接

func (*PooledConn) Close

func (pc *PooledConn) Close() error

关闭池外连接 = 将连接归还

func (*PooledConn) GetDB

func (pc *PooledConn) GetDB() *gorm.DB

func (*PooledConn) GetRedis

func (pc *PooledConn) GetRedis() *redis.Client

type RequestEntity

type RequestEntity struct {
	Data     interface{}         // request data
	Rules    validation.Rules    // validation rules
	Requires validation.Requires // require fields
	Errors   Errors              // validation errors
}

func (*RequestEntity) AddError

func (e *RequestEntity) AddError(field string, err string)

add or append error

func (*RequestEntity) GetFieldError

func (e *RequestEntity) GetFieldError(field string) []string

Get field error

func (*RequestEntity) HaveErrors

func (e *RequestEntity) HaveErrors() bool

Check if the entity have errors

func (*RequestEntity) HaveFieldError

func (e *RequestEntity) HaveFieldError(f string) bool

Check if field error exists

func (*RequestEntity) Validate

func (e *RequestEntity) Validate() Errors

validate request data

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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