config

package
v5.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: AGPL-3.0 Imports: 59 Imported by: 57

Documentation

Overview

Nging is a toolbox for webmasters Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	LockFileName = `installed.lock`
)

Variables

View Source
var (
	Installed sql.NullBool

	ErrUnknowDatabaseType = errors.New(`unkown database type`)
)
View Source
var (
	SessionOptions *echo.SessionOptions
	CookieOptions  *cookie.CookieOptions
	SessionEngine  = `file`
	SessionName    = `SID`
)
View Source
var (
	DBConnecters = map[string]func(sdb.DB) (sqlbuilder.Database, error){
		`mysql`: ConnectMySQL,
	}
	DBInstallers = map[string]func(string) error{
		`mysql`: ExecMySQL,
	}
	DBCreaters = map[string]func(error, sdb.DB) error{
		`mysql`: CreaterMySQL,
	}
	DBUpgraders = map[string]func(string, *sync.Config, sdb.DB) (DBOperators, error){
		`mysql`: UpgradeMySQL,
	}
	DBEngines         = echo.NewKVData().Add(`mysql`, `MySQL`)
	ParseTimeDuration = ssystem.ParseTimeDuration
	ParseBytes        = ssystem.ParseBytes
)
View Source
var CmdIsRunning = com.CmdIsRunning
View Source
var DefaultLogCategories = []string{`db`, `echo,mock`}
View Source
var DefaultPort = 9999
View Source
var DefaultStartup = `task`
View Source
var ErrCmdNotRunning = errors.New(`command is not running`)
View Source
var Navigations = []*Navigation{}
View Source
var Setting = common.Setting
View Source
var Version = &VersionInfo{Name: `Nging`}

Version 版本信息

Functions

func ConnectDB

func ConnectDB(c sdb.DB, index int, name string) error

func ConnectMySQL

func ConnectMySQL(c sdb.DB) (sqlbuilder.Database, error)

func CreaterMySQL

func CreaterMySQL(err error, c sdb.DB) error

func ExecMySQL

func ExecMySQL(sqlStr string) error

func FireInitSettings

func FireInitSettings(configs echo.H) error

func FireSetSettings

func FireSetSettings(group string, diffs Diffs) error

func FixWd added in v5.1.3

func FixWd() error

func FromDB

func FromDB(group ...string) echo.H

func GetInsertSQLs

func GetInsertSQLs() map[string][]string

func GetInstallSQLs

func GetInstallSQLs() map[string][]string

func GetPreupgradeSQLFiles

func GetPreupgradeSQLFiles() []string

func GetPreupgradeSQLs

func GetPreupgradeSQLs() map[string]map[string][]string

func GetSQLInsertFiles

func GetSQLInsertFiles() []string

func GetSQLInstallFiles

func GetSQLInstallFiles() ([]string, error)

func InitSessionOptions

func InitSessionOptions(c *Config)

func InstalledLockFile

func InstalledLockFile() string

func IsInstalled

func IsInstalled() bool

func JoinVersionLabel added in v5.0.1

func JoinVersionLabel(number string, label string) string

func MustOK

func MustOK(err error)

func OnGroupSetSettings

func OnGroupSetSettings(groupAndKey string, fn func(Diffs) error)

func OnKeySetSettings

func OnKeySetSettings(groupAndKey string, fn func(Diff) error)

func OnceUpgradeDB

func OnceUpgradeDB() error

func ParseConfig

func ParseConfig() error

func QueryTo

func QueryTo(sqlStr string, result interface{}) (sqlbuilder.Iterator, error)

func RegisterInsertSQL

func RegisterInsertSQL(project string, insertSQL string)

func RegisterInstallSQL

func RegisterInstallSQL(project string, installSQL string)

func RegisterPreupgradeSQL

func RegisterPreupgradeSQL(project string, version, preupgradeSQL string)

func SetInstalled

func SetInstalled(lockFile string) error

func Table

func Table(table string) string

func ToTable

func ToTable(m sqlbuilder.Name_) string

func UpgradeDB

func UpgradeDB()

func WatchConfig

func WatchConfig(fn func(string) error)

Types

type CLIConfig

type CLIConfig struct {
	BackendDomain  string //后台绑定域名
	FrontendDomain string //前台绑定域名
	Address        string //监听IP地址
	Port           int    //监听端口
	Conf           string //自定义配置文件
	Confd          string //系统默认配置目录
	Confx          string //子模块配置文件
	Type           string //启动类型: webserver/ftpserver/manager
	Startup        string //manager启动时同时启动的服务,可选的有webserver/ftpserver,如有多个需用半角逗号“,”隔开
	// contains filtered or unexported fields
}

func FromCLI

func FromCLI() *CLIConfig

func NewCLIConfig

func NewCLIConfig() *CLIConfig

func (*CLIConfig) Close

func (c *CLIConfig) Close() error

func (*CLIConfig) CmdGet

func (c *CLIConfig) CmdGet(typeName string) *exec.Cmd

func (*CLIConfig) CmdGroupStop

func (c *CLIConfig) CmdGroupStop(groupName string) error

func (*CLIConfig) CmdHasGroup

func (c *CLIConfig) CmdHasGroup(groupName string) bool

func (*CLIConfig) CmdSendSignal

func (c *CLIConfig) CmdSendSignal(typeName string, sig os.Signal) error

func (*CLIConfig) CmdSet

func (c *CLIConfig) CmdSet(name string, cmd *exec.Cmd)

func (*CLIConfig) CmdStop

func (c *CLIConfig) CmdStop(typeName string) error

func (*CLIConfig) ConfDir

func (c *CLIConfig) ConfDir() string

func (*CLIConfig) GenerateIDFromConfigFileName

func (c *CLIConfig) GenerateIDFromConfigFileName(configFile string, musts ...bool) string

func (*CLIConfig) InitEnviron

func (c *CLIConfig) InitEnviron(needFindEnvFile ...bool) (err error)

func (*CLIConfig) InitFlag

func (c *CLIConfig) InitFlag(flagSet *pflag.FlagSet)

func (*CLIConfig) IsRunning

func (c *CLIConfig) IsRunning(cmdType string) bool

func (*CLIConfig) Kill

func (c *CLIConfig) Kill(cmd *exec.Cmd) error

func (*CLIConfig) OnlyRunServer

func (c *CLIConfig) OnlyRunServer() bool

func (*CLIConfig) ParseConfig

func (c *CLIConfig) ParseConfig()

func (*CLIConfig) Pid

func (c *CLIConfig) Pid() int

func (*CLIConfig) Reload

func (c *CLIConfig) Reload(cfg *Config, cts ...string) error

func (*CLIConfig) RunStartup

func (c *CLIConfig) RunStartup()

RunStartup manager启动时同时启动的服务

func (*CLIConfig) SendSignal

func (c *CLIConfig) SendSignal(cmd *exec.Cmd, sig os.Signal) error

func (*CLIConfig) SendSignalToAllCmd added in v5.2.0

func (c *CLIConfig) SendSignalToAllCmd(sig os.Signal) error

func (*CLIConfig) SetLogWriter

func (c *CLIConfig) SetLogWriter(cmdType string, writer ...io.Writer) error

func (*CLIConfig) WatchEnvConfig

func (c *CLIConfig) WatchEnvConfig()

type Config

type Config struct {
	DB       sdb.DB          `json:"db"`
	Sys      ssystem.System  `json:"sys"`
	Cron     scron.Cron      `json:"cron"`
	Cookie   scookie.Config  `json:"cookie"`
	Language language.Config `json:"language"`
	Extend   echo.H          `json:"extend,omitempty"`

	// 自定义validator 验证规则。map 的 key 为规则标识,值为规则
	Validations Validations `json:"validations"`
	// contains filtered or unexported fields
}

func FromFile

func FromFile() *Config

func InitConfig

func InitConfig() (*Config, error)

func MustGetConfig

func MustGetConfig() *Config

func NewConfig

func NewConfig() *Config

func (*Config) APIKey

func (c *Config) APIKey() string

func (*Config) AsDefault

func (c *Config) AsDefault()

func (*Config) Codec

func (c *Config) Codec(lengths ...int) codec.Codec

func (*Config) ConfigFromDB

func (c *Config) ConfigFromDB() echo.H

func (*Config) ConnectedDB

func (c *Config) ConnectedDB(autoConn ...bool) bool

ConnectedDB 数据库是否已连接,如果没有连接则自动连接

func (*Config) CookieConfig

func (c *Config) CookieConfig() scookie.Config

func (*Config) Debug

func (c *Config) Debug() bool

func (*Config) Decode

func (c *Config) Decode(encrypted string, keys ...string) string

func (*Config) Encode

func (c *Config) Encode(raw string, keys ...string) string

func (*Config) GenerateRandomKey

func (c *Config) GenerateRandomKey() string

func (*Config) GenerateSample

func (c *Config) GenerateSample() error

func (*Config) GetExtend added in v5.2.5

func (c *Config) GetExtend() echo.H

func (*Config) GetMaxRequestBodySize

func (c *Config) GetMaxRequestBodySize() int

func (*Config) InitExtend

func (c *Config) InitExtend() *Config

func (*Config) InitSecretKey

func (c *Config) InitSecretKey() *Config

func (*Config) IsEnv

func (c *Config) IsEnv(env string) bool

func (*Config) IsEnvDev

func (c *Config) IsEnvDev() bool

func (*Config) IsEnvProd

func (c *Config) IsEnvProd() bool

func (*Config) PrintExtend added in v5.1.0

func (c *Config) PrintExtend()

func (*Config) Reload

func (c *Config) Reload(newConfig *Config) error

func (*Config) SaveToFile

func (c *Config) SaveToFile() error

func (*Config) SetDebug

func (c *Config) SetDebug(on bool) *Config

func (*Config) SetDefaults

func (c *Config) SetDefaults(configFile string)

func (*Config) Settings

func (c *Config) Settings() *Settings

func (*Config) UnregisterExtend

func (c *Config) UnregisterExtend(key string)

type DBOperators

type DBOperators struct {
	Source      sync.DBOperator
	Destination sync.DBOperator
}

func UpgradeMySQL

func UpgradeMySQL(schema string, syncConfig *sync.Config, cfg sdb.DB) (DBOperators, error)

type Diff

type Diff struct {
	Old    interface{}
	New    interface{}
	IsDiff bool
}

func (Diff) String

func (d Diff) String() string

type Diffs

type Diffs map[string]*Diff

func (Diffs) Get

func (d Diffs) Get(key string) interface{}

type Email

type Email struct {
	*mail.SMTPConfig
	Timeout   int64  //超时时间(秒),采用默认引擎发信时,此项无效
	Engine    string //值为email时采用github.com/jordan-wright/email包发送,否则采用默认的github.com/admpub/mail发送
	From      string //发信人Email地址
	QueueSize int    //允许同一时间发信的数量
}

func (*Email) Init

func (c *Email) Init()

func (*Email) SetBy

func (c *Email) SetBy(r echo.H, defaults echo.H) *Email

type Log

type Log struct {
	Debug        bool     `json:"debug"`
	Colorable    bool     `json:"colorable"`    // for console
	SaveFile     string   `json:"saveFile"`     // for file
	FileMaxBytes int64    `json:"fileMaxBytes"` // for file
	Targets      string   `json:"targets" form_delimiter:","`
	Categories   []string `json:"cagegories"`
}

func (*Log) Init

func (c *Log) Init()

func (*Log) LogCategories

func (c *Log) LogCategories() []string

func (*Log) LogFile

func (c *Log) LogFile() string

func (*Log) LogFilename

func (c *Log) LogFilename(category string) (string, error)

func (*Log) SetBy

func (c *Log) SetBy(r echo.H, defaults echo.H) *Log

func (*Log) Show

func (c *Log) Show(ctx echo.Context) error
type Navigation struct {
	Children []*Navigation
	URL      string
	Name     string
	Label    string
	Pjax     string
	Attrs    map[string]string
}

func NewNavigation

func NewNavigation() *Navigation

type ReloadByConfig

type ReloadByConfig interface {
	ReloadByConfig(cfg *Config, args ...string) error
}

type SQLCollection

type SQLCollection struct {
	Install    map[string][]string            //{ project:[sql-content] }
	Insert     map[string][]string            //{ project:[sql-content] }
	Preupgrade map[string]map[string][]string //{ project:{ version:[sql-content] } }
}

func GetSQLCollection

func GetSQLCollection() *SQLCollection

func NewSQLCollection

func NewSQLCollection() *SQLCollection

func (*SQLCollection) RegisterInsert

func (s *SQLCollection) RegisterInsert(project string, insertSQL string) *SQLCollection

func (*SQLCollection) RegisterInstall

func (s *SQLCollection) RegisterInstall(project, installSQL string) *SQLCollection

func (*SQLCollection) RegisterPreupgrade

func (s *SQLCollection) RegisterPreupgrade(project string, version, preupgradeSQL string) *SQLCollection

type Settings

type Settings struct {
	Email              Email  `json:"email"`
	Log                Log    `json:"log"`
	APIKey             string `json:"-"` //API密钥
	Debug              bool   `json:"debug"`
	MaxRequestBodySize string `json:"maxRequestBodySize"`

	Base echo.H `json:"base"`
	// contains filtered or unexported fields
}

func NewSettings

func NewSettings(config *Config) *Settings

func (*Settings) GetConfig

func (c *Settings) GetConfig() echo.H

func (*Settings) Init

func (c *Settings) Init(ctx echo.Context) error

func (*Settings) MaxRequestBodySizeBytes

func (c *Settings) MaxRequestBodySizeBytes() int

func (*Settings) SetBy

func (c *Settings) SetBy(r echo.H, defaults echo.H) *Settings

func (*Settings) SetConfig

func (c *Settings) SetConfig(group string, ngingConfig echo.H, defaults echo.H)

func (*Settings) SetConfigs

func (c *Settings) SetConfigs(ctx echo.Context, groups ...string) error

func (*Settings) SetDebug

func (c *Settings) SetDebug(on bool)

type Validation

type Validation struct {
	Regexp       string            `json:"regexp"`
	Translations map[string]string `json:"translations"`
}

func (*Validation) Register

func (v *Validation) Register(name string) error

type Validations

type Validations map[string]*Validation

func (Validations) Register

func (v Validations) Register() (err error)

type VersionInfo

type VersionInfo struct {
	Name      string    //软件名称
	Number    string    //版本号 1.0.1
	Package   string    //套餐
	Label     string    //版本标签 beta/alpha/stable
	DBSchema  float64   //数据库表版本 例如:1.2
	BuildTime string    //构建时间
	BuildOS   string    //构建目标系统
	BuildArch string    //构建目标架构
	CommitID  string    //GIT提交ID
	Licensed  bool      //是否已授权
	Expired   time.Time //过期时间
}

func (*VersionInfo) IsExpired

func (v *VersionInfo) IsExpired() bool

func (*VersionInfo) IsNew

func (v *VersionInfo) IsNew(number string, label string) bool

func (*VersionInfo) String

func (v *VersionInfo) String() string

func (*VersionInfo) VNumberString added in v5.0.1

func (v *VersionInfo) VNumberString() string

func (*VersionInfo) VString

func (v *VersionInfo) VString() string

Directories

Path Synopsis
subconfig
sdb

Jump to

Keyboard shortcuts

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