config

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DsnProvider

type DsnProvider interface {
	Dsn() string
}

type GeneralDB

type GeneralDB struct {
	Prefix       string `mapstructure:"prefix" json:"prefix" yaml:"prefix"`                         // 数据库前缀
	Port         string `mapstructure:"port" json:"port" yaml:"port"`                               // 数据库端口
	Config       string `mapstructure:"config" json:"config" yaml:"config"`                         // 高级配置
	Dbname       string `mapstructure:"db-name" json:"db-name" yaml:"db-name"`                      // 数据库名
	Username     string `mapstructure:"username" json:"username" yaml:"username"`                   // 数据库账号
	Password     string `mapstructure:"password" json:"password" yaml:"password"`                   // 数据库密码
	Path         string `mapstructure:"path" json:"path" yaml:"path"`                               // 数据库地址
	Engine       string `mapstructure:"engine" json:"engine" yaml:"engine" default:"InnoDB"`        // 数据库引擎,默认InnoDB
	LogMode      string `mapstructure:"log-mode" json:"log-mode" yaml:"log-mode"`                   // 是否开启Gorm全局日志
	MaxIdleConns int    `mapstructure:"max-idle-conns" json:"max-idle-conns" yaml:"max-idle-conns"` // 空闲中的最大连接数
	MaxOpenConns int    `mapstructure:"max-open-conns" json:"max-open-conns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
	Singular     bool   `mapstructure:"singular" json:"singular" yaml:"singular"`                   // 是否开启全局禁用复数,true表示开启
	LogLevel     int    `mapstructure:"log-level" json:"log-level" yaml:"log-level"`                // 日志级别(默认3) 1:Silent 2:Error 3:Warn 4:Info
}

GeneralDB 也被 Pgsql 和 Mysql 原样使用

type HttpConf

type HttpConf struct {
	MaxIdleCons        int `mapstructure:"max-idle-cons" yaml:"max-idle-cons" json:"maxIdleCons,default=10"`                          // 对所有host的最大链接数量(空闲)
	MaxIdleConsPerHost int `mapstructure:"max-idle-cons-per-host" yaml:"max-idle-cons-per-host" json:"maxIdleConsPerHost,default=10"` // 对每个host的最大链接数量(空闲)
	MaxConnsPerHost    int `mapstructure:"max-conns-per-host" yaml:"max-conns-per-host" json:"maxConnsPerHost,default=10"`            // 对每个host的最大链接数量
	IdleConnTimeout    int `mapstructure:"idle-conn-timeout" yaml:"idle-conn-timeout" json:"idleConnTimeout,default=10"`              // 最大空闲时间
	Timeout            int `mapstructure:"timeout" yaml:"timeout" json:"timeout,default=3"`                                           // 请求超时时间
	SlowThreshold      int `mapstructure:"slow-threshold" yaml:"slow-threshold" json:"slowThreshold,default=1000"`                    // 慢请求阈值
}

type Mysql

type Mysql struct {
	GeneralDB `yaml:",inline" mapstructure:",squash"`
}

func (*Mysql) Dsn

func (m *Mysql) Dsn() string

type Pgsql

type Pgsql struct {
	GeneralDB `yaml:",inline" mapstructure:",squash"`
}

func (*Pgsql) Dsn

func (p *Pgsql) Dsn() string

Dsn 基于配置文件获取 dsn Author [SliverHorn](https://github.com/SliverHorn)

func (*Pgsql) LinkDsn

func (p *Pgsql) LinkDsn(dbname string) string

LinkDsn 根据 dbname 生成 dsn Author [SliverHorn](https://github.com/SliverHorn)

type Server

type Server struct {
	System System `mapstructure:"system" json:"system" yaml:"system"`

	Mysql    Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
	PgsqlCrm Pgsql `mapstructure:"pgsql-crm" json:"pgsql-crm" yaml:"pgsql-crm"`
	// http config
	HttpConf HttpConf `mapstructure:"httpConf" json:"httpConf" yaml:"httpConf"`
}

type System

type System struct {
	Port       int    `mapstructure:"port" json:"port" yaml:"port"` // 端口值
	ApiBaseUrl string `mapstructure:"api-base-url" json:"api-base-url" yaml:"api-base-url"`
}

Jump to

Keyboard shortcuts

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