config

package
v2.2.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2020 License: AGPL-3.0 Imports: 51 Imported by: 0

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/>.

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

This section is empty.

Variables

View Source
var (
	EmptyBytes                 = []byte{}
	ErrNoAvailibaleConfigFound = errors.New(`No available configurations found`)
)
View Source
var (
	Daemon            = goforever.Default
	DaemonDefaultHook = DaemonCommonHook
)
View Source
var (
	Installed sql.NullBool

	DefaultConfig         *Config
	DefaultCLIConfig      = NewCLIConfig()
	OAuthUserSessionKey   = `oauthUser`
	ErrUnknowDatabaseType = errors.New(`unkown database type`)
	Emitter               = emitter.DefaultCondEmitter
)
View Source
var (
	SessionOptions *echo.SessionOptions
	CookieOptions  *cookie.CookieOptions
	SessionEngine  = `file`
	SessionName    = `SID`
)
View Source
var (
	DBConnecters = map[string]func(*Config) error{
		`mysql`: ConnectMySQL,
		`mongo`: ConnectMongoDB,
	}
	DBInstallers = map[string]func(string) error{
		`mysql`: ExecMySQL,
	}
	DBCreaters = map[string]func(error, *Config) error{
		`mysql`: CreaterMySQL,
	}
	DBEngines = echo.NewKVData().Add(`mysql`, `MySQL`)
)
View Source
var CmdIsRunning = com.CmdIsRunning
View Source
var ErrCmdNotRunning = errors.New(`command is not running`)
View Source
var Navigations = []*Navigation{}
View Source
var Version = &VersionInfo{Name: `Nging`}

Functions

func AddDaemon

func AddDaemon(p *dbschema.NgingForeverProcess, run ...bool) *goforever.Process

func ConnectDB

func ConnectDB(c *Config) error

func ConnectMongoDB added in v1.1.0

func ConnectMongoDB(c *Config) error

func ConnectMySQL added in v1.1.0

func ConnectMySQL(c *Config) error

func CreaterMySQL added in v1.1.0

func CreaterMySQL(err error, c *Config) error

func DaemonCommonHook

func DaemonCommonHook(p *goforever.Process)

func ExecMySQL added in v1.1.0

func ExecMySQL(sqlStr string) error

func FireInitSettings

func FireInitSettings(cfg echo.H) error

func FireSetSettings

func FireSetSettings(group string, globalCfg echo.H) error

func GetPreupgradeSQLFiles

func GetPreupgradeSQLFiles() []string

func GetSQLInsertFiles

func GetSQLInsertFiles() []string

func GetSQLInstallFiles

func GetSQLInstallFiles() ([]string, error)

func InitSessionOptions

func InitSessionOptions(c *Config)

func IsInstalled

func IsInstalled() bool

func MustOK

func MustOK(err error)

func OnExitedDaemon

func OnExitedDaemon(processM *dbschema.NgingForeverProcess)

OnExitedDaemon 当值守程序达到最大重试次数退出时

func OnInitSettings

func OnInitSettings(fn func(echo.H) error)

func OnSetSettings

func OnSetSettings(fn func(string, echo.H) error)

func ParseArgsSlice

func ParseArgsSlice(a string) []string

func ParseConfig

func ParseConfig() error

func ParseEnvSlice

func ParseEnvSlice(a string) []string

func ParseTimeDuration

func ParseTimeDuration(timeout string) time.Duration

func QueryTo

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

func RestartDaemon

func RestartDaemon()

RestartDaemon 重启所有已登记的进程

func RunDaemon

func RunDaemon()

RunDaemon 运行值守程序

func SetInstalled

func SetInstalled(lockFile string) error

func Setting

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

func Table

func Table(table string) string

func ToTable

func ToTable(m sqlbuilder.Name_) string

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
	Confx          string
	Type           string //启动类型: webserver/ftpserver/manager
	Startup        string //manager启动时同时启动的服务,可选的有webserver/ftpserver,如有多个需用半角逗号“,”隔开
	// contains filtered or unexported fields
}

func NewCLIConfig

func NewCLIConfig() *CLIConfig

func (*CLIConfig) CaddyReload

func (c *CLIConfig) CaddyReload() error

func (*CLIConfig) CaddyRestart

func (c *CLIConfig) CaddyRestart(writer ...io.Writer) error

func (*CLIConfig) CaddyStart

func (c *CLIConfig) CaddyStart(writer ...io.Writer) (err error)

func (*CLIConfig) CaddyStop

func (c *CLIConfig) CaddyStop() error

func (*CLIConfig) CaddyStopHistory

func (c *CLIConfig) CaddyStopHistory() (err 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) CmdStop

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

func (*CLIConfig) FRPClientRestart

func (c *CLIConfig) FRPClientRestart(writer ...io.Writer) error

func (*CLIConfig) FRPClientRestartID

func (c *CLIConfig) FRPClientRestartID(id string, writer ...io.Writer) error

func (*CLIConfig) FRPClientStart

func (c *CLIConfig) FRPClientStart(writer ...io.Writer) (err error)

func (*CLIConfig) FRPClientStartID

func (c *CLIConfig) FRPClientStartID(id uint, writer ...io.Writer) (err error)

func (*CLIConfig) FRPClientStop

func (c *CLIConfig) FRPClientStop() error

func (*CLIConfig) FRPClientStopHistory

func (c *CLIConfig) FRPClientStopHistory(ids ...string) (err error)

func (*CLIConfig) FRPConfigFile

func (c *CLIConfig) FRPConfigFile(id uint, isServer bool) string

func (*CLIConfig) FRPPidFile

func (c *CLIConfig) FRPPidFile(id string, isServer bool) string

func (*CLIConfig) FRPRebuildConfigFile

func (c *CLIConfig) FRPRebuildConfigFile(data interface{}, configFiles ...string) error

func (*CLIConfig) FRPRestart

func (c *CLIConfig) FRPRestart(writer ...io.Writer) error

func (*CLIConfig) FRPRestartID

func (c *CLIConfig) FRPRestartID(id string, writer ...io.Writer) error

func (*CLIConfig) FRPSaveConfigFile

func (c *CLIConfig) FRPSaveConfigFile(data interface{}) (err error)

func (*CLIConfig) FRPStart

func (c *CLIConfig) FRPStart(writer ...io.Writer) (err error)

func (*CLIConfig) FRPStartID

func (c *CLIConfig) FRPStartID(id uint, writer ...io.Writer) (err error)

func (*CLIConfig) FRPStop

func (c *CLIConfig) FRPStop() error

func (*CLIConfig) FRPStopHistory

func (c *CLIConfig) FRPStopHistory(ids ...string) (err error)

func (*CLIConfig) FTPRestart

func (c *CLIConfig) FTPRestart(writer ...io.Writer) error

func (*CLIConfig) FTPStart

func (c *CLIConfig) FTPStart(writer ...io.Writer) (err error)

func (*CLIConfig) FTPStop

func (c *CLIConfig) FTPStop() error

func (*CLIConfig) FTPStopHistory

func (c *CLIConfig) FTPStopHistory() (err error)

func (*CLIConfig) GenerateIDFromConfigFileName

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

func (*CLIConfig) InitFlag

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

func (*CLIConfig) IsRunning

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

func (*CLIConfig) Kill

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

func (*CLIConfig) MustFRPRebuildConfigFile

func (c *CLIConfig) MustFRPRebuildConfigFile(data interface{}, configFiles ...string) error

func (*CLIConfig) OnlyRunServer

func (c *CLIConfig) OnlyRunServer() bool

func (*CLIConfig) ParseConfig

func (c *CLIConfig) ParseConfig()

func (*CLIConfig) Reload

func (c *CLIConfig) Reload(cts ...string) error

func (*CLIConfig) RunStartup

func (c *CLIConfig) RunStartup()

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

func (*CLIConfig) SetLogWriter

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

type Config

type Config struct {
	DB DB `json:"db"`

	Sys System `json:"sys"`

	Cron struct {
		PoolSize int    `json:"poolSize"`
		Template string `json:"template"` //发信模板
	} `json:"cron"`

	Cookie struct {
		Domain   string `json:"domain"`
		MaxAge   int    `json:"maxAge"`
		Path     string `json:"path"`
		HttpOnly bool   `json:"httpOnly"`
		HashKey  string `json:"hashKey"`
		BlockKey string `json:"blockKey"`
	} `json:"cookie"`

	Caddy    caddy.Config    `json:"caddy"`
	FTP      ftp.Config      `json:"ftp"`
	Language language.Config `json:"language"`
	Download struct {
		SavePath string `json:"savePath"`
	} `json:"download"`

	*Settings `json:"-"`
	// contains filtered or unexported fields
}

func InitConfig added in v1.2.0

func InitConfig() (*Config, error)

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() codec.Codec

func (*Config) ConfigFromDB

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

func (*Config) ConnectedDB

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

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

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) InitSecretKey

func (c *Config) InitSecretKey() *Config

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

type DB

type DB struct {
	Type            string            `json:"type"`
	User            string            `json:"user"`
	Password        string            `json:"password"`
	Host            string            `json:"host"`
	Database        string            `json:"database"`
	Prefix          string            `json:"prefix"`
	Options         map[string]string `json:"options"`
	Debug           bool              `json:"debug"`
	ConnMaxLifetime string            `json:"connMaxLifetime"` //example: 10s
	MaxIdleConns    int               `json:"maxIdleConns"`
	MaxOpenConns    int               `json:"maxOpenConns"`
	// contains filtered or unexported fields
}

func (*DB) ConnMaxDuration

func (d *DB) ConnMaxDuration() time.Duration

func (*DB) SetConn

func (d *DB) SetConn(setter DBConnSetter) error

func (*DB) SetDebug

func (d *DB) SetDebug(on bool)

func (*DB) Table

func (d *DB) Table(table string) string

func (*DB) ToTable

func (d *DB) ToTable(m sqlbuilder.Name_) string

type DBConnSetter

type DBConnSetter interface {
	SetConnMaxLifetime(time.Duration)
	SetMaxIdleConns(int)
	SetMaxOpenConns(int)
}

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:","`
}

func (*Log) Init

func (c *Log) Init()

func (*Log) LogFile

func (c *Log) LogFile() string

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 Settings

type Settings struct {
	Email  Email  `json:"email"`
	Log    Log    `json:"log"`
	APIKey string `json:"-"` //API密钥
	Debug  bool   `json:"debug"`
	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()

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(groups ...string)

func (*Settings) SetDebug

func (c *Settings) SetDebug(on bool)

type System

type System struct {
	VhostsfileDir          string            `json:"vhostsfileDir"`
	AllowIP                []string          `json:"allowIP"`
	SSLAuto                bool              `json:"sslAuto"`
	SSLEmail               string            `json:"sslEmail"`
	SSLHosts               []string          `json:"sslHosts"`
	SSLCacheDir            string            `json:"sslCacheDir"`
	SSLKeyFile             string            `json:"sslKeyFile"`
	SSLCertFile            string            `json:"sslCertFile"`
	EditableFileExtensions map[string]string `json:"editableFileExtensions"`
	EditableFileMaxSize    string            `json:"editableFileMaxSize"`
	EditableFileMaxBytes   int64             `json:"editableFileMaxBytes"`
	PlayableFileExtensions map[string]string `json:"playableFileExtensions"`
	ErrorPages             map[int]string    `json:"errorPages"`
	CmdTimeout             string            `json:"cmdTimeout"`
	CmdTimeoutDuration     time.Duration     `json:"-"`
	ShowExpirationTime     int64             `json:"showExpirationTime"` //显示过期时间:0为始终显示;大于0为距离剩余到期时间多少秒的时候显示;小于0为不显示
	SessionName            string            `json:"sessionName"`
}

func (*System) Editable

func (sys *System) Editable(fileName string) (string, bool)

func (*System) Playable

func (sys *System) Playable(fileName string) (string, bool)

type VersionInfo

type VersionInfo struct {
	Name      string    //软件名称
	Number    string    //版本号 1.0.1
	Label     string    //版本标签 beta/alpha/stable
	DBSchema  float64   //数据库表版本 例如:1.2
	BuildTime 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) VString

func (v *VersionInfo) VString() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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