Documentation ¶
Overview ¶
Package reload offers lightweight automatic reloading of running processes.
After initialisation with reload.Do() any changes to the binary will restart the process.
Example:
go func() { err := reload.Do(log.Printf) if err != nil { panic(err) } }()
A list of additional directories to watch can be added:
go func() { err := reload.Do(log.Printf, reload.Dir("tpl", reloadTpl) if err != nil { panic(err) } }()
Note that this package won't prevent race conditions (e.g. when assigning to a global templates variable). You'll need to use sync.RWMutex yourself.
Index ¶
- Constants
- func BuildDetails() string
- func Cmd(bi BuildInfo)
- func Dir(path string, cb func()) dir
- func Do(servConf *ServConfig, log func(string, ...interface{}), additional ...dir) error
- func GetConfigName() string
- func NewCSVSource(filename string, sep rune) (*csvSource, error)
- func ReExec(servConf *ServConfig) func()
- type Action
- type BuildInfo
- type Config
- type Core
- type ErrorLineExtract
- type Serv
- type ServConfig
- type Templ
Constants ¶
const ( LogLevelNone int = iota LogLevelInfo LogLevelWarn LogLevelError LogLevelDebug )
Variables ¶
This section is empty.
Functions ¶
func BuildDetails ¶
func BuildDetails() string
func Dir ¶
func Dir(path string, cb func()) dir
Dir is an additional directory to watch for changes. Directories are watched non-recursively.
The second argument is the callback that to run when the directory changes. Use reload.ReExec(servConf) to restart the process.
func Do ¶
func Do(servConf *ServConfig, log func(string, ...interface{}), additional ...dir) error
Do reload the current process when its binary changes.
The log function is used to display an informational startup message and errors. It works well with e.g. the standard log package or Logrus.
The error return will only return initialisation errors. Once initialized it will use the log function to print errors, rather than return.
func GetConfigName ¶
func GetConfigName() string
func NewCSVSource ¶
func ReExec ¶
func ReExec(servConf *ServConfig) func()
Exec replaces the current process with a new copy of itself.
Types ¶
type Config ¶
type Config struct { Core `mapstructure:",squash"` Serv `mapstructure:",squash"` // contains filtered or unexported fields }
Config struct holds the GraphJin config values
func ReadInConfig ¶
ReadInConfig function reads in the config file for the environment specified in the GO_ENV environment variable. This is the best way to create a new GraphJin config.
type ErrorLineExtract ¶
type ErrorLineExtract struct { LineNum int // Line number starting with 1 ColumnNum int // Column number starting with 1 Text string // Text of the line without a new line character. }
func ExtractErrorLine ¶
func ExtractErrorLine(source string, position int) (ErrorLineExtract, error)
ExtractErrorLine takes source and character position extracts the line number, column number, and the line of text.
The first character is position 1.
type Serv ¶
type Serv struct { AppName string `mapstructure:"app_name"` Production bool LogLevel string `mapstructure:"log_level"` LogFormat string `mapstructure:"log_format"` HostPort string `mapstructure:"host_port"` Host string Port string HTTPGZip bool `mapstructure:"http_compress"` WebUI bool `mapstructure:"web_ui"` EnableTracing bool `mapstructure:"enable_tracing"` WatchAndReload bool `mapstructure:"reload_on_config_change"` AuthFailBlock bool `mapstructure:"auth_fail_block"` SeedFile string `mapstructure:"seed_file"` MigrationsPath string `mapstructure:"migrations_path"` AllowedOrigins []string `mapstructure:"cors_allowed_origins"` AllowedHeaders []string `mapstructure:"cors_allowed_headers"` DebugCORS bool `mapstructure:"cors_debug"` APIPath string `mapstructure:"api_path"` CacheControl string `mapstructure:"cache_control"` // Telemetry struct contains OpenCensus metrics and tracing related config Telemetry struct { Debug bool Interval *time.Duration Metrics struct { Exporter string Endpoint string Namespace string Key string } Tracing struct { Exporter string Endpoint string Sample string IncludeQuery bool `mapstructure:"include_query"` IncludeParams bool `mapstructure:"include_params"` } } Auth auth.Auth Auths []auth.Auth // DB struct contains db config DB struct { Type string Host string Port uint16 DBName string User string Password string Schema string PoolSize int32 `mapstructure:"pool_size"` MaxRetries int `mapstructure:"max_retries"` PingTimeout time.Duration `mapstructure:"ping_timeout"` EnableTLS bool `mapstructure:"enable_tls"` ServerName string `mapstructure:"server_name"` ServerCert string `mapstructure:"server_cert"` ClientCert string `mapstructure:"client_cert"` ClientKey string `mapstructure:"client_key"` } `mapstructure:"database"` Actions []Action RateLimiter struct { Rate float64 Bucket int IPHeader string `mapstructure:"ip_header"` } `mapstructure:"rate_limiter"` }
Serv struct contains config values used by the GraphJin service
type ServConfig ¶
type ServConfig struct {
// contains filtered or unexported fields
}