config

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultServerConfig = ServerConfig{
		Host:      "0.0.0.0",
		Port:      8080,
		DebugMode: false,
	}
	DefaultDatabaseConfig = DatabaseConfig{
		Type:      "",
		Parameter: "",
	}
	DefaultRedisConfig = RedisConfig{
		URI:                  "localhost:6379",
		MaxIdleConnections:   10,
		MaxActiveConnections: 500,
		MaxIdleTimeout:       10,
		Password:             "",
		Db:                   0,
		ConnectionTimeout:    3,
		ReadTimeout:          3,
		WriteTimeout:         3,
	}
	DefaultSessionConfig = SessionConfig{
		Name:     "session_id",
		MaxAge:   7200,
		Path:     "",
		Domain:   "",
		Secure:   false,
		HttpOnly: false,
	}
	DefaultResourceConfig = ResourceConfig{
		BaseDir: os.Getenv("FLAGFIELD_HOME") + "uploads/",
	}
	DefaultConfig = Config{DefaultServerConfig, DefaultDatabaseConfig, DefaultRedisConfig, DefaultSessionConfig, DefaultResourceConfig}
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Server   ServerConfig   `json:"server"`
	Database DatabaseConfig `json:"database"`
	Redis    RedisConfig    `json:"redis"`
	Session  SessionConfig  `json:"session"`
	Resource ResourceConfig `json:"resource"`
}

func FromFile

func FromFile(path string) *Config

func (*Config) ToFile

func (c *Config) ToFile(path string) error

type DatabaseConfig

type DatabaseConfig struct {
	Type      string `json:"type" validate:"eq=mysql|eq=postgres|eq=sqlite3|eq=mssql,required"`
	Parameter string `json:"parameter" validate:"required"`
}

type MailConfig

type MailConfig struct {
	Host       string `json:"host"`
	Port       uint   `json:"port"`
	SenderName string `json:"sender_name"`
	Address    string `json:"address"`
	Username   string `json:"username"`
	Password   string `json:"password"`
	UseTLS     bool   `json:"use_tls"`
}

type RedisConfig

type RedisConfig struct {
	URI                  string `json:"uri" validate:"uri"`
	MaxIdleConnections   int    `json:"max_idle_connections"`
	MaxActiveConnections int    `json:"max_active_connections"`
	MaxIdleTimeout       int    `json:"max_idle_timeout"`
	Password             string `json:"password"`
	Db                   int    `json:"db"`
	ConnectionTimeout    int    `json:"connection_timeout"`
	ReadTimeout          int    `json:"read_timeout"`
	WriteTimeout         int    `json:"write_timeout"`
}

type ResourceConfig

type ResourceConfig struct {
	BaseDir string `json:"base_dir" validate:"required"`
}

type ServerConfig

type ServerConfig struct {
	Host      string `json:"host" validate:"ip"`
	Port      uint16 `json:"port"`
	DebugMode bool   `json:"debug_mode"`
}

type SessionConfig

type SessionConfig struct {
	Name     string `json:"name" validate:"required"`
	MaxAge   int    `json:"max_age"`
	Path     string `json:"path"`
	Domain   string `json:"domain"`
	Secure   bool   `json:"secure"`
	HttpOnly bool   `json:"http_only"`
}

Jump to

Keyboard shortcuts

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