config

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Ldate         = 1 << iota     // the date in the local time zone: 2009/01/23
	Ltime                         // the time in the local time zone: 01:23:23
	Lmicroseconds                 // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	Llongfile                     // full file name and line number: /a/b/c/d.go:23
	Lshortfile                    // final file name element and line number: d.go:23. overrides Llongfile
	LUTC                          // if Ldate or Ltime is set, use UTC rather than the local time zone
	LstdFlags     = Ldate | Ltime // initial values for the standard logger
)

These flags define which text to prefix to each log entry generated by the Logger. Bits are or'ed together to control what's printed. There is no control over the order they appear (the order listed here) or the format they present (as described in the comments). The prefix is followed by a colon only when Llongfile or Lshortfile is specified. For example, flags Ldate | Ltime (or LstdFlags) produce,

2009/01/23 01:23:23 message

while flags Ldate | Ltime | Lmicroseconds | Llongfile produce,

2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message

Variables

View Source
var (
	// Developer mode, running at debugger.
	DevMode bool
	// AppName is name of this application without extension.
	AppName = PathName(os.Args[0])
	// Executable path.
	ExePath string
	// Configuration file with path.
	CfgFile string
	// Configuration path.
	CfgPath string
	// SQLite-files path.
	SqlPath string
	// TmbPath determines images cache path.
	TmbPath string
	// PkgPath determines resources packages path.
	PkgPath string
)
View Source
var (
	ErrNoCfgFile = errors.New("configyration file was not found")
	ErrNoPkgPath = errors.New("no packages path was found")
)
View Source
var (
	// compiled binary version, sets by compiler with command
	//    go build -ldflags="-X 'github.com/schwarzlichtbezirk/hms/config.BuildVers=%buildvers%'"
	BuildVers string

	// compiled binary build date, sets by compiler with command
	//    go build -ldflags="-X 'github.com/schwarzlichtbezirk/hms/config.BuildTime=%buildtime%'"
	BuildTime string
)
View Source
var Cfg = &Config{
	CfgJWTAuth: CfgJWTAuth{
		AccessTTL:    1 * 24 * time.Hour,
		RefreshTTL:   3 * 24 * time.Hour,
		AccessKey:    "skJgM4NsbP3fs4k7vh0gfdkgGl8dJTszdLxZ1sQ9ksFnxbgvw2RsGH8xxddUV479",
		RefreshKey:   "zxK4dUnuq3Lhd1Gzhpr3usI5lAzgvy2t3fmxld2spzz7a5nfv0hsksm9cheyutie",
		NonceTimeout: 150 * time.Second,
		UaidHmacKey:  "hms-ua",
	},
	CfgWebServ: CfgWebServ{
		PortHTTP:          []string{":80"},
		PortTLS:           []string{},
		ReadTimeout:       15 * time.Second,
		ReadHeaderTimeout: 15 * time.Second,
		WriteTimeout:      15 * time.Second,
		IdleTimeout:       60 * time.Second,
		MaxHeaderBytes:    1 << 20,
		OnlineTimeout:     3 * 60 * time.Second,
		ShutdownTimeout:   15 * time.Second,
	},
	CfgTlsCert: CfgTlsCert{
		UseAutoCert:   false,
		Email:         "example@example.org",
		HostWhitelist: []string{"example.org", "www.example.org"},
	},
	Config: &jnt.Cfg,
	CfgXormDrv: CfgXormDrv{
		XormDriverName: "sqlite3",
	},
	CfgImgProp: CfgImgProp{
		ImageMaxMpx:      46.8,
		FitEmbeddedTmb:   true,
		TmbResolution:    [2]int{256, 256},
		MediaWebpQuality: 80,
		HDWebpQuality:    75,
		TileWebpQuality:  60,
		TmbWebpQuality:   75,
		ScanThreadsNum:   4,
	},
	CfgAppSets: CfgAppSets{
		WPKName:           []string{"hms-app.wpk", "hms-edge.wpk"},
		WPKmmap:           false,
		ThumbCacheMaxSize: 64,
		ImgCacheMaxSize:   256,
		RangeSearchAny:    20,
		RangeSearchLimit:  100,
	},
}

Instance of common service settings. Inits default values if config is not found.

Log is global static ring logger object.

Functions

func AbsDir

func AbsDir(dir string) (string, error)

func AddDir

func AddDir(list []string, dirs ...string) ([]string, error)

func DirExists

func DirExists(fpath string) (bool, error)

DirExists check up directory existence.

func FileExists

func FileExists(fpath string) (bool, error)

FileExists check up file existence.

func InitConfig

func InitConfig()

func LookupDir

func LookupDir(list []string, fname string) string

func LookupInLocations

func LookupInLocations(env, sub, fname string) (fpath string)

func PathName

func PathName(fpath string) string

PathName returns name of file in given file path without extension.

func StringInSlice

func StringInSlice(a string, list []string) bool

Types

type CfgAppSets

type CfgAppSets struct {
	// Name of wpk-file with program resources.
	WPKName []string `json:"wpk-name" yaml:"wpk-name,flow" mapstructure:"wpk-name"`
	// Memory mapping technology for WPK, or load into one solid byte slice otherwise.
	WPKmmap bool `json:"wpk-mmap" yaml:"wpk-mmap" mapstructure:"wpk-mmap"`
	// Maximum size in megabytes of embedded thumbnails memory cache.
	ThumbCacheMaxSize float32 `json:"thumb-cache-max-size" yaml:"thumb-cache-max-size" mapstructure:"thumb-cache-max-size"`
	// Maximum size in megabytes of memory cache for converted images.
	ImgCacheMaxSize float32 `json:"img-cache-max-size" yaml:"img-cache-max-size" mapstructure:"img-cache-max-size"`
	// Maximum number of photos to get on default map state.
	RangeSearchAny int `json:"range-search-any" yaml:"range-search-any" mapstructure:"range-search-any"`
	// Limit of range search.
	RangeSearchLimit int `json:"range-search-limit" yaml:"range-search-limit" mapstructure:"range-search-limit"`
}

CfgAppSets is settings for application-specific logic.

type CfgImgProp

type CfgImgProp struct {
	// Maximum dimension of image (width x height) in megapixels to build tiles and thumbnails.
	ImageMaxMpx float32 `json:"image-max-mpx" yaml:"image-max-mpx" mapstructure:"image-max-mpx"`
	// Stretch big image embedded into mp3-file to fit into standard icon size.
	FitEmbeddedTmb bool `json:"fit-embedded-tmb" yaml:"fit-embedded-tmb" mapstructure:"fit-embedded-tmb"`
	// Thumbnails width and height.
	TmbResolution [2]int `json:"tmb-resolution" yaml:"tmb-resolution" mapstructure:"tmb-resolution"`
	// HD images width and height.
	HDResolution [2]int `json:"hd-resolution" yaml:"hd-resolution" mapstructure:"hd-resolution"`
	// WebP quality of converted images from another format with original dimensions, ranges from 1 to 100 inclusive.
	MediaWebpQuality float32 `json:"media-webp-quality" yaml:"media-webp-quality" mapstructure:"media-webp-quality"`
	// WebP quality of converted to HD-resolution images, ranges from 1 to 100 inclusive.
	HDWebpQuality float32 `json:"hd-webp-quality" yaml:"hd-webp-quality" mapstructure:"hd-webp-quality"`
	// WebP quality of any tiles, ranges from 1 to 100 inclusive.
	TileWebpQuality float32 `json:"tile-webp-quality" yaml:"tile-webp-quality" mapstructure:"tile-webp-quality"`
	// WebP quality of thumbnails, ranges from 1 to 100 inclusive.
	TmbWebpQuality float32 `json:"tmb-webp-quality" yaml:"tmb-webp-quality" mapstructure:"tmb-webp-quality"`
	// Number of image processing threads in which performs converting to
	// tiles and thumbnails. Zero sets this number to GOMAXPROCS value.
	ScanThreadsNum int `json:"scan-threads-num" yaml:"scan-threads-num" mapstructure:"scan-threads-num"`
}

type CfgJWTAuth

type CfgJWTAuth struct {
	// Access token time to live.
	AccessTTL time.Duration `json:"access-ttl" yaml:"access-ttl" mapstructure:"access-ttl"`
	// Refresh token time to live.
	RefreshTTL time.Duration `json:"refresh-ttl" yaml:"refresh-ttl" mapstructure:"refresh-ttl"`
	// Key for access HS-256 JWT-tokens.
	AccessKey string `json:"access-key" yaml:"access-key" mapstructure:"access-key"`
	// Key for refresh HS-256 JWT-tokens.
	RefreshKey string `json:"refresh-key" yaml:"refresh-key" mapstructure:"refresh-key"`
	// Validity timeout of the nonce with which the login hash is signed.
	NonceTimeout time.Duration `json:"nonce-timeout" yaml:"nonce-timeout" mapstructure:"nonce-timeout"`
	// Key to calculate user agent ID by xxhash algorithm.
	UaidHmacKey string `json:"uaid-hmac-key" yaml:"uaid-hmac-key" mapstructure:"uaid-hmac-key"`
}

CfgJWTAuth is authentication settings.

type CfgNetwork

type CfgNetwork struct {
	// Timeout to establish connection to FTP-server.
	DialTimeout time.Duration `json:"dial-timeout" yaml:"dial-timeout" mapstructure:"dial-timeout"`
	// Expiration duration to keep opened iso-disk structures in cache from last access to it.
	DiskCacheExpire time.Duration `json:"disk-cache-expire" yaml:"disk-cache-expire" mapstructure:"disk-cache-expire"`
}

type CfgTlsCert

type CfgTlsCert struct {
	// Indicates to get TLS-certificate from letsencrypt.org service if this value is true. Uses local TLS-certificate otherwise.
	UseAutoCert bool `json:"use-auto-cert" yaml:"use-auto-cert" mapstructure:"use-auto-cert"`
	// Email optionally specifies a contact email address. This is used by CAs, such as Let's Encrypt, to notify about problems with issued certificates.
	Email string `json:"email" yaml:"email" mapstructure:"email"`
	// Creates policy where only the specified host names are allowed.
	HostWhitelist []string `json:"host-whitelist" yaml:"host-whitelist" mapstructure:"host-whitelist"`
}

type CfgWebServ

type CfgWebServ struct {
	// List of address:port values for non-encrypted connections. Address is skipped in most common cases, port only remains.
	PortHTTP []string `json:"port-http" yaml:"port-http" mapstructure:"port-http"`
	// List of address:port values for encrypted connections. Address is skipped in most common cases, port only remains.
	PortTLS []string `json:"port-tls" yaml:"port-tls" mapstructure:"port-tls"`
	// Maximum duration for reading the entire request, including the body.
	ReadTimeout time.Duration `json:"read-timeout" yaml:"read-timeout" mapstructure:"read-timeout"`
	// Amount of time allowed to read request headers.
	ReadHeaderTimeout time.Duration `json:"read-header-timeout" yaml:"read-header-timeout" mapstructure:"read-header-timeout"`
	// Maximum duration before timing out writes of the response.
	WriteTimeout time.Duration `json:"write-timeout" yaml:"write-timeout" mapstructure:"write-timeout"`
	// Maximum amount of time to wait for the next request when keep-alives are enabled.
	IdleTimeout time.Duration `json:"idle-timeout" yaml:"idle-timeout" mapstructure:"idle-timeout"`
	// Controls the maximum number of bytes the server will read parsing the request header's keys and values, including the request line, in bytes.
	MaxHeaderBytes int `json:"max-header-bytes" yaml:"max-header-bytes" mapstructure:"max-header-bytes"`
	// Maximum duration between two ajax-calls to think client is online.
	OnlineTimeout time.Duration `json:"online-timeout" yaml:"online-timeout" mapstructure:"online-timeout"`
	// Maximum duration to wait for graceful shutdown.
	ShutdownTimeout time.Duration `json:"shutdown-timeout" yaml:"shutdown-timeout" mapstructure:"shutdown-timeout"`
}

CfgWebServ is web server settings.

type CfgXormDrv

type CfgXormDrv struct {
	// Provides XORM driver name.
	XormDriverName string `json:"xorm-driver-name" yaml:"xorm-driver-name" mapstructure:"xorm-driver-name"`
}

type Config

type Config struct {
	CfgJWTAuth  `json:"authentication" yaml:"authentication" mapstructure:"authentication"`
	CfgWebServ  `json:"web-server" yaml:"web-server" mapstructure:"web-server"`
	CfgTlsCert  `json:"tls-certificates" yaml:"tls-certificates" mapstructure:"tls-certificates"`
	*jnt.Config `json:"network" yaml:"network" mapstructure:"network"`
	CfgXormDrv  `json:"xorm" yaml:"xorm" mapstructure:"xorm"`
	CfgImgProp  `json:"images-prop" yaml:"images-prop" mapstructure:"images-prop"`
	CfgAppSets  `json:"specification" yaml:"specification" mapstructure:"specification"`
}

Config is common service settings.

type LL

type LL int // log level
const (
	LLdebug LL = iota
	LLinfo
	LLwarn
	LLerror
	LLfatal
	LLpanic
)

type LogStore

type LogStore struct {
	ID    uint      `xorm:"pk autoincr" json:"id" yaml:"id" xml:"id,attr"`
	Time  time.Time `json:"time" yaml:"time" xml:"time,attr"`
	Level LL        `json:"level" yaml:"level" xml:"level,attr"`
	Msg   string    `json:"msg" yaml:"msg" xml:"msg"`
	Line  int       `json:"line,omitempty" yaml:"line,omitempty" xml:"line,omitempty"`
	File  string    `json:"file,omitempty" yaml:"file,omitempty" xml:"file,omitempty"`
}

LogStore represents structured log fields for each log entry. It's used to transmit the log items by network.

type Logger

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

A Logger represents an active logging object that generates lines of output to an io.Writer. Each logging operation makes a single call to the Writer's Write method. A Logger can be used simultaneously from multiple goroutines; it guarantees to serialize access to the Writer.

func NewLogger

func NewLogger(out io.Writer, flag int, lim int) *Logger

NewLogger creates a new Logger. The out variable sets the destination to which log data will be written. The flag argument defines the logging properties.

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

Debug is equivalent to l.Info().

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

Debugf is equivalent to l.Infof().

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

Error is equivalent to l.Info().

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

Errorf is equivalent to l.Infof().

func (*Logger) Fatal

func (l *Logger) Fatal(v ...interface{})

Fatal is equivalent to l.Info() followed by a call to os.Exit(1).

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

Fatalf is equivalent to l.Infof() followed by a call to os.Exit(1).

func (*Logger) Flags

func (l *Logger) Flags() int

Flags returns the output flags for the logger.

func (*Logger) Info

func (l *Logger) Info(v ...interface{})

Info calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Print.

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...interface{})

Infof calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Level

func (l *Logger) Level() LL

Level returns output level of the logger.

func (*Logger) Log

func (l *Logger) Log(level LL, v ...interface{})

Log calls l.Output to print to the logger with specified level. Arguments are handled in the manner of fmt.Print.

func (*Logger) Logf

func (l *Logger) Logf(level LL, format string, v ...interface{})

Logf calls l.Output to print to the logger with specified level. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Output

func (l *Logger) Output(calldepth int, lev LL, s string) error

Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. Calldepth is used to recover the PC and is provided for generality, although at the moment on all pre-defined paths it will be 2.

func (*Logger) Panic

func (l *Logger) Panic(v ...interface{})

Panic is equivalent to l.Info() followed by a call to panic().

func (*Logger) Panicf

func (l *Logger) Panicf(format string, v ...interface{})

Panicf is equivalent to l.Infof() followed by a call to panic().

func (*Logger) Ring

func (l *Logger) Ring() *ring.Ring

Ring returns last element of ring of log items. Ring must be viewed only in backward order.

func (*Logger) SetFlags

func (l *Logger) SetFlags(flag int)

SetFlags sets the output flags for the logger.

func (*Logger) SetLevel

func (l *Logger) SetLevel(lev LL)

SetLevel sets output level of the logger to given value.

func (*Logger) SetOutput

func (l *Logger) SetOutput(w io.Writer)

SetOutput sets the output destination for the logger.

func (*Logger) Size

func (l *Logger) Size() int

Size returns current size of ring of log items. Ring must be viewed only in backward order.

func (*Logger) Warn

func (l *Logger) Warn(v ...interface{})

Warn is equivalent to l.Info().

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...interface{})

Warnf is equivalent to l.Infof().

func (*Logger) Writer

func (l *Logger) Writer() io.Writer

Writer returns the output destination for the logger.

type XormLoggerBridge

type XormLoggerBridge struct {
	*Logger
	// contains filtered or unexported fields
}

func (*XormLoggerBridge) IsShowSQL

func (l *XormLoggerBridge) IsShowSQL() bool

IsShowSQL implement xorm.ILogger.

func (*XormLoggerBridge) Level

func (l *XormLoggerBridge) Level() xlog.LogLevel

Level implement xorm.ILogger.

func (*XormLoggerBridge) SetLevel

func (l *XormLoggerBridge) SetLevel(lev xlog.LogLevel)

SetLevel implement xorm.ILogger.

func (*XormLoggerBridge) ShowSQL

func (l *XormLoggerBridge) ShowSQL(show ...bool)

ShowSQL implement xorm.ILogger.

Jump to

Keyboard shortcuts

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