mirror of
https://github.com/nabbar/golib.git
synced 2025-09-26 20:01:15 +08:00
Package HTTPServer
- replace time.duration / os.FileMode type by golib package duration & file perms to allow parsing string in json Package Logger - replace time.duration / os.FileMode type by golib package duration & file perms to allow parsing string in json - fix json bug in default options Package Monitor - replace time.duration / os.FileMode type by golib package duration & file perms to allow parsing string in json
This commit is contained in:
@@ -32,11 +32,11 @@ import (
|
||||
"net"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
libval "github.com/go-playground/validator/v10"
|
||||
libtls "github.com/nabbar/golib/certificates"
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
libdur "github.com/nabbar/golib/duration"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
srvtps "github.com/nabbar/golib/httpserver/types"
|
||||
liblog "github.com/nabbar/golib/logger"
|
||||
@@ -109,7 +109,7 @@ type Config struct {
|
||||
// decisions on each request body's acceptable deadline or
|
||||
// upload rate, most users will prefer to use
|
||||
// ReadHeaderTimeout. It is valid to use them both.
|
||||
ReadTimeout time.Duration `mapstructure:"read_timeout" json:"read_timeout" yaml:"read_timeout" toml:"read_timeout"`
|
||||
ReadTimeout libdur.Duration `mapstructure:"read_timeout" json:"read_timeout" yaml:"read_timeout" toml:"read_timeout"`
|
||||
|
||||
// ReadHeaderTimeout is the amount of time allowed to read
|
||||
// request headers. The connection's read deadline is reset
|
||||
@@ -117,13 +117,13 @@ type Config struct {
|
||||
// is considered too slow for the body. If ReadHeaderTimeout
|
||||
// is zero, the value of ReadTimeout is used. If both are
|
||||
// zero, there is no timeout.
|
||||
ReadHeaderTimeout time.Duration `mapstructure:"read_header_timeout" json:"read_header_timeout" yaml:"read_header_timeout" toml:"read_header_timeout"`
|
||||
ReadHeaderTimeout libdur.Duration `mapstructure:"read_header_timeout" json:"read_header_timeout" yaml:"read_header_timeout" toml:"read_header_timeout"`
|
||||
|
||||
// WriteTimeout is the maximum duration before timing out
|
||||
// writes of the response. It is reset whenever a new
|
||||
// request's header is read. Like ReadTimeout, it does not
|
||||
// let Handlers make decisions on a per-request basis.
|
||||
WriteTimeout time.Duration `mapstructure:"write_timeout" json:"write_timeout" yaml:"write_timeout" toml:"write_timeout"`
|
||||
WriteTimeout libdur.Duration `mapstructure:"write_timeout" json:"write_timeout" yaml:"write_timeout" toml:"write_timeout"`
|
||||
|
||||
// MaxHeaderBytes controls the maximum number of bytes the
|
||||
// srv will read parsing the request header's keys and
|
||||
@@ -160,7 +160,7 @@ type Config struct {
|
||||
// IdleTimeout specifies how long until idle clients should be
|
||||
// closed with a GOAWAY frame. PING frames are not considered
|
||||
// activity for the purposes of IdleTimeout.
|
||||
IdleTimeout time.Duration `mapstructure:"idle_timeout" json:"idle_timeout" yaml:"idle_timeout" toml:"idle_timeout"`
|
||||
IdleTimeout libdur.Duration `mapstructure:"idle_timeout" json:"idle_timeout" yaml:"idle_timeout" toml:"idle_timeout"`
|
||||
|
||||
// MaxUploadBufferPerConnection is the size of the initial flow
|
||||
// control window for each connections. The HTTP/2 spec does not
|
||||
@@ -375,15 +375,15 @@ func (o *srv) GetConfig() *Config {
|
||||
|
||||
func (o *srv) makeOptServer(cfg Config) *optServer {
|
||||
return &optServer{
|
||||
ReadTimeout: cfg.ReadTimeout,
|
||||
ReadHeaderTimeout: cfg.ReadHeaderTimeout,
|
||||
WriteTimeout: cfg.WriteTimeout,
|
||||
ReadTimeout: cfg.ReadTimeout.Time(),
|
||||
ReadHeaderTimeout: cfg.ReadHeaderTimeout.Time(),
|
||||
WriteTimeout: cfg.WriteTimeout.Time(),
|
||||
MaxHeaderBytes: cfg.MaxHeaderBytes,
|
||||
MaxHandlers: cfg.MaxHandlers,
|
||||
MaxConcurrentStreams: cfg.MaxConcurrentStreams,
|
||||
MaxReadFrameSize: cfg.MaxReadFrameSize,
|
||||
PermitProhibitedCipherSuites: cfg.PermitProhibitedCipherSuites,
|
||||
IdleTimeout: cfg.IdleTimeout,
|
||||
IdleTimeout: cfg.IdleTimeout.Time(),
|
||||
MaxUploadBufferPerConnection: cfg.MaxUploadBufferPerConnection,
|
||||
MaxUploadBufferPerStream: cfg.MaxUploadBufferPerStream,
|
||||
DisableKeepAlive: cfg.DisableKeepAlive,
|
||||
|
@@ -43,7 +43,7 @@ var _defaultConfig = []byte(`
|
||||
"disableStack":false,
|
||||
"disableTimestamp":false,
|
||||
"enableTrace":true,
|
||||
"disableColor":false,
|
||||
"disableColor":false
|
||||
},
|
||||
"logFile":[
|
||||
{
|
||||
|
@@ -28,8 +28,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
libprm "github.com/nabbar/golib/file/perm"
|
||||
libsiz "github.com/nabbar/golib/size"
|
||||
)
|
||||
|
||||
@@ -47,10 +46,10 @@ type OptionsFile struct {
|
||||
CreatePath bool `json:"createPath,omitempty" yaml:"createPath,omitempty" toml:"createPath,omitempty" mapstructure:"createPath,omitempty"`
|
||||
|
||||
// FileMode define mode to be used for the log file if the create it.
|
||||
FileMode os.FileMode `json:"fileMode,omitempty" yaml:"fileMode,omitempty" toml:"fileMode,omitempty" mapstructure:"fileMode,omitempty"`
|
||||
FileMode libprm.Perm `json:"fileMode,omitempty" yaml:"fileMode,omitempty" toml:"fileMode,omitempty" mapstructure:"fileMode,omitempty"`
|
||||
|
||||
// PathMode define mode to be used for the path of the log file if create it.
|
||||
PathMode os.FileMode `json:"pathMode,omitempty" yaml:"pathMode,omitempty" toml:"pathMode,omitempty" mapstructure:"pathMode,omitempty"`
|
||||
PathMode libprm.Perm `json:"pathMode,omitempty" yaml:"pathMode,omitempty" toml:"pathMode,omitempty" mapstructure:"pathMode,omitempty"`
|
||||
|
||||
// DisableStack allow to disable the goroutine id before each message.
|
||||
DisableStack bool `json:"disableStack,omitempty" yaml:"disableStack,omitempty" toml:"disableStack,omitempty" mapstructure:"disableStack,omitempty"`
|
||||
|
@@ -90,8 +90,8 @@ func New(opt logcfg.OptionsFile, format logrus.Formatter) (HookFile, error) {
|
||||
enableAccessLog: opt.EnableAccessLog,
|
||||
createPath: opt.CreatePath,
|
||||
filepath: opt.Filepath,
|
||||
fileMode: opt.FileMode,
|
||||
pathMode: opt.PathMode,
|
||||
fileMode: opt.FileMode.FileMode(),
|
||||
pathMode: opt.PathMode.FileMode(),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -102,13 +102,13 @@ func New(opt logcfg.OptionsFile, format logrus.Formatter) (HookFile, error) {
|
||||
}
|
||||
|
||||
if opt.CreatePath {
|
||||
if e := libiot.PathCheckCreate(true, opt.Filepath, opt.FileMode, opt.PathMode); e != nil {
|
||||
if e := libiot.PathCheckCreate(true, opt.Filepath, opt.FileMode.FileMode(), opt.PathMode.FileMode()); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
}
|
||||
|
||||
// #nosec
|
||||
h, e := os.OpenFile(opt.Filepath, flags, opt.FileMode)
|
||||
h, e := os.OpenFile(opt.Filepath, flags, opt.FileMode.FileMode())
|
||||
|
||||
if e != nil {
|
||||
return nil, e
|
||||
|
@@ -30,6 +30,7 @@ import (
|
||||
"time"
|
||||
|
||||
libctx "github.com/nabbar/golib/context"
|
||||
libdur "github.com/nabbar/golib/duration"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
liblog "github.com/nabbar/golib/logger"
|
||||
logcfg "github.com/nabbar/golib/logger/config"
|
||||
@@ -116,10 +117,10 @@ func (o *mon) SetConfig(ctx libctx.FuncContext, cfg montps.Config) liberr.Error
|
||||
}
|
||||
|
||||
cnf := &runCfg{
|
||||
checkTimeout: cfg.CheckTimeout,
|
||||
intervalCheck: cfg.IntervalCheck,
|
||||
intervalFall: cfg.IntervalFall,
|
||||
intervalRise: cfg.IntervalRise,
|
||||
checkTimeout: cfg.CheckTimeout.Time(),
|
||||
intervalCheck: cfg.IntervalCheck.Time(),
|
||||
intervalFall: cfg.IntervalFall.Time(),
|
||||
intervalRise: cfg.IntervalRise.Time(),
|
||||
fallCountKO: cfg.FallCountKO,
|
||||
fallCountWarn: cfg.FallCountWarn,
|
||||
riseCountKO: cfg.RiseCountKO,
|
||||
@@ -192,10 +193,10 @@ func (o *mon) GetConfig() montps.Config {
|
||||
|
||||
return montps.Config{
|
||||
Name: o.getName(),
|
||||
CheckTimeout: cfg.checkTimeout,
|
||||
IntervalCheck: cfg.intervalCheck,
|
||||
IntervalFall: cfg.intervalFall,
|
||||
IntervalRise: cfg.intervalRise,
|
||||
CheckTimeout: libdur.ParseDuration(cfg.checkTimeout),
|
||||
IntervalCheck: libdur.ParseDuration(cfg.intervalCheck),
|
||||
IntervalFall: libdur.ParseDuration(cfg.intervalFall),
|
||||
IntervalRise: libdur.ParseDuration(cfg.intervalRise),
|
||||
FallCountKO: cfg.fallCountKO,
|
||||
FallCountWarn: cfg.fallCountWarn,
|
||||
RiseCountKO: cfg.riseCountKO,
|
||||
|
@@ -30,10 +30,10 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
libval "github.com/go-playground/validator/v10"
|
||||
cfgtps "github.com/nabbar/golib/config/const"
|
||||
libdur "github.com/nabbar/golib/duration"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
logcfg "github.com/nabbar/golib/logger/config"
|
||||
)
|
||||
@@ -69,16 +69,16 @@ type Config struct {
|
||||
Name string `json:"name" yaml:"name" toml:"name" mapstructure:"name"`
|
||||
|
||||
// CheckTimeout define the timeout use for healthcheck. Default is 5 second.
|
||||
CheckTimeout time.Duration `json:"check-timeout" yaml:"check-timeout" toml:"check-timeout" mapstructure:"check-timeout"`
|
||||
CheckTimeout libdur.Duration `json:"check-timeout" yaml:"check-timeout" toml:"check-timeout" mapstructure:"check-timeout"`
|
||||
|
||||
// IntervalCheck define the time waiting between 2 healthcheck. Default is 5 second.
|
||||
IntervalCheck time.Duration `json:"interval-check" yaml:"interval-check" toml:"interval-check" mapstructure:"interval-check"`
|
||||
IntervalCheck libdur.Duration `json:"interval-check" yaml:"interval-check" toml:"interval-check" mapstructure:"interval-check"`
|
||||
|
||||
// IntervalFall define the time waiting between 2 healthcheck when last check is KO. Default is 5 second.
|
||||
IntervalFall time.Duration `json:"interval-fall" yaml:"interval-fall" toml:"interval-fall" mapstructure:"interval-down"`
|
||||
IntervalFall libdur.Duration `json:"interval-fall" yaml:"interval-fall" toml:"interval-fall" mapstructure:"interval-down"`
|
||||
|
||||
// IntervalRise define the time waiting between 2 healthcheck when status is KO or Warn but last check is OK. Default is 5 second.
|
||||
IntervalRise time.Duration `json:"interval-rise" yaml:"interval-rise" toml:"interval-rise" mapstructure:"interval-rise"`
|
||||
IntervalRise libdur.Duration `json:"interval-rise" yaml:"interval-rise" toml:"interval-rise" mapstructure:"interval-rise"`
|
||||
|
||||
// FallCountKO define the number of KO before considerate the component as down.
|
||||
FallCountKO uint8 `json:"fall-count-ko" yaml:"fall-count-ko" toml:"fall-count-ko" mapstructure:"fall-count-ko"`
|
||||
|
Reference in New Issue
Block a user