config

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2019 License: Apache-2.0, Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIGETConfig added in v0.0.5

func APIGETConfig(c *gin.Context)

APIGETConfig 返回系统配置项 @since 0.0.4

func Authorization added in v0.0.11

func Authorization() gin.HandlerFunc

func CORS added in v0.0.10

func CORS() gin.HandlerFunc

CORS returns the location middleware with default configuration. @since v0.0.9

func GetTablePrefix added in v0.0.5

func GetTablePrefix(dbID string) string

func HTMLRender

func HTMLRender() render.HTMLRender

HTMLRender 从配置文件配置该中间件 @since 0.0.1

func Register added in v0.0.5

func Register(path ...string) error

Register 进行配置 @since 0.0.1 @since 0.0.4 change name func SetConfig(ctx context.Context, path ...string) error {

func SetDatabases

func SetDatabases() (err error)

SetDatabases 设置数据库 和对应的 db TODO 去重 @since 0.0.1

func SetGin

func SetGin()

SetGin 设置 Gin 相关配置 @since 0.0.1

func SetLog

func SetLog()

SetLog 根据配置文件取 @since 0.0.1 @since 0.0.4 解决windows下 控制台输出编码问题

Types

type CORSConfig added in v0.0.11

type CORSConfig struct {
	AllowOrigins []string `json:"allow-origins"`
	AllowMethods []string `json:"allow-methods"`
	AllowHeaders []string `json:"allow-headers"`
}

@since 0.0.10 增加跨域的配置项

type Config

type Config struct {
	Databases Databases `json:"databases"`
	System    System    `json:"system"`
	Gin       Gin       `json:"gin"`
	SQL       SQL       `json:"sql"`
	// @since 0.0.10
	CORS CORSConfig `json:"cors"`
	// @since 0.0.11
	KV KVS `json:"kv"`
}

Config 配置 @since 0.0.10 增加跨域功能

var (
	// Conf 配置
	Conf *Config

	// DefConf 默认配置
	DefConf Config

	// Cookie 配置
	// @since 0.0.2
	Cookie = cookie{
		MaxAge:   1 * 60 * 60,
		Path:     "/",
		Domain:   "",
		Secure:   false,
		HTTPOnly: false,
	}
)

@since 0.0.1

func DefaultConf

func DefaultConf() Config

DefaultConf 默认配置 这里待考虑 是写在内存里还是流出配置文件 考虑的结果是为了防止文件缺失的问题写到内存里 conf.default.json 依旧在包里供查阅 @since 0.0.1

func LoadConf

func LoadConf(path string) *Config

LoadConf 加载配置文件 @since 0.0.1

type Database

type Database struct {
	DBID        string  `json:"db_id"`
	Driver      string  `json:"driver"`
	Name        string  `json:"name"`
	User        string  `json:"user"`
	Password    string  `json:"password"`
	Host        string  `json:"host"`
	Port        string  `json:"port"`
	Charset     string  `json:"charset"`
	TablePrefix string  `json:"table_prefix"`
	DB          *sql.DB `json:"-"`
}

Database 数据库配置 @since 0.0.1

func (Database) DataSourceName

func (d Database) DataSourceName() (driverName, dataSourceName string)

DataSourceName 获取数据库连接字符串 @since 0.0.1 @since 0.0.10 取消 dburl 的引用

func (Database) DataSourceNameGORM

func (d Database) DataSourceNameGORM() string

DataSourceNameGORM 因为系统 SQL 和 GORM DNS 不一样 见下连接 详细原因待查 @since 0.0.1

type Databases

type Databases []Database

func (Databases) Get

func (d Databases) Get(dbID string) (Database, error)

Get 获取 db 操作句柄 @since 0.0.1

type Gin

type Gin struct {
	Template Template `json:"template"`
	Static   []Static `json:"static"`
}

Gin 相关的配置 @since 0.0.1

type KV added in v0.0.11

type KV struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type KVS added in v0.0.11

type KVS []KV

func (*KVS) Get added in v0.0.11

func (kvs *KVS) Get(key string) (value string, has bool)

获取 KV 的值 @since 0.0.11

func (*KVS) Set added in v0.0.11

func (kvs *KVS) Set(key string, value string)

设置系统配置项的值,暂不写入 config.json 文件

type SQL

type SQL struct {
}

@since 0.0.1

type Static

type Static struct {
	RelativePath string `json:"relative_path"`
	Root         string `json:"root"`
	Type         string `json:"type"`
}

Static 静态文件目录 @since 0.0.1 @since 0.0.10 支持单个静态文件

type System

type System struct {
	Mode    string `json:"mode"`
	Cache   bool   `json:"cache"`
	Port    string `json:"port"`
	CDNPath string `json:"cdn_path"`
	// @since 0.0.6
	Wechat  bool   `json:"wechat"`
	Version string `json:"version"`
}

System 系统配置 @since 0.0.1 @since 0.0.6 增加 echat 开关

增加 Version 版本号

type Template

type Template struct {
	Root         string `json:"root"`
	Master       string `json:"master"`
	Extension    string `json:"extension"`
	DisableCache bool   `json:"disable_cache"`
}

Template 模板配置 @since 0.0.1

Jump to

Keyboard shortcuts

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