serv

package
v0.16.24 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2021 License: Apache-2.0 Imports: 63 Imported by: 0

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

View Source
const (
	LogLevelNone int = iota
	LogLevelInfo
	LogLevelWarn
	LogLevelError
	LogLevelDebug
)

Variables

This section is empty.

Functions

func BuildDetails

func BuildDetails() string

func Cmd

func Cmd(bi BuildInfo)

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 NewCSVSource(filename string, sep rune) (*csvSource, error)

func ReExec

func ReExec(servConf *ServConfig) func()

Exec replaces the current process with a new copy of itself.

Types

type Action

type Action struct {
	Name     string
	SQL      string
	AuthName string `mapstructure:"auth_name"`
}

Action struct contains config values for a GraphJin service action

type BuildInfo added in v0.15.84

type BuildInfo struct {
	Version string
	Commit  string
	Date    string
}

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

func ReadInConfig(configFile string) (*Config, error)

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 Core

type Core = core.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
}

type Templ

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

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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