config

package
v0.0.0-...-1bcc78e Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalFlags = []cli.Flag{
	cli.BoolFlag{
		Name:   "debug",
		Usage:  "run in debug mode",
		EnvVar: "CENTAUR_DEBUG",
	},
	cli.StringFlag{
		Name:   "log-level",
		Usage:  "specify log level, value is one of [trace, debug, info, warning, error, fatal or panic]",
		Value:  "info",
		EnvVar: "CENTAUR_LOG_LEVEL",
	},
	cli.StringFlag{
		Name:   "config-file, c",
		Usage:  "load configuration from `FILENAME`",
		Value:  "./centaur.yml",
		EnvVar: "CENTAUR_CONFIG_FILE",
	},
	cli.StringFlag{
		Name:   "http-host, h",
		Usage:  "HTTP server host",
		Value:  "",
		EnvVar: "CENTAUR_HTTP_HOST",
	},
	cli.StringFlag{
		Name:   "http-port, p",
		Usage:  "HTTp server port",
		Value:  "80",
		EnvVar: "CENTAUR_HTTP_PORT",
	},
	cli.StringFlag{
		Name:   "mysql-host",
		Usage:  "MySQL server host",
		Value:  "",
		EnvVar: "CENTAUR_MYSQL_HOST",
	},
	cli.StringFlag{
		Name:   "mysql-port",
		Usage:  "MySQL server host",
		Value:  "3306",
		EnvVar: "CENTAUR_MYSQL_HOST",
	},
	cli.BoolFlag{
		Name:   "daemonize, d",
		Usage:  "run centaur as Daemon",
		EnvVar: "CENTAUR_DAEMON_MODE",
	},
}

GlobalFlags are Global CLI Flags

Functions

This section is empty.

Types

type CORS

type CORS struct {
	CORSEnable       bool     `yaml:"cors-enable"`
	AllowOrigins     []string `yaml:"allow-origins"`
	AllowMethods     []string `yaml:"allow-methods"`
	AllowHeaders     []string `yaml:"allow-headers"`
	AllowCredentials bool     `yaml:"allow-credentials"`
	MaxAge           int      `yaml:"max-age"`
}

CORS 描述跨域请求配置

type Captcha

type Captcha struct {
	Length      int    `yaml:"length"`
	Width       int    `yaml:"width"`
	Height      int    `yaml:"height"`
	RedisPrefix string `yaml:"redis_prefix"`
}

Captcha 指定验证码配置,包括验证码位数/高度/宽度/验证码的redis前缀等

type Config

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

func GetGlobalConfig

func GetGlobalConfig() *Config

func NewConfig

func NewConfig(ctx *cli.Context) *Config

NewConfig will return a Config instance with parameters generated from cli.Context

func (*Config) CORS

func (c *Config) CORS() *CORS

CORS will return CORS settings.

func (*Config) CaptchaConf

func (c *Config) CaptchaConf() *Captcha

CaptchaConf returns Login Captcha config

func (*Config) CloseDB

func (c *Config) CloseDB() error

CloseDB will cut the connection to DB and return the error if failed.

func (*Config) DB

func (c *Config) DB() *gorm.DB

DB will return DB connection.

func (*Config) DaemonLogFile

func (c *Config) DaemonLogFile() string

DaemonLogFile will return log output file at daemon mode

func (*Config) DaemonPidFile

func (c *Config) DaemonPidFile() string

DaemonPidFile will return pid file at daemon mode

func (*Config) DatabaseDSN

func (c *Config) DatabaseDSN() string

DatabaseDSN will return the connect string of database

func (*Config) Debug

func (c *Config) Debug() bool

Debug will return true if server is set to running at debug mode.

func (*Config) HttpServerHost

func (c *Config) HttpServerHost() string

HttpServerHost will return the host ip which is listening for new connections.

func (*Config) HttpServerMode

func (c *Config) HttpServerMode() string

HttpServerMode will return under which mode server will be running.

func (*Config) HttpServerPort

func (c *Config) HttpServerPort() uint16

HttpServerPort will return HTTP Server's using port.

func (*Config) InitDB

func (c *Config) InitDB(ctx context.Context) error

InitDB will initialize DB configuration

func (*Config) JWTConf

func (c *Config) JWTConf() *JWT

JWTConf will return JWT authentication config(config.JWT)

func (*Config) RedisConf

func (c *Config) RedisConf() *Redis

RedisConf will return Redis settings

func (*Config) ShouldDaemonize

func (c *Config) ShouldDaemonize() bool

ShouldDaemonize will return true if daemon mode is set.

func (*Config) ShutDown

func (c *Config) ShutDown()

ShutDown will release the using resources. inlcuding DB connection, ...

func (*Config) StaticPath

func (c *Config) StaticPath() string

StaticPath will return where are static files stored.

func (*Config) SuperAdmin

func (c *Config) SuperAdmin() *SpAdmin

SuperAdmin returns User who owns root permission

type JWT

type JWT struct {
	SigningMethod string `yaml:"signing_method"`
	SigningKey    string `yaml:"signing_key"`
	Expired       int    `yaml:"expired"`
	RedisPrefix   string `yaml:"redis_prefix"`
}

type Params

type Params struct {
	Name           string
	Version        string
	Debug          bool   `yaml:"debug" flag:"debug"`
	LogLevel       string `yaml:"log-level" flag:"log-level"`
	ConfigFile     string
	ConfigPath     string   `yaml:"config-path" flag:"config-path"`
	DbType         string   `yaml:"db-type" flag:"db-type"`
	DbServerHost   string   `yaml:"db-host" flag:"db-host"`
	DbServerPort   uint16   `yaml:"db-port" flag:"db-port"`
	DbUserName     string   `yaml:"db-user" flag:"db-user"`
	DbPassword     string   `yaml:"db-password" flag:"db-password"`
	DbName         string   `yaml:"db-name" flag:"db-name"`
	HttpServerHost string   `yaml:"http-host" flag:"http-host"`
	HttpServerPort uint16   `yaml:"http-port" flag:"http-port"`
	HttpServerMode string   `yaml:"http-server-mode" flag:"http-server-mode"`
	DaemonMode     bool     `yaml:"daemon" flag:"daemon"`
	DaemonPidPath  string   `yaml:"daemon-pid-path" flag:"daemon-pid-path"`
	DaemonLogPath  string   `yaml:"daemon-log-path" flag:"daemon-log-path"`
	StaticPath     string   `yaml:"static-path" flag:"static-path"`
	CORS           *CORS    `yaml:"cors"`
	RedisConf      *Redis   `yaml:"redis"`
	CaptchaConf    *Captcha `yaml:"captcha"`
	SuperAdmin     *SpAdmin `yaml:"superadmin"`
	JWTConf        *JWT     `yaml:"jwt"`
}

Params stores the application config

func NewParams

func NewParams(ctx *cli.Context) *Params

NewParams will return an instance of struct Params

func (*Params) LoadFromFile

func (p *Params) LoadFromFile(file string) error

LoadFromFile will read config from config file and parse it into *Params

type Redis

type Redis struct {
	Addr      string `yaml:"addr"`
	Password  string `yaml:"password"`
	KeyPrefix string `yaml:"key-prefix"`
}

Redis配置,包括连接参数以及key前缀

type SpAdmin

type SpAdmin struct {
	UserName string `yaml:"username"`
	RealName string `yaml:"realname"`
	Password string `yaml:"password"`
}

Jump to

Keyboard shortcuts

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