config

package
v0.0.25 Latest Latest
Warning

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

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

Documentation

Overview

config 系统底层的配置文件相关模块 支持第三方应用的 kv 配置 支持定义各种数据库连接格式 做了些基础设置和模板函数

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIGETConfig

func APIGETConfig(c *gin.Context)

APIGETConfig 返回系统配置项 @since 0.0.4

func Authorization

func Authorization() gin.HandlerFunc

func CORS

func CORS() gin.HandlerFunc

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

func GetTablePrefix

func GetTablePrefix(dbID string) string

func HTMLRender

func HTMLRender() render.HTMLRender

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

func Register

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

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

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

type KVS

type KVS []KV

func (*KVS) Get

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

获取 KV 的值 @since 0.0.11

func (*KVS) Set

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