mirror of
https://github.com/nabbar/golib.git
synced 2025-10-08 01:00:09 +08:00
Package AWS :
- Config Model : add a config model with a golib RouerStatus Config Model to use a AWS connection for API with a request status health check - Config Interface : add function GetAccessKey to retrieve the accesskey value currently used into the current connection - function Walk (Object, version, ...) : fix bug with pointer of string not initialized Package Config : - interface Component : add status router pointer into the Init function to allow used a global router status for all component status registration as router status component Package Status : - move Status Config as an sub package of Package Status Package Errors : - add CamelCase const Package Logger : - fix following bump dependencies Global : - bump dependencies - change init of errors files : change function never call vy panic to prevent an error code collision
This commit is contained in:
@@ -203,7 +203,7 @@ func ExtractAll(src libiot.FileProgress, originalName, outputPath string, defaul
|
|||||||
func CreateArchive(archiveType ArchiveType, archive libiot.FileProgress, stripPath string, comment string, pathContent ...string) (created bool, err liberr.Error) {
|
func CreateArchive(archiveType ArchiveType, archive libiot.FileProgress, stripPath string, comment string, pathContent ...string) (created bool, err liberr.Error) {
|
||||||
if len(pathContent) < 1 {
|
if len(pathContent) < 1 {
|
||||||
//nolint #goerr113
|
//nolint #goerr113
|
||||||
return false, ErrorParamsEmpty.ErrorParent(fmt.Errorf("pathContent is empty"))
|
return false, ErrorParamEmpty.ErrorParent(fmt.Errorf("pathContent is empty"))
|
||||||
}
|
}
|
||||||
|
|
||||||
switch archiveType {
|
switch archiveType {
|
||||||
|
@@ -26,10 +26,14 @@
|
|||||||
|
|
||||||
package archive
|
package archive
|
||||||
|
|
||||||
import "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgArchive
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgArchive
|
||||||
ErrorFileSeek
|
ErrorFileSeek
|
||||||
ErrorFileOpen
|
ErrorFileOpen
|
||||||
ErrorFileClose
|
ErrorFileClose
|
||||||
@@ -39,22 +43,16 @@ const (
|
|||||||
ErrorIOCopy
|
ErrorIOCopy
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case ErrorParamEmpty:
|
||||||
return ""
|
|
||||||
case ErrorParamsEmpty:
|
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorFileSeek:
|
case ErrorFileSeek:
|
||||||
return "cannot seek into file"
|
return "cannot seek into file"
|
||||||
@@ -72,5 +70,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "error occurs when io copy"
|
return "error occurs when io copy"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,8 @@
|
|||||||
package configAws
|
package configAws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -40,16 +42,13 @@ const (
|
|||||||
ErrorCredentialsInvalid
|
ErrorCredentialsInvalid
|
||||||
)
|
)
|
||||||
|
|
||||||
var isErrInit = liberr.ExistInMapMessage(ErrorAwsError)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
if liberr.ExistInMapMessage(ErrorAwsError) {
|
||||||
|
panic(fmt.Errorf("error code collision"))
|
||||||
|
}
|
||||||
liberr.RegisterIdFctMessage(ErrorAwsError, getMessage)
|
liberr.RegisterIdFctMessage(ErrorAwsError, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsErrorInit() bool {
|
|
||||||
return isErrInit
|
|
||||||
}
|
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) string {
|
func getMessage(code liberr.CodeError) string {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorAwsError:
|
case ErrorAwsError:
|
||||||
@@ -70,5 +69,5 @@ func getMessage(code liberr.CodeError) string {
|
|||||||
return "the specified credentials seems to be incorrect"
|
return "the specified credentials seems to be incorrect"
|
||||||
}
|
}
|
||||||
|
|
||||||
return liberr.UNK_MESSAGE
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -53,6 +53,18 @@ func NewConfigJsonUnmashal(p []byte) (libaws.Config, errors.Error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewConfigStatusJsonUnmashal(p []byte) (libaws.Config, errors.Error) {
|
||||||
|
c := ModelStatus{}
|
||||||
|
if err := json.Unmarshal(p, &c); err != nil {
|
||||||
|
return nil, ErrorConfigJsonUnmarshall.ErrorParent(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &awsModel{
|
||||||
|
Model: c.Config,
|
||||||
|
retryer: nil,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func NewConfig(bucket, accessKey, secretKey, region string) libaws.Config {
|
func NewConfig(bucket, accessKey, secretKey, region string) libaws.Config {
|
||||||
return &awsModel{
|
return &awsModel{
|
||||||
Model: Model{
|
Model: Model{
|
||||||
|
@@ -31,6 +31,8 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
libsts "github.com/nabbar/golib/status/config"
|
||||||
|
|
||||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||||
libval "github.com/go-playground/validator/v10"
|
libval "github.com/go-playground/validator/v10"
|
||||||
"github.com/nabbar/golib/errors"
|
"github.com/nabbar/golib/errors"
|
||||||
@@ -44,6 +46,11 @@ type Model struct {
|
|||||||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket" toml:"bucket" validate:"printascii,omitempty"`
|
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket" toml:"bucket" validate:"printascii,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ModelStatus struct {
|
||||||
|
Config Model `json:"config" yaml:"config" toml:"config" mapstructure:"config" validate:"required,dive"`
|
||||||
|
Status libsts.ConfigStatus `json:"status" yaml:"status" toml:"status" mapstructure:"status" validate:"required,dive"`
|
||||||
|
}
|
||||||
|
|
||||||
type awsModel struct {
|
type awsModel struct {
|
||||||
Model
|
Model
|
||||||
retryer func() sdkaws.Retryer
|
retryer func() sdkaws.Retryer
|
||||||
@@ -70,6 +77,10 @@ func (c *awsModel) Validate() errors.Error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *awsModel) GetAccessKey() string {
|
||||||
|
return c.AccessKey
|
||||||
|
}
|
||||||
|
|
||||||
func (c *awsModel) SetCredentials(accessKey, secretKey string) {
|
func (c *awsModel) SetCredentials(accessKey, secretKey string) {
|
||||||
c.AccessKey = accessKey
|
c.AccessKey = accessKey
|
||||||
c.SecretKey = secretKey
|
c.SecretKey = secretKey
|
||||||
|
@@ -26,6 +26,8 @@
|
|||||||
package configCustom
|
package configCustom
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -39,16 +41,13 @@ const (
|
|||||||
ErrorCredentialsInvalid
|
ErrorCredentialsInvalid
|
||||||
)
|
)
|
||||||
|
|
||||||
var isErrInit = liberr.ExistInMapMessage(ErrorAwsError)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
if liberr.ExistInMapMessage(ErrorAwsError) {
|
||||||
|
panic(fmt.Errorf("error code collision"))
|
||||||
|
}
|
||||||
liberr.RegisterIdFctMessage(ErrorAwsError, getMessage)
|
liberr.RegisterIdFctMessage(ErrorAwsError, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsErrorInit() bool {
|
|
||||||
return isErrInit
|
|
||||||
}
|
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) string {
|
func getMessage(code liberr.CodeError) string {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorAwsError:
|
case ErrorAwsError:
|
||||||
@@ -67,5 +66,5 @@ func getMessage(code liberr.CodeError) string {
|
|||||||
return "the specified credentials seems to be incorrect"
|
return "the specified credentials seems to be incorrect"
|
||||||
}
|
}
|
||||||
|
|
||||||
return liberr.UNK_MESSAGE
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -35,14 +35,14 @@ import (
|
|||||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||||
sdkcrd "github.com/aws/aws-sdk-go-v2/credentials"
|
sdkcrd "github.com/aws/aws-sdk-go-v2/credentials"
|
||||||
libaws "github.com/nabbar/golib/aws"
|
libaws "github.com/nabbar/golib/aws"
|
||||||
"github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetConfigModel() interface{} {
|
func GetConfigModel() interface{} {
|
||||||
return Model{}
|
return Model{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfigJsonUnmashal(p []byte) (libaws.Config, errors.Error) {
|
func NewConfigJsonUnmashal(p []byte) (libaws.Config, liberr.Error) {
|
||||||
c := Model{}
|
c := Model{}
|
||||||
if err := json.Unmarshal(p, &c); err != nil {
|
if err := json.Unmarshal(p, &c); err != nil {
|
||||||
return nil, ErrorConfigJsonUnmarshall.ErrorParent(err)
|
return nil, ErrorConfigJsonUnmarshall.ErrorParent(err)
|
||||||
@@ -55,6 +55,19 @@ func NewConfigJsonUnmashal(p []byte) (libaws.Config, errors.Error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewConfigStatusJsonUnmashal(p []byte) (libaws.Config, liberr.Error) {
|
||||||
|
c := ModelStatus{}
|
||||||
|
if err := json.Unmarshal(p, &c); err != nil {
|
||||||
|
return nil, ErrorConfigJsonUnmarshall.ErrorParent(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &awsModel{
|
||||||
|
Model: c.Config,
|
||||||
|
retryer: nil,
|
||||||
|
mapRegion: nil,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func NewConfig(bucket, accessKey, secretKey string, endpoint *url.URL, region string) libaws.Config {
|
func NewConfig(bucket, accessKey, secretKey string, endpoint *url.URL, region string) libaws.Config {
|
||||||
return &awsModel{
|
return &awsModel{
|
||||||
Model: Model{
|
Model: Model{
|
||||||
@@ -91,7 +104,7 @@ func (c *awsModel) Clone() libaws.Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *awsModel) GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, errors.Error) {
|
func (c *awsModel) GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, liberr.Error) {
|
||||||
|
|
||||||
cfg := sdkaws.NewConfig()
|
cfg := sdkaws.NewConfig()
|
||||||
|
|
||||||
|
@@ -34,9 +34,10 @@ import (
|
|||||||
|
|
||||||
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
|
||||||
libval "github.com/go-playground/validator/v10"
|
libval "github.com/go-playground/validator/v10"
|
||||||
"github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
"github.com/nabbar/golib/httpcli"
|
libhtc "github.com/nabbar/golib/httpcli"
|
||||||
"github.com/nabbar/golib/logger"
|
liblog "github.com/nabbar/golib/logger"
|
||||||
|
libsts "github.com/nabbar/golib/status/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Model struct {
|
type Model struct {
|
||||||
@@ -47,6 +48,11 @@ type Model struct {
|
|||||||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket" toml:"bucket" validate:"omitempty,hostname"`
|
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket" toml:"bucket" validate:"omitempty,hostname"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ModelStatus struct {
|
||||||
|
Config Model `json:"config" yaml:"config" toml:"config" mapstructure:"config" validate:"required,dive"`
|
||||||
|
Status libsts.ConfigStatus `json:"status" yaml:"status" toml:"status" mapstructure:"status" validate:"required,dive"`
|
||||||
|
}
|
||||||
|
|
||||||
type awsModel struct {
|
type awsModel struct {
|
||||||
Model
|
Model
|
||||||
|
|
||||||
@@ -55,7 +61,7 @@ type awsModel struct {
|
|||||||
mapRegion map[string]*url.URL
|
mapRegion map[string]*url.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *awsModel) Validate() errors.Error {
|
func (c *awsModel) Validate() liberr.Error {
|
||||||
err := ErrorConfigValidator.Error(nil)
|
err := ErrorConfigValidator.Error(nil)
|
||||||
|
|
||||||
if er := libval.New().Struct(c); er != nil {
|
if er := libval.New().Struct(c); er != nil {
|
||||||
@@ -93,6 +99,10 @@ func (c *awsModel) Validate() errors.Error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *awsModel) GetAccessKey() string {
|
||||||
|
return c.AccessKey
|
||||||
|
}
|
||||||
|
|
||||||
func (c *awsModel) SetCredentials(accessKey, secretKey string) {
|
func (c *awsModel) SetCredentials(accessKey, secretKey string) {
|
||||||
c.AccessKey = accessKey
|
c.AccessKey = accessKey
|
||||||
c.SecretKey = secretKey
|
c.SecretKey = secretKey
|
||||||
@@ -102,7 +112,7 @@ func (c *awsModel) ResetRegionEndpoint() {
|
|||||||
c.mapRegion = make(map[string]*url.URL)
|
c.mapRegion = make(map[string]*url.URL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) errors.Error {
|
func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) liberr.Error {
|
||||||
if endpoint == nil && c.endpoint != nil {
|
if endpoint == nil && c.endpoint != nil {
|
||||||
endpoint = c.endpoint
|
endpoint = c.endpoint
|
||||||
} else if endpoint == nil && c.Endpoint != "" {
|
} else if endpoint == nil && c.Endpoint != "" {
|
||||||
@@ -137,7 +147,7 @@ func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) erro
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *awsModel) RegisterRegionAws(endpoint *url.URL) errors.Error {
|
func (c *awsModel) RegisterRegionAws(endpoint *url.URL) liberr.Error {
|
||||||
if endpoint == nil && c.endpoint != nil {
|
if endpoint == nil && c.endpoint != nil {
|
||||||
endpoint = c.endpoint
|
endpoint = c.endpoint
|
||||||
} else if endpoint == nil && c.Endpoint != "" {
|
} else if endpoint == nil && c.Endpoint != "" {
|
||||||
@@ -231,7 +241,7 @@ func (c *awsModel) ResolveEndpoint(service, region string) (sdkaws.Endpoint, err
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.DebugLevel.Logf("Called ResolveEndpoint for service '%s' / region '%s' with nil endpoint", service, region)
|
liblog.DebugLevel.Logf("Called ResolveEndpoint for service '%s' / region '%s' with nil endpoint", service, region)
|
||||||
return sdkaws.Endpoint{}, ErrorEndpointInvalid.Error(nil)
|
return sdkaws.Endpoint{}, ErrorEndpointInvalid.Error(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,12 +253,12 @@ func (c *awsModel) SetRetryer(retryer func() sdkaws.Retryer) {
|
|||||||
c.retryer = retryer
|
c.retryer = retryer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c awsModel) Check(ctx context.Context) errors.Error {
|
func (c awsModel) Check(ctx context.Context) liberr.Error {
|
||||||
var (
|
var (
|
||||||
cfg *sdkaws.Config
|
cfg *sdkaws.Config
|
||||||
con net.Conn
|
con net.Conn
|
||||||
err error
|
err error
|
||||||
e errors.Error
|
e liberr.Error
|
||||||
)
|
)
|
||||||
|
|
||||||
if cfg, e = c.GetConfig(ctx, nil); e != nil {
|
if cfg, e = c.GetConfig(ctx, nil); e != nil {
|
||||||
@@ -268,8 +278,8 @@ func (c awsModel) Check(ctx context.Context) errors.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
d := net.Dialer{
|
d := net.Dialer{
|
||||||
Timeout: httpcli.ClientTimeout5Sec,
|
Timeout: libhtc.ClientTimeout5Sec,
|
||||||
KeepAlive: httpcli.ClientTimeout5Sec,
|
KeepAlive: libhtc.ClientTimeout5Sec,
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.endpoint.Port() == "" && c.endpoint.Scheme == "http" {
|
if c.endpoint.Port() == "" && c.endpoint.Scheme == "http" {
|
||||||
|
@@ -26,12 +26,14 @@
|
|||||||
package helper
|
package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
errors "github.com/nabbar/golib/errors"
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// minmal are errors.MIN_AVAILABLE + get a hope free range 1000 + 10 for aws-config errors.
|
// minmal are liberr.MIN_AVAILABLE + get a hope free range 1000 + 10 for aws-config liberr.
|
||||||
ErrorResponse errors.CodeError = iota + errors.MinPkgAws + 60
|
ErrorResponse liberr.CodeError = iota + liberr.MinPkgAws + 60
|
||||||
ErrorConfigEmpty
|
ErrorConfigEmpty
|
||||||
ErrorAwsEmpty
|
ErrorAwsEmpty
|
||||||
ErrorAws
|
ErrorAws
|
||||||
@@ -39,17 +41,20 @@ const (
|
|||||||
ErrorParamsEmpty
|
ErrorParamsEmpty
|
||||||
)
|
)
|
||||||
|
|
||||||
var isErrInit = errors.ExistInMapMessage(ErrorResponse)
|
var isErrInit = liberr.ExistInMapMessage(ErrorResponse)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
errors.RegisterIdFctMessage(ErrorResponse, getMessage)
|
if liberr.ExistInMapMessage(ErrorResponse) {
|
||||||
|
panic(fmt.Errorf("error code collision with package golib/aws/helpers"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorResponse, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsErrorInit() bool {
|
func IsErrorInit() bool {
|
||||||
return isErrInit
|
return isErrInit
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) string {
|
func getMessage(code liberr.CodeError) string {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorResponse:
|
case ErrorResponse:
|
||||||
return "calling aws api occurred a response error"
|
return "calling aws api occurred a response error"
|
||||||
@@ -65,5 +70,5 @@ func getMessage(code errors.CodeError) string {
|
|||||||
return "at least one parameters needed is empty"
|
return "at least one parameters needed is empty"
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.UNK_MESSAGE
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -48,6 +48,7 @@ type Config interface {
|
|||||||
Check(ctx context.Context) liberr.Error
|
Check(ctx context.Context) liberr.Error
|
||||||
Validate() liberr.Error
|
Validate() liberr.Error
|
||||||
|
|
||||||
|
GetAccessKey() string
|
||||||
SetCredentials(accessKey, secretKey string)
|
SetCredentials(accessKey, secretKey string)
|
||||||
ResetRegionEndpoint()
|
ResetRegionEndpoint()
|
||||||
RegisterRegionEndpoint(region string, endpoint *url.URL) liberr.Error
|
RegisterRegionEndpoint(region string, endpoint *url.URL) liberr.Error
|
||||||
|
@@ -81,7 +81,7 @@ func (cli *client) WalkPrefix(prefix string, f WalkFunc) liberr.Error {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
e liberr.Error
|
e liberr.Error
|
||||||
t *string
|
t = sdkaws.String("")
|
||||||
)
|
)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@@ -77,8 +77,8 @@ func (cli *client) VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMa
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
e liberr.Error
|
e liberr.Error
|
||||||
km *string
|
km = sdkaws.String("")
|
||||||
mi *string
|
mi = sdkaws.String("")
|
||||||
)
|
)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@@ -26,10 +26,14 @@
|
|||||||
|
|
||||||
package certificates
|
package certificates
|
||||||
|
|
||||||
import "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgCertificate
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgCertificate
|
||||||
ErrorFileStat
|
ErrorFileStat
|
||||||
ErrorFileRead
|
ErrorFileRead
|
||||||
ErrorFileEmpty
|
ErrorFileEmpty
|
||||||
@@ -39,22 +43,18 @@ const (
|
|||||||
ErrorValidatorError
|
ErrorValidatorError
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/certificates"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case liberr.UNK_ERROR:
|
||||||
return ""
|
return ""
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorFileStat:
|
case ErrorFileStat:
|
||||||
return "cannot get file stat"
|
return "cannot get file stat"
|
||||||
@@ -72,5 +72,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "tls : invalid config"
|
return "tls : invalid config"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -53,7 +53,7 @@ type config struct {
|
|||||||
func (c *config) checkFile(pemFiles ...string) liberr.Error {
|
func (c *config) checkFile(pemFiles ...string) liberr.Error {
|
||||||
for _, f := range pemFiles {
|
for _, f := range pemFiles {
|
||||||
if f == "" {
|
if f == "" {
|
||||||
return ErrorParamsEmpty.Error(nil)
|
return ErrorParamEmpty.Error(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, e := os.Stat(f); e != nil {
|
if _, e := os.Stat(f); e != nil {
|
||||||
@@ -157,7 +157,7 @@ func (c *config) AddCertificatePairString(key, crt string) liberr.Error {
|
|||||||
crt = strings.TrimSpace(crt)
|
crt = strings.TrimSpace(crt)
|
||||||
|
|
||||||
if len(key) < 1 || len(crt) < 1 {
|
if len(key) < 1 || len(crt) < 1 {
|
||||||
return ErrorParamsEmpty.Error(nil)
|
return ErrorParamEmpty.Error(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
p, err := tls.X509KeyPair([]byte(crt), []byte(key))
|
p, err := tls.X509KeyPair([]byte(crt), []byte(key))
|
||||||
|
@@ -37,7 +37,7 @@ type Component interface {
|
|||||||
Type() string
|
Type() string
|
||||||
|
|
||||||
// Init is called by Config to register some function and value to the component instance.
|
// Init is called by Config to register some function and value to the component instance.
|
||||||
Init(key string, ctx FuncContext, get FuncComponentGet, vpr FuncComponentViper)
|
Init(key string, ctx FuncContext, get FuncComponentGet, vpr FuncComponentViper, sts FuncRouteStatus)
|
||||||
|
|
||||||
// RegisterFuncStart is called to register the function to be called before and after the start function.
|
// RegisterFuncStart is called to register the function to be called before and after the start function.
|
||||||
RegisterFuncStart(before, after func(cpt Component) liberr.Error)
|
RegisterFuncStart(before, after func(cpt Component) liberr.Error)
|
||||||
|
@@ -35,6 +35,7 @@ import (
|
|||||||
cfgcus "github.com/nabbar/golib/aws/configCustom"
|
cfgcus "github.com/nabbar/golib/aws/configCustom"
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
libsts "github.com/nabbar/golib/status/config"
|
||||||
spfcbr "github.com/spf13/cobra"
|
spfcbr "github.com/spf13/cobra"
|
||||||
spfvbr "github.com/spf13/viper"
|
spfvbr "github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@@ -47,6 +48,15 @@ var _defaultConfigStandard = []byte(`{
|
|||||||
"endpoint": ""
|
"endpoint": ""
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
|
var _defaultConfigStandardWithStatus = []byte(`{
|
||||||
|
"bucket": "",
|
||||||
|
"accesskey": "",
|
||||||
|
"secretkey": "",
|
||||||
|
"region": "",
|
||||||
|
"endpoint": "",
|
||||||
|
"status":` + string(libsts.DefaultConfig(libcfg.JSONIndent+libcfg.JSONIndent)) + `
|
||||||
|
}`)
|
||||||
|
|
||||||
var _defaultConfigCustom = []byte(`{
|
var _defaultConfigCustom = []byte(`{
|
||||||
"bucket": "",
|
"bucket": "",
|
||||||
"accesskey": "",
|
"accesskey": "",
|
||||||
@@ -55,18 +65,35 @@ var _defaultConfigCustom = []byte(`{
|
|||||||
"endpoint": ""
|
"endpoint": ""
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
|
var _defaultConfigCustomWithStatus = []byte(`{
|
||||||
|
"bucket": "",
|
||||||
|
"accesskey": "",
|
||||||
|
"secretkey": "",
|
||||||
|
"region": "",
|
||||||
|
"endpoint": "",
|
||||||
|
"status":` + string(libsts.DefaultConfig(libcfg.JSONIndent+libcfg.JSONIndent)) + `
|
||||||
|
}`)
|
||||||
|
|
||||||
var _defaultConfig = _defaultConfigCustom
|
var _defaultConfig = _defaultConfigCustom
|
||||||
|
|
||||||
func SetDefaultConfig(cfg []byte) {
|
func SetDefaultConfig(cfg []byte) {
|
||||||
_defaultConfig = cfg
|
_defaultConfig = cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetDefaultConfigStandard() {
|
func SetDefaultConfigStandard(withStatus bool) {
|
||||||
_defaultConfig = _defaultConfigStandard
|
if withStatus {
|
||||||
|
_defaultConfig = _defaultConfigStandardWithStatus
|
||||||
|
} else {
|
||||||
|
_defaultConfig = _defaultConfigStandard
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetDefaultConfigCustom() {
|
func SetDefaultConfigCustom(withStatus bool) {
|
||||||
_defaultConfig = _defaultConfigCustom
|
if withStatus {
|
||||||
|
_defaultConfig = _defaultConfigCustomWithStatus
|
||||||
|
} else {
|
||||||
|
_defaultConfig = _defaultConfigCustom
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultConfig(indent string) []byte {
|
func DefaultConfig(indent string) []byte {
|
||||||
@@ -104,18 +131,44 @@ func (c *componentAws) RegisterFlag(Command *spfcbr.Command, Viper *spfvbr.Viper
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentAws) _getConfig(getCfg libcfg.FuncComponentConfigGet) (libaws.Config, liberr.Error) {
|
func (c *componentAws) _getConfig(getCfg libcfg.FuncComponentConfigGet) (libaws.Config, *libsts.ConfigStatus, liberr.Error) {
|
||||||
var (
|
var (
|
||||||
vpr = c.vpr()
|
vpr = c.vpr()
|
||||||
cfg libaws.Config
|
cfg libaws.Config
|
||||||
|
sts *libsts.ConfigStatus
|
||||||
err liberr.Error
|
err liberr.Error
|
||||||
)
|
)
|
||||||
|
|
||||||
switch c.d {
|
switch c.d {
|
||||||
|
case ConfigCustomStatus:
|
||||||
|
cnf := cfgcus.ModelStatus{}
|
||||||
|
if e := getCfg(c.key, &cnf); e != nil {
|
||||||
|
return nil, nil, ErrorParamInvalid.Error(e)
|
||||||
|
}
|
||||||
|
if s := vpr.GetString(c.key + ".access-key"); s != "" {
|
||||||
|
cnf.Config.AccessKey = s
|
||||||
|
}
|
||||||
|
if s := vpr.GetString(c.key + ".secret-key"); s != "" {
|
||||||
|
cnf.Config.SecretKey = s
|
||||||
|
}
|
||||||
|
if s := vpr.GetString(c.key + ".bucket"); s != "" {
|
||||||
|
cnf.Config.Bucket = s
|
||||||
|
}
|
||||||
|
if s := vpr.GetString(c.key + ".region"); s != "" {
|
||||||
|
cnf.Config.Region = s
|
||||||
|
}
|
||||||
|
if s := vpr.GetString(c.key + ".endpoint"); s != "" {
|
||||||
|
cnf.Config.Endpoint = s
|
||||||
|
}
|
||||||
|
if cfg, err = c.d.NewFromModel(cnf); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
} else {
|
||||||
|
sts = &cnf.Status
|
||||||
|
}
|
||||||
case ConfigCustom:
|
case ConfigCustom:
|
||||||
cnf := cfgcus.Model{}
|
cnf := cfgcus.Model{}
|
||||||
if e := getCfg(c.key, &cnf); e != nil {
|
if e := getCfg(c.key, &cnf); e != nil {
|
||||||
return nil, ErrorParamsInvalid.Error(e)
|
return nil, nil, ErrorParamInvalid.Error(e)
|
||||||
}
|
}
|
||||||
if s := vpr.GetString(c.key + ".access-key"); s != "" {
|
if s := vpr.GetString(c.key + ".access-key"); s != "" {
|
||||||
cnf.AccessKey = s
|
cnf.AccessKey = s
|
||||||
@@ -133,12 +186,34 @@ func (c *componentAws) _getConfig(getCfg libcfg.FuncComponentConfigGet) (libaws.
|
|||||||
cnf.Endpoint = s
|
cnf.Endpoint = s
|
||||||
}
|
}
|
||||||
if cfg, err = c.d.NewFromModel(cnf); err != nil {
|
if cfg, err = c.d.NewFromModel(cnf); err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
case ConfigStandardStatus:
|
||||||
|
cnf := cfgstd.ModelStatus{}
|
||||||
|
if e := getCfg(c.key, &cnf); e != nil {
|
||||||
|
return nil, nil, ErrorParamInvalid.Error(e)
|
||||||
|
}
|
||||||
|
if s := vpr.GetString(c.key + ".access-key"); s != "" {
|
||||||
|
cnf.Config.AccessKey = s
|
||||||
|
}
|
||||||
|
if s := vpr.GetString(c.key + ".secret-key"); s != "" {
|
||||||
|
cnf.Config.SecretKey = s
|
||||||
|
}
|
||||||
|
if s := vpr.GetString(c.key + ".bucket"); s != "" {
|
||||||
|
cnf.Config.Bucket = s
|
||||||
|
}
|
||||||
|
if s := vpr.GetString(c.key + ".region"); s != "" {
|
||||||
|
cnf.Config.Region = s
|
||||||
|
}
|
||||||
|
if cfg, err = c.d.NewFromModel(cnf); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
} else {
|
||||||
|
sts = &cnf.Status
|
||||||
}
|
}
|
||||||
case ConfigStandard:
|
case ConfigStandard:
|
||||||
cnf := cfgstd.Model{}
|
cnf := cfgstd.Model{}
|
||||||
if e := getCfg(c.key, &cnf); e != nil {
|
if e := getCfg(c.key, &cnf); e != nil {
|
||||||
return nil, ErrorParamsInvalid.Error(e)
|
return nil, nil, ErrorParamInvalid.Error(e)
|
||||||
}
|
}
|
||||||
if s := vpr.GetString(c.key + ".access-key"); s != "" {
|
if s := vpr.GetString(c.key + ".access-key"); s != "" {
|
||||||
cnf.AccessKey = s
|
cnf.AccessKey = s
|
||||||
@@ -153,13 +228,13 @@ func (c *componentAws) _getConfig(getCfg libcfg.FuncComponentConfigGet) (libaws.
|
|||||||
cnf.Region = s
|
cnf.Region = s
|
||||||
}
|
}
|
||||||
if cfg, err = c.d.NewFromModel(cnf); err != nil {
|
if cfg, err = c.d.NewFromModel(cnf); err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = cfg.Validate(); err != nil {
|
if err = cfg.Validate(); err != nil {
|
||||||
return nil, ErrorConfigInvalid.Error(err)
|
return nil, nil, ErrorConfigInvalid.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return cfg, nil
|
return cfg, sts, nil
|
||||||
}
|
}
|
||||||
|
@@ -39,13 +39,19 @@ type ConfigDriver uint8
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
ConfigStandard ConfigDriver = iota
|
ConfigStandard ConfigDriver = iota
|
||||||
|
ConfigStandardStatus
|
||||||
ConfigCustom
|
ConfigCustom
|
||||||
|
ConfigCustomStatus
|
||||||
)
|
)
|
||||||
|
|
||||||
func DriverConfig(value int) ConfigDriver {
|
func DriverConfig(value int) ConfigDriver {
|
||||||
switch value {
|
switch value {
|
||||||
case int(ConfigCustom):
|
case int(ConfigCustom):
|
||||||
return ConfigCustom
|
return ConfigCustom
|
||||||
|
case int(ConfigCustomStatus):
|
||||||
|
return ConfigCustomStatus
|
||||||
|
case int(ConfigStandardStatus):
|
||||||
|
return ConfigStandardStatus
|
||||||
default:
|
default:
|
||||||
return ConfigStandard
|
return ConfigStandard
|
||||||
}
|
}
|
||||||
@@ -55,6 +61,10 @@ func (a ConfigDriver) String() string {
|
|||||||
switch a {
|
switch a {
|
||||||
case ConfigCustom:
|
case ConfigCustom:
|
||||||
return "Custom"
|
return "Custom"
|
||||||
|
case ConfigCustomStatus:
|
||||||
|
return "CustomWithStatus"
|
||||||
|
case ConfigStandardStatus:
|
||||||
|
return "StandardWithStatus"
|
||||||
default:
|
default:
|
||||||
return "Standard"
|
return "Standard"
|
||||||
}
|
}
|
||||||
@@ -64,6 +74,10 @@ func (a ConfigDriver) Unmarshal(p []byte) (libaws.Config, liberr.Error) {
|
|||||||
switch a {
|
switch a {
|
||||||
case ConfigCustom:
|
case ConfigCustom:
|
||||||
return cfgcus.NewConfigJsonUnmashal(p)
|
return cfgcus.NewConfigJsonUnmashal(p)
|
||||||
|
case ConfigCustomStatus:
|
||||||
|
return cfgcus.NewConfigStatusJsonUnmashal(p)
|
||||||
|
case ConfigStandardStatus:
|
||||||
|
return cfgstd.NewConfigStatusJsonUnmashal(p)
|
||||||
default:
|
default:
|
||||||
return cfgstd.NewConfigJsonUnmashal(p)
|
return cfgstd.NewConfigJsonUnmashal(p)
|
||||||
}
|
}
|
||||||
@@ -71,8 +85,10 @@ func (a ConfigDriver) Unmarshal(p []byte) (libaws.Config, liberr.Error) {
|
|||||||
|
|
||||||
func (a ConfigDriver) Config(bucket, accessKey, secretKey string, region string, endpoint *url.URL) libaws.Config {
|
func (a ConfigDriver) Config(bucket, accessKey, secretKey string, region string, endpoint *url.URL) libaws.Config {
|
||||||
switch a {
|
switch a {
|
||||||
case ConfigCustom:
|
case ConfigCustom, ConfigCustomStatus:
|
||||||
return cfgcus.NewConfig(bucket, accessKey, secretKey, endpoint, region)
|
return cfgcus.NewConfig(bucket, accessKey, secretKey, endpoint, region)
|
||||||
|
case ConfigStandardStatus:
|
||||||
|
return cfgstd.NewConfig(bucket, accessKey, secretKey, region)
|
||||||
default:
|
default:
|
||||||
return cfgstd.NewConfig(bucket, accessKey, secretKey, region)
|
return cfgstd.NewConfig(bucket, accessKey, secretKey, region)
|
||||||
}
|
}
|
||||||
@@ -82,6 +98,10 @@ func (a ConfigDriver) Model() interface{} {
|
|||||||
switch a {
|
switch a {
|
||||||
case ConfigCustom:
|
case ConfigCustom:
|
||||||
return cfgcus.Model{}
|
return cfgcus.Model{}
|
||||||
|
case ConfigCustomStatus:
|
||||||
|
return cfgcus.ModelStatus{}
|
||||||
|
case ConfigStandardStatus:
|
||||||
|
return cfgstd.ModelStatus{}
|
||||||
default:
|
default:
|
||||||
return cfgstd.Model{}
|
return cfgstd.Model{}
|
||||||
}
|
}
|
||||||
@@ -89,6 +109,18 @@ func (a ConfigDriver) Model() interface{} {
|
|||||||
|
|
||||||
func (a ConfigDriver) NewFromModel(i interface{}) (libaws.Config, liberr.Error) {
|
func (a ConfigDriver) NewFromModel(i interface{}) (libaws.Config, liberr.Error) {
|
||||||
switch a {
|
switch a {
|
||||||
|
case ConfigCustomStatus:
|
||||||
|
if o, ok := i.(cfgcus.ModelStatus); !ok {
|
||||||
|
return nil, ErrorConfigInvalid.Error(nil)
|
||||||
|
} else {
|
||||||
|
return ConfigCustom.NewFromModel(o.Config)
|
||||||
|
}
|
||||||
|
case ConfigStandardStatus:
|
||||||
|
if o, ok := i.(cfgstd.ModelStatus); !ok {
|
||||||
|
return nil, ErrorConfigInvalid.Error(nil)
|
||||||
|
} else {
|
||||||
|
return ConfigStandard.NewFromModel(o.Config)
|
||||||
|
}
|
||||||
case ConfigCustom:
|
case ConfigCustom:
|
||||||
if o, ok := i.(cfgcus.Model); !ok {
|
if o, ok := i.(cfgcus.Model); !ok {
|
||||||
return nil, ErrorConfigInvalid.Error(nil)
|
return nil, ErrorConfigInvalid.Error(nil)
|
||||||
|
@@ -27,13 +27,15 @@
|
|||||||
package aws
|
package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + libcfg.MinErrorComponentAws
|
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentAws
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorComponentNotInitialized
|
ErrorComponentNotInitialized
|
||||||
ErrorConfigInvalid
|
ErrorConfigInvalid
|
||||||
ErrorStartComponent
|
ErrorStartComponent
|
||||||
@@ -42,21 +44,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/config/components/aws"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorComponentNotInitialized:
|
case ErrorComponentNotInitialized:
|
||||||
return "this component seems to not be correctly initialized"
|
return "this component seems to not be correctly initialized"
|
||||||
@@ -70,5 +68,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "cannot retrieve default Logger"
|
return "cannot retrieve default Logger"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -33,12 +33,16 @@ import (
|
|||||||
libaws "github.com/nabbar/golib/aws"
|
libaws "github.com/nabbar/golib/aws"
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
libsts "github.com/nabbar/golib/status"
|
||||||
|
stscfg "github.com/nabbar/golib/status/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type componentAws struct {
|
type componentAws struct {
|
||||||
ctx libcfg.FuncContext
|
ctx libcfg.FuncContext
|
||||||
get libcfg.FuncComponentGet
|
get libcfg.FuncComponentGet
|
||||||
vpr libcfg.FuncComponentViper
|
vpr libcfg.FuncComponentViper
|
||||||
|
sts libcfg.FuncRouteStatus
|
||||||
|
|
||||||
key string
|
key string
|
||||||
|
|
||||||
fsa func(cpt libcfg.Component) liberr.Error
|
fsa func(cpt libcfg.Component) liberr.Error
|
||||||
@@ -46,10 +50,14 @@ type componentAws struct {
|
|||||||
fra func(cpt libcfg.Component) liberr.Error
|
fra func(cpt libcfg.Component) liberr.Error
|
||||||
frb func(cpt libcfg.Component) liberr.Error
|
frb func(cpt libcfg.Component) liberr.Error
|
||||||
|
|
||||||
|
fsi libsts.FctInfo
|
||||||
|
fsh libsts.FctHealth
|
||||||
|
|
||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
d ConfigDriver
|
d ConfigDriver
|
||||||
c func() *http.Client
|
c func() *http.Client
|
||||||
a libaws.AWS
|
a libaws.AWS
|
||||||
|
s stscfg.ConfigStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentAws) _getHttpClient() *http.Client {
|
func (c *componentAws) _getHttpClient() *http.Client {
|
||||||
@@ -83,12 +91,16 @@ func (c *componentAws) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Erro
|
|||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
if cfg, err := c._getConfig(getCfg); err != nil {
|
if cfg, sts, err := c._getConfig(getCfg); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if cli, er := libaws.New(c.ctx(), cfg, c._getHttpClient()); er != nil {
|
} else if cli, er := libaws.New(c.ctx(), cfg, c._getHttpClient()); er != nil {
|
||||||
return er
|
return er
|
||||||
} else {
|
} else {
|
||||||
c.a = cli
|
c.a = cli
|
||||||
|
|
||||||
|
if sts != nil && c.sts != nil && c.fsi != nil && c.fsh != nil {
|
||||||
|
sts.RegisterStatus(c.sts(), c.key, c.fsi, c.fsh)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -112,7 +124,7 @@ func (c *componentAws) Type() string {
|
|||||||
return ComponentType
|
return ComponentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentAws) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper) {
|
func (c *componentAws) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper, sts libcfg.FuncRouteStatus) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ import (
|
|||||||
libdbs "github.com/nabbar/golib/database"
|
libdbs "github.com/nabbar/golib/database"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
liblog "github.com/nabbar/golib/logger"
|
liblog "github.com/nabbar/golib/logger"
|
||||||
libsts "github.com/nabbar/golib/status"
|
libsts "github.com/nabbar/golib/status/config"
|
||||||
spfcbr "github.com/spf13/cobra"
|
spfcbr "github.com/spf13/cobra"
|
||||||
spfvbr "github.com/spf13/viper"
|
spfvbr "github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@@ -153,7 +153,7 @@ func (c *componentDatabase) _getConfig(getCfg libcfg.FuncComponentConfigGet) (li
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := getCfg(c.key, &cnf); err != nil {
|
if err := getCfg(c.key, &cnf); err != nil {
|
||||||
return cnf, ErrorParamsInvalid.Error(err)
|
return cnf, ErrorParamInvalid.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fct := func() liblog.Logger {
|
fct := func() liblog.Logger {
|
||||||
|
@@ -27,13 +27,15 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + libcfg.MinErrorComponentDatabase
|
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentDatabase
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorComponentNotInitialized
|
ErrorComponentNotInitialized
|
||||||
ErrorConfigInvalid
|
ErrorConfigInvalid
|
||||||
ErrorStartDatabase
|
ErrorStartDatabase
|
||||||
@@ -42,21 +44,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/config/components/database"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorComponentNotInitialized:
|
case ErrorComponentNotInitialized:
|
||||||
return "this component seems to not be correctly initialized"
|
return "this component seems to not be correctly initialized"
|
||||||
@@ -70,5 +68,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "cannot retrieve default Logger"
|
return "cannot retrieve default Logger"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -139,7 +139,7 @@ func (c *componentDatabase) Type() string {
|
|||||||
return ComponentType
|
return ComponentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentDatabase) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper) {
|
func (c *componentDatabase) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper, sts libcfg.FuncRouteStatus) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
|
@@ -27,13 +27,15 @@
|
|||||||
package head
|
package head
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + libcfg.MinErrorComponentHead
|
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentHead
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorComponentNotInitialized
|
ErrorComponentNotInitialized
|
||||||
ErrorConfigInvalid
|
ErrorConfigInvalid
|
||||||
ErrorReloadPoolServer
|
ErrorReloadPoolServer
|
||||||
@@ -41,21 +43,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/config/components/head"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorComponentNotInitialized:
|
case ErrorComponentNotInitialized:
|
||||||
return "this component seems to not be correctly initialized"
|
return "this component seems to not be correctly initialized"
|
||||||
@@ -67,5 +65,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "cannot update default TLS with new config"
|
return "cannot update default TLS with new config"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -74,7 +74,7 @@ func (c *componentHead) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Err
|
|||||||
|
|
||||||
cnf := librtr.HeadersConfig{}
|
cnf := librtr.HeadersConfig{}
|
||||||
if err := getCfg(c.key, &cnf); err != nil {
|
if err := getCfg(c.key, &cnf); err != nil {
|
||||||
return ErrorParamsInvalid.Error(err)
|
return ErrorParamInvalid.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.h = cnf.New()
|
c.h = cnf.New()
|
||||||
@@ -99,7 +99,7 @@ func (c *componentHead) Type() string {
|
|||||||
return ComponentType
|
return ComponentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentHead) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper) {
|
func (c *componentHead) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper, sts libcfg.FuncRouteStatus) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ import (
|
|||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
cpttls "github.com/nabbar/golib/config/components/tls"
|
cpttls "github.com/nabbar/golib/config/components/tls"
|
||||||
libsts "github.com/nabbar/golib/status"
|
libsts "github.com/nabbar/golib/status/config"
|
||||||
spfcbr "github.com/spf13/cobra"
|
spfcbr "github.com/spf13/cobra"
|
||||||
spfvbr "github.com/spf13/viper"
|
spfvbr "github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
@@ -27,13 +27,15 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + libcfg.MinErrorComponentHttp
|
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentHttp
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorComponentNotInitialized
|
ErrorComponentNotInitialized
|
||||||
ErrorConfigInvalid
|
ErrorConfigInvalid
|
||||||
ErrorStartComponent
|
ErrorStartComponent
|
||||||
@@ -43,21 +45,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/config/components/http"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorComponentNotInitialized:
|
case ErrorComponentNotInitialized:
|
||||||
return "this component seems to not be correctly initialized"
|
return "this component seems to not be correctly initialized"
|
||||||
@@ -73,5 +71,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "cannot retrieve Logger Component"
|
return "cannot retrieve Logger Component"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -44,6 +44,7 @@ type componentHttp struct {
|
|||||||
ctx libcfg.FuncContext
|
ctx libcfg.FuncContext
|
||||||
get libcfg.FuncComponentGet
|
get libcfg.FuncComponentGet
|
||||||
vpr libcfg.FuncComponentViper
|
vpr libcfg.FuncComponentViper
|
||||||
|
sts libcfg.FuncRouteStatus
|
||||||
key string
|
key string
|
||||||
|
|
||||||
fsa func(cpt libcfg.Component) liberr.Error
|
fsa func(cpt libcfg.Component) liberr.Error
|
||||||
@@ -106,7 +107,7 @@ func (c *componentHttp) _getPoolServerConfig(getCfg libcfg.FuncComponentConfigGe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := getCfg(c.key, &cnf); err != nil {
|
if err := getCfg(c.key, &cnf); err != nil {
|
||||||
return cnf, ErrorParamsInvalid.Error(err)
|
return cnf, ErrorParamInvalid.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if tls, err := c._GetTLS(); err != nil {
|
if tls, err := c._GetTLS(); err != nil {
|
||||||
@@ -189,6 +190,10 @@ func (c *componentHttp) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.Err
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if c.sts != nil {
|
||||||
|
c.pool.StatusRoute(c.key, c.sts())
|
||||||
|
}
|
||||||
|
|
||||||
if err = c.pool.ListenMultiHandler(c.hand); err != nil {
|
if err = c.pool.ListenMultiHandler(c.hand); err != nil {
|
||||||
return ErrorStartComponent.Error(err)
|
return ErrorStartComponent.Error(err)
|
||||||
}
|
}
|
||||||
@@ -218,7 +223,7 @@ func (c *componentHttp) Type() string {
|
|||||||
return ComponentType
|
return ComponentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentHttp) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper) {
|
func (c *componentHttp) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper, sts libcfg.FuncRouteStatus) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
@@ -226,6 +231,7 @@ func (c *componentHttp) Init(key string, ctx libcfg.FuncContext, get libcfg.Func
|
|||||||
c.ctx = ctx
|
c.ctx = ctx
|
||||||
c.get = get
|
c.get = get
|
||||||
c.vpr = vpr
|
c.vpr = vpr
|
||||||
|
c.sts = sts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentHttp) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
|
func (c *componentHttp) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
|
||||||
|
@@ -27,34 +27,32 @@
|
|||||||
package ldap
|
package ldap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + libcfg.MinErrorComponentRequest
|
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentRequest
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorComponentNotInitialized
|
ErrorComponentNotInitialized
|
||||||
ErrorConfigInvalid
|
ErrorConfigInvalid
|
||||||
ErrorDependencyTLSDefault
|
ErrorDependencyTLSDefault
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/config/components/ldap"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorComponentNotInitialized:
|
case ErrorComponentNotInitialized:
|
||||||
return "this component seems to not be correctly initialized"
|
return "this component seems to not be correctly initialized"
|
||||||
@@ -64,5 +62,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "cannot retrieve TLS component"
|
return "cannot retrieve TLS component"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -29,9 +29,8 @@ package ldap
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
lbldap "github.com/nabbar/golib/ldap"
|
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
|
lbldap "github.com/nabbar/golib/ldap"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@@ -39,6 +39,7 @@ type componentLDAP struct {
|
|||||||
ctx libcfg.FuncContext
|
ctx libcfg.FuncContext
|
||||||
get libcfg.FuncComponentGet
|
get libcfg.FuncComponentGet
|
||||||
vpr libcfg.FuncComponentViper
|
vpr libcfg.FuncComponentViper
|
||||||
|
sts libcfg.FuncRouteStatus
|
||||||
key string
|
key string
|
||||||
|
|
||||||
fsa func(cpt libcfg.Component) liberr.Error
|
fsa func(cpt libcfg.Component) liberr.Error
|
||||||
@@ -93,7 +94,7 @@ func (c *componentLDAP) _runCli(ctx context.Context, getCfg libcfg.FuncComponent
|
|||||||
|
|
||||||
cfg := lbldap.Config{}
|
cfg := lbldap.Config{}
|
||||||
if err := getCfg(c.key, &cfg); err != nil {
|
if err := getCfg(c.key, &cfg); err != nil {
|
||||||
return ErrorParamsInvalid.Error(err)
|
return ErrorParamInvalid.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if l, e := lbldap.NewLDAP(ctx, &cfg, nil); e != nil {
|
if l, e := lbldap.NewLDAP(ctx, &cfg, nil); e != nil {
|
||||||
@@ -103,6 +104,12 @@ func (c *componentLDAP) _runCli(ctx context.Context, getCfg libcfg.FuncComponent
|
|||||||
c.c = &cfg
|
c.c = &cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.sts != nil {
|
||||||
|
if s := c.sts(); s != nil {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +131,7 @@ func (c *componentLDAP) Type() string {
|
|||||||
return ComponentType
|
return ComponentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentLDAP) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper) {
|
func (c *componentLDAP) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper, sts libcfg.FuncRouteStatus) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
|
@@ -137,7 +137,7 @@ func (c *componentLog) _GetOptions(getCfg libcfg.FuncComponentConfigGet) (*liblo
|
|||||||
)
|
)
|
||||||
|
|
||||||
if err = getCfg(c.key, &cfg); err != nil {
|
if err = getCfg(c.key, &cfg); err != nil {
|
||||||
return nil, ErrorParamsInvalid.Error(err)
|
return nil, ErrorParamInvalid.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if val := vpr.GetBool(c.key + "disableStandard"); val {
|
if val := vpr.GetBool(c.key + "disableStandard"); val {
|
||||||
|
@@ -27,13 +27,15 @@
|
|||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + libcfg.MinErrorComponentLog
|
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentLog
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorConfigInvalid
|
ErrorConfigInvalid
|
||||||
ErrorComponentNotInitialized
|
ErrorComponentNotInitialized
|
||||||
ErrorStartLog
|
ErrorStartLog
|
||||||
@@ -41,21 +43,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/config/components/log"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorConfigInvalid:
|
case ErrorConfigInvalid:
|
||||||
return "server invalid config"
|
return "server invalid config"
|
||||||
@@ -67,5 +65,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "cannot update Logger with new config"
|
return "cannot update Logger with new config"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -115,7 +115,7 @@ func (c *componentLog) Type() string {
|
|||||||
return ComponentType
|
return ComponentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentLog) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper) {
|
func (c *componentLog) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper, sts libcfg.FuncRouteStatus) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
|
@@ -157,7 +157,7 @@ func (c *componentMail) _getConfig(getCfg libcfg.FuncComponentConfigGet) (libmai
|
|||||||
}
|
}
|
||||||
|
|
||||||
if e := getCfg(c.key, &cfg); e != nil {
|
if e := getCfg(c.key, &cfg); e != nil {
|
||||||
return cfg, ErrorParamsInvalid.Error(e)
|
return cfg, ErrorParamInvalid.Error(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
if val := vpr.GetString(c.key + ".charset"); val != "" {
|
if val := vpr.GetString(c.key + ".charset"); val != "" {
|
||||||
|
@@ -27,13 +27,15 @@
|
|||||||
package mail
|
package mail
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + libcfg.MinErrorComponentMail
|
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentMail
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorComponentNotInitialized
|
ErrorComponentNotInitialized
|
||||||
ErrorConfigInvalid
|
ErrorConfigInvalid
|
||||||
ErrorStartComponent
|
ErrorStartComponent
|
||||||
@@ -43,21 +45,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/config/components/mail"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorComponentNotInitialized:
|
case ErrorComponentNotInitialized:
|
||||||
return "this component seems to not be correctly initialized"
|
return "this component seems to not be correctly initialized"
|
||||||
@@ -73,5 +71,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "cannot retrieve Logger Component"
|
return "cannot retrieve Logger Component"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -115,7 +115,7 @@ func (c *componentMail) Type() string {
|
|||||||
return ComponentType
|
return ComponentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentMail) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper) {
|
func (c *componentMail) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper, sts libcfg.FuncRouteStatus) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
|
@@ -305,7 +305,7 @@ func (c *componentNats) _getConfig(getCfg libcfg.FuncComponentConfigGet) (libnat
|
|||||||
)
|
)
|
||||||
|
|
||||||
if e := getCfg(c.key, &cfg); e != nil {
|
if e := getCfg(c.key, &cfg); e != nil {
|
||||||
return cfg, ErrorParamsInvalid.Error(e)
|
return cfg, ErrorParamInvalid.Error(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = cfg.Validate(); err != nil {
|
if err = cfg.Validate(); err != nil {
|
||||||
|
@@ -27,13 +27,15 @@
|
|||||||
package natsServer
|
package natsServer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + libcfg.MinErrorComponentNats
|
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentNats
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorComponentNotInitialized
|
ErrorComponentNotInitialized
|
||||||
ErrorConfigInvalid
|
ErrorConfigInvalid
|
||||||
ErrorStartComponent
|
ErrorStartComponent
|
||||||
@@ -43,21 +45,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/config/components/natsServer"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorComponentNotInitialized:
|
case ErrorComponentNotInitialized:
|
||||||
return "this component seems to not be correctly initialized"
|
return "this component seems to not be correctly initialized"
|
||||||
@@ -73,5 +71,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "cannot retrieve Logger Component"
|
return "cannot retrieve Logger Component"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -29,11 +29,10 @@ package natsServer
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
libsts "github.com/nabbar/golib/status"
|
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
libnat "github.com/nabbar/golib/nats"
|
libnat "github.com/nabbar/golib/nats"
|
||||||
|
libsts "github.com/nabbar/golib/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@@ -151,7 +151,7 @@ func (c *componentNats) Type() string {
|
|||||||
return ComponentType
|
return ComponentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentNats) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper) {
|
func (c *componentNats) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper, sts libcfg.FuncRouteStatus) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
|
@@ -142,7 +142,7 @@ func (c *componentNutsDB) _getConfig(getCfg libcfg.FuncComponentConfigGet) (libn
|
|||||||
)
|
)
|
||||||
|
|
||||||
if e := getCfg(c.key, &cfg); e != nil {
|
if e := getCfg(c.key, &cfg); e != nil {
|
||||||
return cfg, ErrorParamsInvalid.Error(e)
|
return cfg, ErrorParamInvalid.Error(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = cfg.Validate(); err != nil {
|
if err = cfg.Validate(); err != nil {
|
||||||
|
@@ -27,13 +27,15 @@
|
|||||||
package nutsdb
|
package nutsdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + libcfg.MinErrorComponentNutsDB
|
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentNutsDB
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorComponentNotInitialized
|
ErrorComponentNotInitialized
|
||||||
ErrorConfigInvalid
|
ErrorConfigInvalid
|
||||||
ErrorStartComponent
|
ErrorStartComponent
|
||||||
@@ -42,21 +44,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/config/components/nutsdb"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorComponentNotInitialized:
|
case ErrorComponentNotInitialized:
|
||||||
return "this component seems to not be correctly initialized"
|
return "this component seems to not be correctly initialized"
|
||||||
@@ -70,5 +68,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "cannot retrieve default Logger"
|
return "cannot retrieve default Logger"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -30,13 +30,11 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
libsts "github.com/nabbar/golib/status"
|
|
||||||
|
|
||||||
cptlog "github.com/nabbar/golib/config/components/log"
|
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
|
cptlog "github.com/nabbar/golib/config/components/log"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
libndb "github.com/nabbar/golib/nutsdb"
|
libndb "github.com/nabbar/golib/nutsdb"
|
||||||
|
libsts "github.com/nabbar/golib/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@@ -153,7 +153,7 @@ func (c *componentNutsDB) Type() string {
|
|||||||
return ComponentType
|
return ComponentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentNutsDB) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper) {
|
func (c *componentNutsDB) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper, sts libcfg.FuncRouteStatus) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ import (
|
|||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
cmptls "github.com/nabbar/golib/config/components/tls"
|
cmptls "github.com/nabbar/golib/config/components/tls"
|
||||||
libsts "github.com/nabbar/golib/status"
|
libsts "github.com/nabbar/golib/status/config"
|
||||||
spfcbr "github.com/spf13/cobra"
|
spfcbr "github.com/spf13/cobra"
|
||||||
spfvbr "github.com/spf13/viper"
|
spfvbr "github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
@@ -27,34 +27,32 @@
|
|||||||
package request
|
package request
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + libcfg.MinErrorComponentRequest
|
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentRequest
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorComponentNotInitialized
|
ErrorComponentNotInitialized
|
||||||
ErrorConfigInvalid
|
ErrorConfigInvalid
|
||||||
ErrorDependencyTLSDefault
|
ErrorDependencyTLSDefault
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/config/components/request"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorComponentNotInitialized:
|
case ErrorComponentNotInitialized:
|
||||||
return "this component seems to not be correctly initialized"
|
return "this component seems to not be correctly initialized"
|
||||||
@@ -64,5 +62,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "cannot retrieve TLS component"
|
return "cannot retrieve TLS component"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,7 @@ type componentRequest struct {
|
|||||||
ctx libcfg.FuncContext
|
ctx libcfg.FuncContext
|
||||||
get libcfg.FuncComponentGet
|
get libcfg.FuncComponentGet
|
||||||
vpr libcfg.FuncComponentViper
|
vpr libcfg.FuncComponentViper
|
||||||
|
sts libcfg.FuncRouteStatus
|
||||||
key string
|
key string
|
||||||
|
|
||||||
fsa func(cpt libcfg.Component) liberr.Error
|
fsa func(cpt libcfg.Component) liberr.Error
|
||||||
@@ -112,7 +113,7 @@ func (c *componentRequest) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.
|
|||||||
cfg.SetDefaultTLS(c._GetTLS)
|
cfg.SetDefaultTLS(c._GetTLS)
|
||||||
|
|
||||||
if err := getCfg(c.key, &cfg); err != nil {
|
if err := getCfg(c.key, &cfg); err != nil {
|
||||||
return ErrorParamsInvalid.Error(err)
|
return ErrorParamInvalid.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.r == nil {
|
if c.r == nil {
|
||||||
@@ -129,6 +130,12 @@ func (c *componentRequest) _runCli(getCfg libcfg.FuncComponentConfigGet) liberr.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.sts != nil {
|
||||||
|
if s := c.sts(); s != nil {
|
||||||
|
c.r.StatusRegister(s, c.key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +157,7 @@ func (c *componentRequest) Type() string {
|
|||||||
return ComponentType
|
return ComponentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentRequest) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper) {
|
func (c *componentRequest) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper, sts libcfg.FuncRouteStatus) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
@@ -158,6 +165,7 @@ func (c *componentRequest) Init(key string, ctx libcfg.FuncContext, get libcfg.F
|
|||||||
c.ctx = ctx
|
c.ctx = ctx
|
||||||
c.get = get
|
c.get = get
|
||||||
c.vpr = vpr
|
c.vpr = vpr
|
||||||
|
c.sts = sts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentRequest) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
|
func (c *componentRequest) RegisterFuncStart(before, after func(cpt libcfg.Component) liberr.Error) {
|
||||||
|
@@ -35,7 +35,7 @@ import (
|
|||||||
cpttls "github.com/nabbar/golib/config/components/tls"
|
cpttls "github.com/nabbar/golib/config/components/tls"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
libsmtp "github.com/nabbar/golib/smtp"
|
libsmtp "github.com/nabbar/golib/smtp"
|
||||||
libsts "github.com/nabbar/golib/status"
|
libsts "github.com/nabbar/golib/status/config"
|
||||||
spfcbr "github.com/spf13/cobra"
|
spfcbr "github.com/spf13/cobra"
|
||||||
spfvbr "github.com/spf13/viper"
|
spfvbr "github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@@ -81,7 +81,7 @@ func (c *componentSmtp) _getConfig(getCfg libcfg.FuncComponentConfigGet) (libsmt
|
|||||||
)
|
)
|
||||||
|
|
||||||
if e := getCfg(c.key, &cfg); e != nil {
|
if e := getCfg(c.key, &cfg); e != nil {
|
||||||
return cfg, ErrorParamsInvalid.Error(e)
|
return cfg, ErrorParamInvalid.Error(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
if val := vpr.GetString(c.key + "dsn"); val != "" {
|
if val := vpr.GetString(c.key + "dsn"); val != "" {
|
||||||
|
@@ -27,13 +27,15 @@
|
|||||||
package smtp
|
package smtp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + libcfg.MinErrorComponentSmtp
|
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentSmtp
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorComponentNotInitialized
|
ErrorComponentNotInitialized
|
||||||
ErrorConfigInvalid
|
ErrorConfigInvalid
|
||||||
ErrorStartComponent
|
ErrorStartComponent
|
||||||
@@ -43,21 +45,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/config/components/smtp"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorComponentNotInitialized:
|
case ErrorComponentNotInitialized:
|
||||||
return "this component seems to not be correctly initialized"
|
return "this component seems to not be correctly initialized"
|
||||||
@@ -73,5 +71,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "cannot retrieve Logger Component"
|
return "cannot retrieve Logger Component"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -29,13 +29,11 @@ package smtp
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
libsts "github.com/nabbar/golib/status"
|
|
||||||
|
|
||||||
cpttls "github.com/nabbar/golib/config/components/tls"
|
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
|
cpttls "github.com/nabbar/golib/config/components/tls"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
libsmtp "github.com/nabbar/golib/smtp"
|
libsmtp "github.com/nabbar/golib/smtp"
|
||||||
|
libsts "github.com/nabbar/golib/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@@ -141,7 +141,7 @@ func (c *componentSmtp) Type() string {
|
|||||||
return ComponentType
|
return ComponentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentSmtp) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper) {
|
func (c *componentSmtp) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper, sts libcfg.FuncRouteStatus) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
|
@@ -119,7 +119,7 @@ func (c *componentTls) _getConfig(getCfg libcfg.FuncComponentConfigGet) (*libtls
|
|||||||
cfg := libtls.Config{}
|
cfg := libtls.Config{}
|
||||||
|
|
||||||
if err := getCfg(c.key, &cfg); err != nil {
|
if err := getCfg(c.key, &cfg); err != nil {
|
||||||
return nil, ErrorParamsInvalid.Error(err)
|
return nil, ErrorParamInvalid.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cfg.Validate(); err != nil {
|
if err := cfg.Validate(); err != nil {
|
||||||
|
@@ -27,13 +27,15 @@
|
|||||||
package tls
|
package tls
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + libcfg.MinErrorComponentTls
|
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentTls
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorComponentNotInitialized
|
ErrorComponentNotInitialized
|
||||||
ErrorConfigInvalid
|
ErrorConfigInvalid
|
||||||
ErrorComponentStart
|
ErrorComponentStart
|
||||||
@@ -41,21 +43,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/config/components/tls"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorComponentNotInitialized:
|
case ErrorComponentNotInitialized:
|
||||||
return "this component seems to not be correctly initialized"
|
return "this component seems to not be correctly initialized"
|
||||||
@@ -67,5 +65,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "cannot update database connection with new config"
|
return "cannot update database connection with new config"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -112,7 +112,7 @@ func (c *componentTls) Type() string {
|
|||||||
return ComponentType
|
return ComponentType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentTls) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper) {
|
func (c *componentTls) Init(key string, ctx libcfg.FuncContext, get libcfg.FuncComponentGet, vpr libcfg.FuncComponentViper, sts libcfg.FuncRouteStatus) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
|
@@ -35,10 +35,11 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
spfcbr "github.com/spf13/cobra"
|
"golang.org/x/exp/slices"
|
||||||
spfvpr "github.com/spf13/viper"
|
|
||||||
|
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
spfcbr "github.com/spf13/cobra"
|
||||||
|
spfvpr "github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
const JSONIndent = " "
|
const JSONIndent = " "
|
||||||
@@ -280,7 +281,7 @@ func (c *componentList) reloadOne(isReload []string, key string, getCfg FuncComp
|
|||||||
return isReload, ErrorComponentNotFound.ErrorParent(fmt.Errorf("component: %s", key))
|
return isReload, ErrorComponentNotFound.ErrorParent(fmt.Errorf("component: %s", key))
|
||||||
} else if cpt = c.ComponentGet(key); cpt == nil {
|
} else if cpt = c.ComponentGet(key); cpt == nil {
|
||||||
return isReload, ErrorComponentNotFound.ErrorParent(fmt.Errorf("component: %s", key))
|
return isReload, ErrorComponentNotFound.ErrorParent(fmt.Errorf("component: %s", key))
|
||||||
} else if stringIsInSlice(isReload, key) {
|
} else if slices.Contains(isReload, key) {
|
||||||
return isReload, nil
|
return isReload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,12 +371,18 @@ func (c *componentList) DefaultConfig() io.Reader {
|
|||||||
buffer.WriteString("\n")
|
buffer.WriteString("\n")
|
||||||
buffer.WriteString("}")
|
buffer.WriteString("}")
|
||||||
|
|
||||||
var res = bytes.NewBuffer(make([]byte, 0))
|
var (
|
||||||
if err := json.Indent(res, buffer.Bytes(), "", JSONIndent); err != nil {
|
cmp = bytes.NewBuffer(make([]byte, 0))
|
||||||
|
ind = bytes.NewBuffer(make([]byte, 0))
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := json.Compact(cmp, buffer.Bytes()); err != nil {
|
||||||
|
return buffer
|
||||||
|
} else if err = json.Indent(ind, cmp.Bytes(), "", JSONIndent); err != nil {
|
||||||
return buffer
|
return buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return ind
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *componentList) RegisterFlag(Command *spfcbr.Command, Viper *spfvpr.Viper) error {
|
func (c *componentList) RegisterFlag(Command *spfcbr.Command, Viper *spfvpr.Viper) error {
|
||||||
|
@@ -26,10 +26,14 @@
|
|||||||
|
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgConfig
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgConfig
|
||||||
ErrorConfigMissingViper
|
ErrorConfigMissingViper
|
||||||
ErrorComponentNotFound
|
ErrorComponentNotFound
|
||||||
ErrorComponentFlagError
|
ErrorComponentFlagError
|
||||||
@@ -40,7 +44,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MinErrorComponentAws = ErrorParamsEmpty + 10
|
MinErrorComponentAws = ErrorParamEmpty + 10
|
||||||
MinErrorComponentDatabase = MinErrorComponentAws + 10
|
MinErrorComponentDatabase = MinErrorComponentAws + 10
|
||||||
MinErrorComponentHead = MinErrorComponentDatabase + 10
|
MinErrorComponentHead = MinErrorComponentDatabase + 10
|
||||||
MinErrorComponentHttp = MinErrorComponentHead + 10
|
MinErrorComponentHttp = MinErrorComponentHead + 10
|
||||||
@@ -53,22 +57,18 @@ const (
|
|||||||
MinErrorComponentTls = MinErrorComponentSmtp + 10
|
MinErrorComponentTls = MinErrorComponentSmtp + 10
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/config"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case liberr.UNK_ERROR:
|
||||||
return ""
|
return ""
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorConfigMissingViper:
|
case ErrorConfigMissingViper:
|
||||||
return "missing valid viper function"
|
return "missing valid viper function"
|
||||||
@@ -86,5 +86,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "cannot reload at least one component"
|
return "cannot reload at least one component"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -33,14 +33,15 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
spfvpr "github.com/spf13/viper"
|
|
||||||
|
|
||||||
libctx "github.com/nabbar/golib/context"
|
libctx "github.com/nabbar/golib/context"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
libsts "github.com/nabbar/golib/status"
|
||||||
libvpr "github.com/nabbar/golib/viper"
|
libvpr "github.com/nabbar/golib/viper"
|
||||||
|
spfvpr "github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FuncContext func() context.Context
|
type FuncContext func() context.Context
|
||||||
|
type FuncRouteStatus func() libsts.RouteStatus
|
||||||
type FuncComponentGet func(key string) Component
|
type FuncComponentGet func(key string) Component
|
||||||
type FuncComponentViper func() *spfvpr.Viper
|
type FuncComponentViper func() *spfvpr.Viper
|
||||||
type FuncComponentConfigGet func(key string, model interface{}) liberr.Error
|
type FuncComponentConfigGet func(key string, model interface{}) liberr.Error
|
||||||
@@ -74,8 +75,14 @@ type Config interface {
|
|||||||
// Section Event : github.com/nabbar/golib/config
|
// Section Event : github.com/nabbar/golib/config
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// RegisterFuncViper is used to expose golib Viper instance to all config component.
|
||||||
|
// With this function, the component can load his own config part and start or reload.
|
||||||
RegisterFuncViper(fct func() libvpr.Viper)
|
RegisterFuncViper(fct func() libvpr.Viper)
|
||||||
|
|
||||||
|
// RegisterFuncRouteStatus is used to expose golib Status Router instance to all config component.
|
||||||
|
// With this function, the component can register component status for router status and expose his own health.
|
||||||
|
RegisterFuncRouteStatus(fct FuncRouteStatus)
|
||||||
|
|
||||||
// Start will trigger the start function of all registered component.
|
// Start will trigger the start function of all registered component.
|
||||||
// If any component return an error, this func will stop the start
|
// If any component return an error, this func will stop the start
|
||||||
// process and return the error.
|
// process and return the error.
|
||||||
|
@@ -29,16 +29,15 @@ package config
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
libctx "github.com/nabbar/golib/context"
|
libctx "github.com/nabbar/golib/context"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
libvpr "github.com/nabbar/golib/viper"
|
libvpr "github.com/nabbar/golib/viper"
|
||||||
spfcbr "github.com/spf13/cobra"
|
spfcbr "github.com/spf13/cobra"
|
||||||
spfvpr "github.com/spf13/viper"
|
spfvpr "github.com/spf13/viper"
|
||||||
|
|
||||||
"io"
|
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type configModel struct {
|
type configModel struct {
|
||||||
@@ -49,6 +48,7 @@ type configModel struct {
|
|||||||
|
|
||||||
cpt ComponentList
|
cpt ComponentList
|
||||||
|
|
||||||
|
fctGolibStatus FuncRouteStatus
|
||||||
fctGolibViper func() libvpr.Viper
|
fctGolibViper func() libvpr.Viper
|
||||||
fctStartBefore func() liberr.Error
|
fctStartBefore func() liberr.Error
|
||||||
fctStartAfter func() liberr.Error
|
fctStartAfter func() liberr.Error
|
||||||
@@ -123,6 +123,10 @@ func (c *configModel) RegisterFuncViper(fct func() libvpr.Viper) {
|
|||||||
c.fctGolibViper = fct
|
c.fctGolibViper = fct
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *configModel) RegisterFuncRouteStatus(fct FuncRouteStatus) {
|
||||||
|
c.fctGolibStatus = fct
|
||||||
|
}
|
||||||
|
|
||||||
func (c *configModel) Start() liberr.Error {
|
func (c *configModel) Start() liberr.Error {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
@@ -250,7 +254,7 @@ func (c *configModel) ComponentDel(key string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *configModel) ComponentSet(key string, cpt Component) {
|
func (c *configModel) ComponentSet(key string, cpt Component) {
|
||||||
cpt.Init(key, c.Context, c.ComponentGet, func() *spfvpr.Viper {
|
fv := func() *spfvpr.Viper {
|
||||||
if c.fctGolibViper == nil {
|
if c.fctGolibViper == nil {
|
||||||
return nil
|
return nil
|
||||||
} else if vpr := c.fctGolibViper(); vpr == nil {
|
} else if vpr := c.fctGolibViper(); vpr == nil {
|
||||||
@@ -258,8 +262,9 @@ func (c *configModel) ComponentSet(key string, cpt Component) {
|
|||||||
} else {
|
} else {
|
||||||
return vpr.Viper()
|
return vpr.Viper()
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
cpt.Init(key, c.Context, c.ComponentGet, fv, c.fctGolibStatus)
|
||||||
c.cpt.ComponentSet(key, cpt)
|
c.cpt.ComponentSet(key, cpt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,31 +26,29 @@
|
|||||||
|
|
||||||
package console
|
package console
|
||||||
|
|
||||||
import "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgConsole
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgConsole
|
||||||
ErrorColorIOFprintf
|
ErrorColorIOFprintf
|
||||||
ErrorColorBufWrite
|
ErrorColorBufWrite
|
||||||
ErrorColorBufUndefined
|
ErrorColorBufUndefined
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/console"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case ErrorParamEmpty:
|
||||||
return ""
|
|
||||||
case ErrorParamsEmpty:
|
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorColorIOFprintf:
|
case ErrorColorIOFprintf:
|
||||||
return "cannot write on IO"
|
return "cannot write on IO"
|
||||||
@@ -60,5 +58,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "buffer is not defined"
|
return "buffer is not defined"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
libsts "github.com/nabbar/golib/status"
|
libsts "github.com/nabbar/golib/status/config"
|
||||||
|
|
||||||
libval "github.com/go-playground/validator/v10"
|
libval "github.com/go-playground/validator/v10"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
@@ -40,8 +40,11 @@ type Message func(code CodeError) (message string)
|
|||||||
type CodeError uint16
|
type CodeError uint16
|
||||||
|
|
||||||
const UNK_ERROR CodeError = 0
|
const UNK_ERROR CodeError = 0
|
||||||
|
const UnknownError CodeError = 0
|
||||||
const UNK_MESSAGE = "unknown error"
|
const UNK_MESSAGE = "unknown error"
|
||||||
|
const UnknownMessage = "unknown error"
|
||||||
const NUL_MESSAGE = ""
|
const NUL_MESSAGE = ""
|
||||||
|
const NullMessage = ""
|
||||||
|
|
||||||
func (c CodeError) GetUint16() uint16 {
|
func (c CodeError) GetUint16() uint16 {
|
||||||
return uint16(c)
|
return uint16(c)
|
||||||
@@ -56,8 +59,8 @@ func (c CodeError) GetString() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c CodeError) GetMessage() string {
|
func (c CodeError) GetMessage() string {
|
||||||
if c == UNK_ERROR {
|
if c == UnknownError {
|
||||||
return UNK_MESSAGE
|
return UnknownMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
if f, ok := idMsgFct[findCodeErrorInMapMessage(c)]; ok {
|
if f, ok := idMsgFct[findCodeErrorInMapMessage(c)]; ok {
|
||||||
@@ -66,7 +69,7 @@ func (c CodeError) GetMessage() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return UNK_MESSAGE
|
return UnknownMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c CodeError) Error(p Error) Error {
|
func (c CodeError) Error(p Error) Error {
|
||||||
@@ -125,7 +128,7 @@ func RegisterIdFctMessage(minCode CodeError, fct Message) {
|
|||||||
|
|
||||||
func ExistInMapMessage(code CodeError) bool {
|
func ExistInMapMessage(code CodeError) bool {
|
||||||
if f, ok := idMsgFct[findCodeErrorInMapMessage(code)]; ok {
|
if f, ok := idMsgFct[findCodeErrorInMapMessage(code)]; ok {
|
||||||
if m := f(code); m != NUL_MESSAGE {
|
if m := f(code); m != NullMessage {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
103
go.mod
103
go.mod
@@ -1,58 +1,59 @@
|
|||||||
module github.com/nabbar/golib
|
module github.com/nabbar/golib
|
||||||
|
|
||||||
go 1.18
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/aws/aws-sdk-go-v2 v1.16.8
|
github.com/aws/aws-sdk-go-v2 v1.16.14
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.15.15
|
github.com/aws/aws-sdk-go-v2/config v1.17.5
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.12.10
|
github.com/aws/aws-sdk-go-v2/credentials v1.12.18
|
||||||
github.com/aws/aws-sdk-go-v2/service/iam v1.18.10
|
github.com/aws/aws-sdk-go-v2/service/iam v1.18.17
|
||||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.2
|
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.9
|
||||||
github.com/bits-and-blooms/bitset v1.3.0
|
github.com/bits-and-blooms/bitset v1.3.2
|
||||||
github.com/c-bata/go-prompt v0.2.6
|
github.com/c-bata/go-prompt v0.2.6
|
||||||
github.com/fatih/color v1.13.0
|
github.com/fatih/color v1.13.0
|
||||||
github.com/fsnotify/fsnotify v1.5.4
|
github.com/fsnotify/fsnotify v1.5.4
|
||||||
github.com/fxamacker/cbor/v2 v2.4.0
|
github.com/fxamacker/cbor/v2 v2.4.0
|
||||||
github.com/gin-gonic/gin v1.8.1
|
github.com/gin-gonic/gin v1.8.1
|
||||||
github.com/go-ldap/ldap/v3 v3.4.4
|
github.com/go-ldap/ldap/v3 v3.4.4
|
||||||
github.com/go-playground/validator/v10 v10.10.0
|
github.com/go-playground/validator/v10 v10.11.0
|
||||||
github.com/google/go-github/v33 v33.0.0
|
github.com/google/go-github/v33 v33.0.0
|
||||||
github.com/hashicorp/go-hclog v1.2.2
|
github.com/hashicorp/go-hclog v1.3.0
|
||||||
github.com/hashicorp/go-retryablehttp v0.7.1
|
github.com/hashicorp/go-retryablehttp v0.7.1
|
||||||
github.com/hashicorp/go-uuid v1.0.3
|
github.com/hashicorp/go-uuid v1.0.3
|
||||||
github.com/hashicorp/go-version v1.6.0
|
github.com/hashicorp/go-version v1.6.0
|
||||||
github.com/jlaffaye/ftp v0.0.0-20220630165035-11536801d1ff
|
github.com/jlaffaye/ftp v0.1.0
|
||||||
github.com/lni/dragonboat/v3 v3.3.5
|
github.com/lni/dragonboat/v3 v3.3.5
|
||||||
github.com/matcornic/hermes/v2 v2.1.0
|
github.com/matcornic/hermes/v2 v2.1.0
|
||||||
github.com/mattn/go-colorable v0.1.12
|
github.com/mattn/go-colorable v0.1.13
|
||||||
github.com/mitchellh/go-homedir v1.1.0
|
github.com/mitchellh/go-homedir v1.1.0
|
||||||
github.com/nats-io/jwt/v2 v2.3.0
|
github.com/nats-io/jwt/v2 v2.3.0
|
||||||
github.com/nats-io/nats-server/v2 v2.8.4
|
github.com/nats-io/nats-server/v2 v2.9.0
|
||||||
github.com/nats-io/nats.go v1.16.0
|
github.com/nats-io/nats.go v1.16.1-0.20220906180156-a1017eec10b0
|
||||||
github.com/onsi/ginkgo/v2 v2.1.4
|
github.com/onsi/ginkgo/v2 v2.1.6
|
||||||
github.com/onsi/gomega v1.20.0
|
github.com/onsi/gomega v1.20.2
|
||||||
github.com/pelletier/go-toml v1.9.5
|
github.com/pelletier/go-toml v1.9.5
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/prometheus/client_golang v1.12.2
|
github.com/prometheus/client_golang v1.13.0
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible
|
github.com/shirou/gopsutil v3.21.11+incompatible
|
||||||
github.com/sirupsen/logrus v1.9.0
|
github.com/sirupsen/logrus v1.9.0
|
||||||
github.com/spf13/cobra v1.5.0
|
github.com/spf13/cobra v1.5.0
|
||||||
github.com/spf13/jwalterweatherman v1.1.0
|
github.com/spf13/jwalterweatherman v1.1.0
|
||||||
github.com/spf13/viper v1.12.0
|
github.com/spf13/viper v1.13.0
|
||||||
github.com/vbauerster/mpb/v5 v5.4.0
|
github.com/vbauerster/mpb/v5 v5.4.0
|
||||||
github.com/xanzy/go-gitlab v0.70.0
|
github.com/xanzy/go-gitlab v0.73.1
|
||||||
github.com/xhit/go-simple-mail v2.2.2+incompatible
|
github.com/xhit/go-simple-mail v2.2.2+incompatible
|
||||||
github.com/xujiajun/nutsdb v0.9.0
|
github.com/xujiajun/nutsdb v0.10.0
|
||||||
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b
|
github.com/xujiajun/utils v0.0.0-20220904132955-5f7c5b914235
|
||||||
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e
|
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561
|
||||||
golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c
|
golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
|
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8
|
golang.org/x/sync v0.0.0-20220907140024-f12130a52804
|
||||||
|
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
gorm.io/driver/clickhouse v0.4.2
|
gorm.io/driver/clickhouse v0.4.2
|
||||||
gorm.io/driver/mysql v1.3.5
|
gorm.io/driver/mysql v1.3.6
|
||||||
gorm.io/driver/postgres v1.3.8
|
gorm.io/driver/postgres v1.3.9
|
||||||
gorm.io/driver/sqlite v1.3.6
|
gorm.io/driver/sqlite v1.3.6
|
||||||
gorm.io/driver/sqlserver v1.3.2
|
gorm.io/driver/sqlserver v1.3.2
|
||||||
gorm.io/gorm v1.23.8
|
gorm.io/gorm v1.23.8
|
||||||
@@ -70,19 +71,20 @@ require (
|
|||||||
github.com/andybalholm/cascadia v1.0.0 // indirect
|
github.com/andybalholm/cascadia v1.0.0 // indirect
|
||||||
github.com/aokoli/goutils v1.0.1 // indirect
|
github.com/aokoli/goutils v1.0.1 // indirect
|
||||||
github.com/armon/go-metrics v0.3.10 // indirect
|
github.com/armon/go-metrics v0.3.10 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.3 // indirect
|
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.7 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.9 // indirect
|
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.15 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.15 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.21 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.9 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.15 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.16 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.22 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.6 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.12 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.3 // indirect
|
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.8 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.10 // indirect
|
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.16 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.9 // indirect
|
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.15 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.9 // indirect
|
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.15 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/sso v1.11.13 // indirect
|
github.com/aws/aws-sdk-go-v2/service/sso v1.11.21 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/sts v1.16.10 // indirect
|
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.3 // indirect
|
||||||
github.com/aws/smithy-go v1.12.0 // indirect
|
github.com/aws/aws-sdk-go-v2/service/sts v1.16.17 // indirect
|
||||||
|
github.com/aws/smithy-go v1.13.2 // indirect
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/bwmarrin/snowflake v0.3.0 // indirect
|
github.com/bwmarrin/snowflake v0.3.0 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||||
@@ -98,7 +100,7 @@ require (
|
|||||||
github.com/go-playground/locales v0.14.0 // indirect
|
github.com/go-playground/locales v0.14.0 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||||
github.com/goccy/go-json v0.9.7 // indirect
|
github.com/goccy/go-json v0.9.11 // indirect
|
||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
|
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
|
||||||
github.com/golang-sql/sqlexp v0.0.0-20170517235910-f1bb20e5a188 // indirect
|
github.com/golang-sql/sqlexp v0.0.0-20170517235910-f1bb20e5a188 // indirect
|
||||||
@@ -134,13 +136,13 @@ require (
|
|||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/juju/ratelimit v1.0.2-0.20191002062651-f60b32039441 // indirect
|
github.com/juju/ratelimit v1.0.2-0.20191002062651-f60b32039441 // indirect
|
||||||
github.com/klauspost/compress v1.14.4 // indirect
|
github.com/klauspost/compress v1.15.9 // indirect
|
||||||
github.com/kr/pretty v0.3.0 // indirect
|
github.com/kr/pretty v0.3.0 // indirect
|
||||||
github.com/kr/text v0.2.0 // indirect
|
github.com/kr/text v0.2.0 // indirect
|
||||||
github.com/leodido/go-urn v1.2.1 // indirect
|
github.com/leodido/go-urn v1.2.1 // indirect
|
||||||
github.com/lni/goutils v1.3.0 // indirect
|
github.com/lni/goutils v1.3.0 // indirect
|
||||||
github.com/magiconair/properties v1.8.6 // indirect
|
github.com/magiconair/properties v1.8.6 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.9 // indirect
|
github.com/mattn/go-runewidth v0.0.9 // indirect
|
||||||
github.com/mattn/go-sqlite3 v1.14.12 // indirect
|
github.com/mattn/go-sqlite3 v1.14.12 // indirect
|
||||||
github.com/mattn/go-tty v0.0.3 // indirect
|
github.com/mattn/go-tty v0.0.3 // indirect
|
||||||
@@ -154,12 +156,12 @@ require (
|
|||||||
github.com/nats-io/nuid v1.0.1 // indirect
|
github.com/nats-io/nuid v1.0.1 // indirect
|
||||||
github.com/olekukonko/tablewriter v0.0.1 // indirect
|
github.com/olekukonko/tablewriter v0.0.1 // indirect
|
||||||
github.com/paulmach/orb v0.7.1 // indirect
|
github.com/paulmach/orb v0.7.1 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
|
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
|
||||||
github.com/pierrec/lz4/v4 v4.1.15 // indirect
|
github.com/pierrec/lz4/v4 v4.1.15 // indirect
|
||||||
github.com/pkg/term v1.2.0-beta.2 // indirect
|
github.com/pkg/term v1.2.0-beta.2 // indirect
|
||||||
github.com/prometheus/client_model v0.2.0 // indirect
|
github.com/prometheus/client_model v0.2.0 // indirect
|
||||||
github.com/prometheus/common v0.32.1 // indirect
|
github.com/prometheus/common v0.37.0 // indirect
|
||||||
github.com/prometheus/procfs v0.7.3 // indirect
|
github.com/prometheus/procfs v0.8.0 // indirect
|
||||||
github.com/rogpeppe/go-internal v1.8.0 // indirect
|
github.com/rogpeppe/go-internal v1.8.0 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
|
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
|
||||||
@@ -168,7 +170,7 @@ require (
|
|||||||
github.com/spf13/cast v1.5.0 // indirect
|
github.com/spf13/cast v1.5.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
|
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
|
||||||
github.com/subosito/gotenv v1.3.0 // indirect
|
github.com/subosito/gotenv v1.4.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.7 // indirect
|
github.com/ugorji/go/codec v1.2.7 // indirect
|
||||||
github.com/valyala/fastrand v1.0.0 // indirect
|
github.com/valyala/fastrand v1.0.0 // indirect
|
||||||
github.com/valyala/histogram v1.0.1 // indirect
|
github.com/valyala/histogram v1.0.1 // indirect
|
||||||
@@ -179,12 +181,11 @@ require (
|
|||||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||||
go.opentelemetry.io/otel v1.7.0 // indirect
|
go.opentelemetry.io/otel v1.7.0 // indirect
|
||||||
go.opentelemetry.io/otel/trace v1.7.0 // indirect
|
go.opentelemetry.io/otel/trace v1.7.0 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
|
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
|
||||||
golang.org/x/exp v0.0.0-20200513190911-00229845015e // indirect
|
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/text v0.3.7 // indirect
|
||||||
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
|
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
|
||||||
google.golang.org/appengine v1.6.7 // indirect
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
google.golang.org/protobuf v1.28.0 // indirect
|
google.golang.org/protobuf v1.28.1 // indirect
|
||||||
gopkg.in/ini.v1 v1.66.4 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
)
|
)
|
||||||
|
@@ -27,32 +27,30 @@
|
|||||||
package httpcli
|
package httpcli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + liberr.MinPkgHttpCli
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgHttpCli
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorValidatorError
|
ErrorValidatorError
|
||||||
ErrorClientTransportHttp2
|
ErrorClientTransportHttp2
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/httpcli"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorValidatorError:
|
case ErrorValidatorError:
|
||||||
return "config seems to be invalid"
|
return "config seems to be invalid"
|
||||||
@@ -60,5 +58,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "error while configure http2 transport for client"
|
return "error while configure http2 transport for client"
|
||||||
}
|
}
|
||||||
|
|
||||||
return liberr.NUL_MESSAGE
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -34,10 +34,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
libsts "github.com/nabbar/golib/status/config"
|
||||||
|
|
||||||
libval "github.com/go-playground/validator/v10"
|
libval "github.com/go-playground/validator/v10"
|
||||||
libtls "github.com/nabbar/golib/certificates"
|
libtls "github.com/nabbar/golib/certificates"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
libsts "github.com/nabbar/golib/status"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MapUpdPoolServerConfig func(cfg ServerConfig) ServerConfig
|
type MapUpdPoolServerConfig func(cfg ServerConfig) ServerConfig
|
||||||
|
@@ -26,10 +26,14 @@
|
|||||||
|
|
||||||
package httpserver
|
package httpserver
|
||||||
|
|
||||||
import "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgHttpServer
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgHttpServer
|
||||||
ErrorHTTP2Configure
|
ErrorHTTP2Configure
|
||||||
ErrorPoolAdd
|
ErrorPoolAdd
|
||||||
ErrorPoolValidate
|
ErrorPoolValidate
|
||||||
@@ -40,22 +44,16 @@ const (
|
|||||||
ErrorServerOffline
|
ErrorServerOffline
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/httpserver"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case ErrorParamEmpty:
|
||||||
return ""
|
|
||||||
case ErrorParamsEmpty:
|
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorHTTP2Configure:
|
case ErrorHTTP2Configure:
|
||||||
return "cannot initialize http2 over http server"
|
return "cannot initialize http2 over http server"
|
||||||
@@ -75,5 +73,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "server offline"
|
return "server offline"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,8 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/nabbar/golib/status/config"
|
||||||
|
|
||||||
liblog "github.com/nabbar/golib/logger"
|
liblog "github.com/nabbar/golib/logger"
|
||||||
|
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
@@ -253,7 +255,7 @@ func (s *server) StatusHealth() error {
|
|||||||
|
|
||||||
func (s *server) StatusComponent() libsts.Component {
|
func (s *server) StatusComponent() libsts.Component {
|
||||||
if cfg := s.GetConfig(); cfg == nil {
|
if cfg := s.GetConfig(); cfg == nil {
|
||||||
cnf := libsts.ConfigStatus{
|
cnf := config.ConfigStatus{
|
||||||
Mandatory: true,
|
Mandatory: true,
|
||||||
MessageOK: "",
|
MessageOK: "",
|
||||||
MessageKO: "",
|
MessageKO: "",
|
||||||
|
@@ -26,10 +26,14 @@
|
|||||||
|
|
||||||
package ioutils
|
package ioutils
|
||||||
|
|
||||||
import "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgIOUtils
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgIOUtils
|
||||||
ErrorSyscallRLimitGet
|
ErrorSyscallRLimitGet
|
||||||
ErrorSyscallRLimitSet
|
ErrorSyscallRLimitSet
|
||||||
ErrorIOFileStat
|
ErrorIOFileStat
|
||||||
@@ -41,22 +45,16 @@ const (
|
|||||||
ErrorNilPointer
|
ErrorNilPointer
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/ioutils"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case ErrorParamEmpty:
|
||||||
return ""
|
|
||||||
case ErrorParamsEmpty:
|
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorSyscallRLimitGet:
|
case ErrorSyscallRLimitGet:
|
||||||
return "error on retrieve value in syscall rlimit"
|
return "error on retrieve value in syscall rlimit"
|
||||||
@@ -78,5 +76,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "cannot call function for a nil pointer"
|
return "cannot call function for a nil pointer"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -26,10 +26,14 @@
|
|||||||
|
|
||||||
package ldap
|
package ldap
|
||||||
|
|
||||||
import "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorEmptyParams errors.CodeError = iota + errors.MinPkgLDAP
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgLDAP
|
||||||
ErrorLDAPContext
|
ErrorLDAPContext
|
||||||
ErrorLDAPServerConfig
|
ErrorLDAPServerConfig
|
||||||
ErrorLDAPServerConnection
|
ErrorLDAPServerConnection
|
||||||
@@ -49,21 +53,16 @@ const (
|
|||||||
ErrorLDAPGroupNotFound
|
ErrorLDAPGroupNotFound
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = errors.ExistInMapMessage(ErrorEmptyParams)
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
errors.RegisterIdFctMessage(ErrorEmptyParams, getMessage)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
|
panic(fmt.Errorf("error code collision with package golib/ldap"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case ErrorParamEmpty:
|
||||||
return ""
|
|
||||||
case ErrorEmptyParams:
|
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorLDAPContext:
|
case ErrorLDAPContext:
|
||||||
return "LDAP server connection context occurs an error"
|
return "LDAP server connection context occurs an error"
|
||||||
@@ -101,5 +100,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "group not found"
|
return "group not found"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
14
ldap/ldap.go
14
ldap/ldap.go
@@ -57,7 +57,7 @@ type HelperLDAP struct {
|
|||||||
// NewLDAP build a new LDAP helper based on config struct given.
|
// NewLDAP build a new LDAP helper based on config struct given.
|
||||||
func NewLDAP(ctx context.Context, cnf *Config, attributes []string) (*HelperLDAP, liberr.Error) {
|
func NewLDAP(ctx context.Context, cnf *Config, attributes []string) (*HelperLDAP, liberr.Error) {
|
||||||
if cnf == nil {
|
if cnf == nil {
|
||||||
return nil, ErrorEmptyParams.Error(nil)
|
return nil, ErrorParamEmpty.Error(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &HelperLDAP{
|
return &HelperLDAP{
|
||||||
@@ -210,7 +210,7 @@ func (lc *HelperLDAP) starttls(l *ldap.Conn) liberr.Error {
|
|||||||
|
|
||||||
func (lc *HelperLDAP) tryConnect() (TLSMode, liberr.Error) {
|
func (lc *HelperLDAP) tryConnect() (TLSMode, liberr.Error) {
|
||||||
if lc == nil {
|
if lc == nil {
|
||||||
return TLSModeNone, ErrorEmptyParams.Error(nil)
|
return TLSModeNone, ErrorParamEmpty.Error(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -257,7 +257,7 @@ func (lc *HelperLDAP) tryConnect() (TLSMode, liberr.Error) {
|
|||||||
|
|
||||||
func (lc *HelperLDAP) connect() liberr.Error {
|
func (lc *HelperLDAP) connect() liberr.Error {
|
||||||
if lc == nil || lc.ctx == nil {
|
if lc == nil || lc.ctx == nil {
|
||||||
return ErrorLDAPContext.Error(ErrorEmptyParams.Error(nil))
|
return ErrorLDAPContext.Error(ErrorParamEmpty.Error(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := lc.ctx.Err(); err != nil {
|
if err := lc.ctx.Err(); err != nil {
|
||||||
@@ -320,7 +320,7 @@ func (lc *HelperLDAP) connect() liberr.Error {
|
|||||||
// Check used to check if connection success (without any bind).
|
// Check used to check if connection success (without any bind).
|
||||||
func (lc *HelperLDAP) Check() liberr.Error {
|
func (lc *HelperLDAP) Check() liberr.Error {
|
||||||
if lc == nil {
|
if lc == nil {
|
||||||
return ErrorEmptyParams.Error(nil)
|
return ErrorParamEmpty.Error(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if lc.conn == nil {
|
if lc.conn == nil {
|
||||||
@@ -355,7 +355,7 @@ func (lc *HelperLDAP) Close() {
|
|||||||
// AuthUser used to test bind given user uid and password.
|
// AuthUser used to test bind given user uid and password.
|
||||||
func (lc *HelperLDAP) AuthUser(username, password string) liberr.Error {
|
func (lc *HelperLDAP) AuthUser(username, password string) liberr.Error {
|
||||||
if lc == nil {
|
if lc == nil {
|
||||||
return ErrorEmptyParams.Error(nil)
|
return ErrorParamEmpty.Error(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := lc.connect(); err != nil {
|
if err := lc.connect(); err != nil {
|
||||||
@@ -363,7 +363,7 @@ func (lc *HelperLDAP) AuthUser(username, password string) liberr.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if username == "" || password == "" {
|
if username == "" || password == "" {
|
||||||
return ErrorEmptyParams.Error(nil)
|
return ErrorParamEmpty.Error(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := lc.conn.Bind(username, password)
|
err := lc.conn.Bind(username, password)
|
||||||
@@ -374,7 +374,7 @@ func (lc *HelperLDAP) AuthUser(username, password string) liberr.Error {
|
|||||||
// Connect used to connect and bind to server.
|
// Connect used to connect and bind to server.
|
||||||
func (lc *HelperLDAP) Connect() liberr.Error {
|
func (lc *HelperLDAP) Connect() liberr.Error {
|
||||||
if lc == nil {
|
if lc == nil {
|
||||||
return ErrorEmptyParams.Error(nil)
|
return ErrorParamEmpty.Error(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := lc.AuthUser(lc.bindDN, lc.bindPass); err != nil {
|
if err := lc.AuthUser(lc.bindDN, lc.bindPass); err != nil {
|
||||||
|
@@ -27,31 +27,30 @@
|
|||||||
package logger
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + liberr.MinPkgLogger
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgLogger
|
||||||
ErrorValidatorError
|
ErrorValidatorError
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
|
panic(fmt.Errorf("error code collision with package golib/logger"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorValidatorError:
|
case ErrorValidatorError:
|
||||||
return "logger : invalid config"
|
return "logger : invalid config"
|
||||||
}
|
}
|
||||||
|
|
||||||
return liberr.UNK_MESSAGE
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -45,7 +45,7 @@ type _hclog struct {
|
|||||||
|
|
||||||
func (l *_hclog) Log(level hclog.Level, msg string, args ...interface{}) {
|
func (l *_hclog) Log(level hclog.Level, msg string, args ...interface{}) {
|
||||||
switch level {
|
switch level {
|
||||||
case hclog.Off, hclog.NoLevel:
|
case hclog.NoLevel, hclog.Off:
|
||||||
return
|
return
|
||||||
case hclog.Trace:
|
case hclog.Trace:
|
||||||
l.l.Debug(msg, nil, args...)
|
l.l.Debug(msg, nil, args...)
|
||||||
@@ -141,7 +141,7 @@ func (l *_hclog) ResetNamed(name string) hclog.Logger {
|
|||||||
|
|
||||||
func (l *_hclog) SetLevel(level hclog.Level) {
|
func (l *_hclog) SetLevel(level hclog.Level) {
|
||||||
switch level {
|
switch level {
|
||||||
case hclog.Off, hclog.NoLevel:
|
case hclog.NoLevel, hclog.Off:
|
||||||
l.l.SetLevel(NilLevel)
|
l.l.SetLevel(NilLevel)
|
||||||
case hclog.Trace:
|
case hclog.Trace:
|
||||||
l.l.SetLevel(DebugLevel)
|
l.l.SetLevel(DebugLevel)
|
||||||
@@ -159,7 +159,7 @@ func (l *_hclog) SetLevel(level hclog.Level) {
|
|||||||
func (l *_hclog) StandardLogger(opts *hclog.StandardLoggerOptions) *log.Logger {
|
func (l *_hclog) StandardLogger(opts *hclog.StandardLoggerOptions) *log.Logger {
|
||||||
var lvl Level
|
var lvl Level
|
||||||
switch opts.ForceLevel {
|
switch opts.ForceLevel {
|
||||||
case hclog.Off, hclog.NoLevel:
|
case hclog.NoLevel, hclog.Off:
|
||||||
lvl = NilLevel
|
lvl = NilLevel
|
||||||
case hclog.Trace:
|
case hclog.Trace:
|
||||||
lvl = DebugLevel
|
lvl = DebugLevel
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
package mail
|
package mail
|
||||||
|
|
||||||
|
import "golang.org/x/exp/slices"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
headerFrom = "From"
|
headerFrom = "From"
|
||||||
headerSender = "Sender"
|
headerSender = "Sender"
|
||||||
@@ -150,35 +152,21 @@ func (e *email) AddRecipients(rt recipientType, rcpt ...string) {
|
|||||||
for _, s := range rcpt {
|
for _, s := range rcpt {
|
||||||
switch rt {
|
switch rt {
|
||||||
case RecipientTo:
|
case RecipientTo:
|
||||||
if !e.isInSlice(e.to, s) {
|
if !slices.Contains(e.to, s) {
|
||||||
e.to = append(e.to, s)
|
e.to = append(e.to, s)
|
||||||
}
|
}
|
||||||
case RecipientCC:
|
case RecipientCC:
|
||||||
if !e.isInSlice(e.cc, s) {
|
if !slices.Contains(e.cc, s) {
|
||||||
e.cc = append(e.cc, s)
|
e.cc = append(e.cc, s)
|
||||||
}
|
}
|
||||||
case RecipientBCC:
|
case RecipientBCC:
|
||||||
if !e.isInSlice(e.bcc, s) {
|
if !slices.Contains(e.bcc, s) {
|
||||||
e.bcc = append(e.bcc, s)
|
e.bcc = append(e.bcc, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e email) isInSlice(s []string, str string) bool {
|
|
||||||
if str == "" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, i := range s {
|
|
||||||
if i == str {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *email) getHeader(h func(key string, values ...string)) {
|
func (e *email) getHeader(h func(key string, values ...string)) {
|
||||||
h(headerFrom, e.GetFrom())
|
h(headerFrom, e.GetFrom())
|
||||||
h(headerSender, e.GetSender())
|
h(headerSender, e.GetSender())
|
||||||
|
@@ -26,10 +26,14 @@
|
|||||||
|
|
||||||
package mail
|
package mail
|
||||||
|
|
||||||
import "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgMail
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgMail
|
||||||
ErrorMailConfigInvalid
|
ErrorMailConfigInvalid
|
||||||
ErrorMailIORead
|
ErrorMailIORead
|
||||||
ErrorMailIOWrite
|
ErrorMailIOWrite
|
||||||
@@ -38,22 +42,16 @@ const (
|
|||||||
ErrorMailSenderInit
|
ErrorMailSenderInit
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/mail"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case ErrorParamEmpty:
|
||||||
return ""
|
|
||||||
case ErrorParamsEmpty:
|
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorMailConfigInvalid:
|
case ErrorMailConfigInvalid:
|
||||||
return "config is invalid"
|
return "config is invalid"
|
||||||
@@ -69,5 +67,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "error occurs while to preparing SMTP Email sender"
|
return "error occurs while to preparing SMTP Email sender"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -244,10 +244,10 @@ func (s *sender) Send(ctx context.Context, cli libsmtp.SMTP) liberr.Error {
|
|||||||
|
|
||||||
if len(s.from) < _MinSizeAddr {
|
if len(s.from) < _MinSizeAddr {
|
||||||
//nolint #goerr113
|
//nolint #goerr113
|
||||||
return ErrorParamsEmpty.ErrorParent(fmt.Errorf("parameters 'from' is not valid"))
|
return ErrorParamEmpty.ErrorParent(fmt.Errorf("parameters 'from' is not valid"))
|
||||||
} else if len(s.rcpt) < 1 || len(s.rcpt[0]) < _MinSizeAddr {
|
} else if len(s.rcpt) < 1 || len(s.rcpt[0]) < _MinSizeAddr {
|
||||||
//nolint #goerr113
|
//nolint #goerr113
|
||||||
return ErrorParamsEmpty.ErrorParent(fmt.Errorf("parameters 'receipient' is not valid"))
|
return ErrorParamEmpty.ErrorParent(fmt.Errorf("parameters 'receipient' is not valid"))
|
||||||
}
|
}
|
||||||
|
|
||||||
e := cli.Send(ctx, s.from, s.rcpt, s.data)
|
e := cli.Send(ctx, s.from, s.rcpt, s.data)
|
||||||
|
@@ -25,30 +25,28 @@
|
|||||||
|
|
||||||
package mailPooler
|
package mailPooler
|
||||||
|
|
||||||
import "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgMailPooler
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgMailPooler
|
||||||
ErrorMailPooler
|
ErrorMailPooler
|
||||||
ErrorMailPoolerContext
|
ErrorMailPoolerContext
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/mailPooler"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case ErrorParamEmpty:
|
||||||
return ""
|
|
||||||
case ErrorParamsEmpty:
|
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorMailPooler:
|
case ErrorMailPooler:
|
||||||
return "generic mail pooler error"
|
return "generic mail pooler error"
|
||||||
@@ -56,5 +54,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "context has trigger error"
|
return "context has trigger error"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -45,7 +45,7 @@ type pooler struct {
|
|||||||
|
|
||||||
func (p *pooler) Reset() liberr.Error {
|
func (p *pooler) Reset() liberr.Error {
|
||||||
if p.s == nil {
|
if p.s == nil {
|
||||||
return ErrorParamsEmpty.ErrorParent(errors.New("smtp client is not define"))
|
return ErrorParamEmpty.ErrorParent(errors.New("smtp client is not define"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.c.Reset(); err != nil {
|
if err := p.c.Reset(); err != nil {
|
||||||
@@ -71,7 +71,7 @@ func (p *pooler) NewPooler() Pooler {
|
|||||||
|
|
||||||
func (p *pooler) Send(ctx context.Context, from string, to []string, data io.WriterTo) liberr.Error {
|
func (p *pooler) Send(ctx context.Context, from string, to []string, data io.WriterTo) liberr.Error {
|
||||||
if p.s == nil {
|
if p.s == nil {
|
||||||
return ErrorParamsEmpty.ErrorParent(errors.New("smtp client is not define"))
|
return ErrorParamEmpty.ErrorParent(errors.New("smtp client is not define"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.c.Pool(ctx); err != nil {
|
if err := p.c.Pool(ctx); err != nil {
|
||||||
@@ -83,7 +83,7 @@ func (p *pooler) Send(ctx context.Context, from string, to []string, data io.Wri
|
|||||||
|
|
||||||
func (p *pooler) Client(ctx context.Context) (*smtp.Client, liberr.Error) {
|
func (p *pooler) Client(ctx context.Context) (*smtp.Client, liberr.Error) {
|
||||||
if p.s == nil {
|
if p.s == nil {
|
||||||
return nil, ErrorParamsEmpty.ErrorParent(errors.New("smtp client is not define"))
|
return nil, ErrorParamEmpty.ErrorParent(errors.New("smtp client is not define"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.s.Client(ctx)
|
return p.s.Client(ctx)
|
||||||
@@ -97,7 +97,7 @@ func (p *pooler) Close() {
|
|||||||
|
|
||||||
func (p *pooler) Check(ctx context.Context) liberr.Error {
|
func (p *pooler) Check(ctx context.Context) liberr.Error {
|
||||||
if p.s == nil {
|
if p.s == nil {
|
||||||
return ErrorParamsEmpty.ErrorParent(errors.New("smtp client is not define"))
|
return ErrorParamEmpty.ErrorParent(errors.New("smtp client is not define"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.s.Check(ctx)
|
return p.s.Check(ctx)
|
||||||
@@ -121,7 +121,7 @@ func (p *pooler) StatusInfo() (name string, release string, hash string) {
|
|||||||
|
|
||||||
func (p *pooler) StatusHealth() error {
|
func (p *pooler) StatusHealth() error {
|
||||||
if p.s == nil {
|
if p.s == nil {
|
||||||
return ErrorParamsEmpty.ErrorParent(errors.New("smtp client is not define"))
|
return ErrorParamEmpty.ErrorParent(errors.New("smtp client is not define"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.s.StatusHealth()
|
return p.s.StatusHealth()
|
||||||
|
@@ -26,31 +26,29 @@
|
|||||||
|
|
||||||
package mailer
|
package mailer
|
||||||
|
|
||||||
import "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgMailer
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgMailer
|
||||||
ErrorMailerConfigInvalid
|
ErrorMailerConfigInvalid
|
||||||
ErrorMailerHtml
|
ErrorMailerHtml
|
||||||
ErrorMailerText
|
ErrorMailerText
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/mailer"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case ErrorParamEmpty:
|
||||||
return ""
|
|
||||||
case ErrorParamsEmpty:
|
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorMailerConfigInvalid:
|
case ErrorMailerConfigInvalid:
|
||||||
return "config of mailer is invalid"
|
return "config of mailer is invalid"
|
||||||
@@ -60,5 +58,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "cannot generate pain text content"
|
return "cannot generate pain text content"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -36,12 +36,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
libsts "github.com/nabbar/golib/status/config"
|
||||||
|
|
||||||
libval "github.com/go-playground/validator/v10"
|
libval "github.com/go-playground/validator/v10"
|
||||||
libtls "github.com/nabbar/golib/certificates"
|
libtls "github.com/nabbar/golib/certificates"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
libiot "github.com/nabbar/golib/ioutils"
|
libiot "github.com/nabbar/golib/ioutils"
|
||||||
liblog "github.com/nabbar/golib/logger"
|
liblog "github.com/nabbar/golib/logger"
|
||||||
libsts "github.com/nabbar/golib/status"
|
|
||||||
natjwt "github.com/nats-io/jwt/v2"
|
natjwt "github.com/nats-io/jwt/v2"
|
||||||
natsrv "github.com/nats-io/nats-server/v2/server"
|
natsrv "github.com/nats-io/nats-server/v2/server"
|
||||||
)
|
)
|
||||||
|
@@ -36,6 +36,8 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/nabbar/golib/status/config"
|
||||||
|
|
||||||
libtls "github.com/nabbar/golib/certificates"
|
libtls "github.com/nabbar/golib/certificates"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
libsts "github.com/nabbar/golib/status"
|
libsts "github.com/nabbar/golib/status"
|
||||||
@@ -70,7 +72,7 @@ type Server interface {
|
|||||||
StatusRouter(sts libsts.RouteStatus, prefix string)
|
StatusRouter(sts libsts.RouteStatus, prefix string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(opt *natsrv.Options, sts libsts.ConfigStatus) Server {
|
func NewServer(opt *natsrv.Options, sts config.ConfigStatus) Server {
|
||||||
o := new(atomic.Value)
|
o := new(atomic.Value)
|
||||||
|
|
||||||
if opt != nil {
|
if opt != nil {
|
||||||
@@ -86,7 +88,7 @@ func NewServer(opt *natsrv.Options, sts libsts.ConfigStatus) Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type server struct {
|
type server struct {
|
||||||
c *libsts.ConfigStatus
|
c *config.ConfigStatus
|
||||||
o *atomic.Value
|
o *atomic.Value
|
||||||
s *atomic.Value
|
s *atomic.Value
|
||||||
r *atomic.Value
|
r *atomic.Value
|
||||||
|
@@ -36,7 +36,7 @@ import (
|
|||||||
libval "github.com/go-playground/validator/v10"
|
libval "github.com/go-playground/validator/v10"
|
||||||
libclu "github.com/nabbar/golib/cluster"
|
libclu "github.com/nabbar/golib/cluster"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
libsts "github.com/nabbar/golib/status"
|
libsts "github.com/nabbar/golib/status/config"
|
||||||
"github.com/xujiajun/nutsdb"
|
"github.com/xujiajun/nutsdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -30,7 +30,9 @@
|
|||||||
|
|
||||||
package nutsdb
|
package nutsdb
|
||||||
|
|
||||||
import liberr "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + liberr.MinPkgNutsDB
|
ErrorParamsEmpty liberr.CodeError = iota + liberr.MinPkgNutsDB
|
||||||
|
@@ -27,39 +27,37 @@
|
|||||||
|
|
||||||
package progress
|
package progress
|
||||||
|
|
||||||
import liberr "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + liberr.MinPkgNutsDB
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgNutsDB
|
||||||
ErrorParamsMissing
|
ErrorParamMissing
|
||||||
ErrorParamsMismatching
|
ErrorParamMismatching
|
||||||
ErrorBarNotInitialized
|
ErrorBarNotInitialized
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/progress"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case liberr.UNK_ERROR:
|
case ErrorParamEmpty:
|
||||||
return ""
|
|
||||||
case ErrorParamsEmpty:
|
|
||||||
return "at least on given parameters is empty"
|
return "at least on given parameters is empty"
|
||||||
case ErrorParamsMissing:
|
case ErrorParamMissing:
|
||||||
return "at least on given parameters is missing"
|
return "at least on given parameters is missing"
|
||||||
case ErrorParamsMismatching:
|
case ErrorParamMismatching:
|
||||||
return "at least on given parameters is mismatching awaiting type"
|
return "at least on given parameters is mismatching awaiting type"
|
||||||
case ErrorBarNotInitialized:
|
case ErrorBarNotInitialized:
|
||||||
return "progress bar not initialized"
|
return "progress bar not initialized"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -27,12 +27,14 @@
|
|||||||
package request
|
package request
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty liberr.CodeError = iota + liberr.MinPkgRequest
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgRequest
|
||||||
ErrorParamsInvalid
|
ErrorParamInvalid
|
||||||
ErrorValidatorError
|
ErrorValidatorError
|
||||||
ErrorCreateRequest
|
ErrorCreateRequest
|
||||||
ErrorSendRequest
|
ErrorSendRequest
|
||||||
@@ -45,21 +47,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
liberr.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/request"))
|
||||||
}
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case ErrorParamsEmpty:
|
case ErrorParamEmpty:
|
||||||
return "at least one given parameters is empty"
|
return "at least one given parameters is empty"
|
||||||
case ErrorParamsInvalid:
|
case ErrorParamInvalid:
|
||||||
return "at least one given parameters is invalid"
|
return "at least one given parameters is invalid"
|
||||||
case ErrorValidatorError:
|
case ErrorValidatorError:
|
||||||
return "config seems to be invalid"
|
return "config seems to be invalid"
|
||||||
@@ -81,5 +79,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "the body match with not contains constraint"
|
return "the body match with not contains constraint"
|
||||||
}
|
}
|
||||||
|
|
||||||
return liberr.NUL_MESSAGE
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -646,7 +646,7 @@ func (r *request) Do() (*http.Response, liberr.Error) {
|
|||||||
defer r.s.Unlock()
|
defer r.s.Unlock()
|
||||||
|
|
||||||
if r.m == "" || r.u == nil || r.u.String() == "" {
|
if r.m == "" || r.u == nil || r.u.String() == "" {
|
||||||
return nil, ErrorParamsInvalid.Error(nil)
|
return nil, ErrorParamInvalid.Error(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@@ -30,12 +30,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
libsts "github.com/nabbar/golib/status/config"
|
||||||
|
|
||||||
libval "github.com/go-playground/validator/v10"
|
libval "github.com/go-playground/validator/v10"
|
||||||
libtls "github.com/nabbar/golib/certificates"
|
libtls "github.com/nabbar/golib/certificates"
|
||||||
libcfg "github.com/nabbar/golib/config"
|
libcfg "github.com/nabbar/golib/config"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
libhtc "github.com/nabbar/golib/httpcli"
|
libhtc "github.com/nabbar/golib/httpcli"
|
||||||
libsts "github.com/nabbar/golib/status"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type OptionsCredentials struct {
|
type OptionsCredentials struct {
|
||||||
|
@@ -104,7 +104,7 @@ func (a authorization) Handler(c *gin.Context) {
|
|||||||
auth := c.Request.Header.Get(HEAD_AUTH_SEND)
|
auth := c.Request.Header.Get(HEAD_AUTH_SEND)
|
||||||
|
|
||||||
if auth == "" {
|
if auth == "" {
|
||||||
AuthRequire(c, HEADER_AUTH_MISSING.Error(nil).GetErrorFull(""))
|
AuthRequire(c, ErrorHeaderAuthMissing.Error(nil).GetErrorFull(""))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ func (a authorization) Handler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if authValue == "" {
|
if authValue == "" {
|
||||||
AuthRequire(c, HEADER_AUTH_EMPTY.Error(nil).GetErrorFull(""))
|
AuthRequire(c, ErrorHeaderAuthEmpty.Error(nil).GetErrorFull(""))
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
code, err := a.check(authValue)
|
code, err := a.check(authValue)
|
||||||
@@ -130,12 +130,12 @@ func (a authorization) Handler(c *gin.Context) {
|
|||||||
r(c)
|
r(c)
|
||||||
}
|
}
|
||||||
case AUTH_CODE_REQUIRE:
|
case AUTH_CODE_REQUIRE:
|
||||||
AuthRequire(c, HEADER_AUTH_REQUIRE.Error(err).GetErrorFull(""))
|
AuthRequire(c, ErrorHeaderAuthRequire.Error(err).GetErrorFull(""))
|
||||||
case AUTH_CODE_FORBIDDEN:
|
case AUTH_CODE_FORBIDDEN:
|
||||||
AuthForbidden(c, HEADER_AUTH_FORBIDDEN.Error(err).GetErrorFull(""))
|
AuthForbidden(c, ErrorHeaderAuthForbidden.Error(err).GetErrorFull(""))
|
||||||
default:
|
default:
|
||||||
c.Errors = append(c.Errors, &gin.Error{
|
c.Errors = append(c.Errors, &gin.Error{
|
||||||
Err: HEADER_AUTH_ERROR.Error(err).GetErrorFull(""),
|
Err: ErrorHeaderAuth.Error(err).GetErrorFull(""),
|
||||||
Type: gin.ErrorTypePrivate,
|
Type: gin.ErrorTypePrivate,
|
||||||
})
|
})
|
||||||
c.AbortWithStatus(http.StatusInternalServerError)
|
c.AbortWithStatus(http.StatusInternalServerError)
|
||||||
|
@@ -26,51 +26,43 @@
|
|||||||
|
|
||||||
package router
|
package router
|
||||||
|
|
||||||
import errors "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
const (
|
liberr "github.com/nabbar/golib/errors"
|
||||||
EMPTY_PARAMS errors.CodeError = iota + errors.MinPkgRouter
|
|
||||||
HEADER_AUTH_MISSING
|
|
||||||
HEADER_AUTH_EMPTY
|
|
||||||
HEADER_AUTH_REQUIRE
|
|
||||||
HEADER_AUTH_FORBIDDEN
|
|
||||||
HEADER_AUTH_ERROR
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
const (
|
||||||
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgRouter
|
||||||
func IsCodeError() bool {
|
ErrorHeaderAuth
|
||||||
return isCodeError
|
ErrorHeaderAuthMissing
|
||||||
}
|
ErrorHeaderAuthEmpty
|
||||||
|
ErrorHeaderAuthRequire
|
||||||
|
ErrorHeaderAuthForbidden
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(EMPTY_PARAMS)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(EMPTY_PARAMS, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/router"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case EMPTY_PARAMS:
|
case ErrorParamEmpty:
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
|
case ErrorHeaderAuthMissing:
|
||||||
case HEADER_AUTH_MISSING:
|
|
||||||
return "missing authorization header"
|
return "missing authorization header"
|
||||||
|
case ErrorHeaderAuthEmpty:
|
||||||
case HEADER_AUTH_EMPTY:
|
|
||||||
return "authorization header is empty"
|
return "authorization header is empty"
|
||||||
|
case ErrorHeaderAuthRequire:
|
||||||
case HEADER_AUTH_REQUIRE:
|
|
||||||
return "authorization check failed, authorization still require"
|
return "authorization check failed, authorization still require"
|
||||||
|
case ErrorHeaderAuthForbidden:
|
||||||
case HEADER_AUTH_FORBIDDEN:
|
|
||||||
return "authorization check success but unauthorized client"
|
return "authorization check success but unauthorized client"
|
||||||
|
case ErrorHeaderAuth:
|
||||||
case HEADER_AUTH_ERROR:
|
|
||||||
return "authorization check return an invalid response code"
|
return "authorization check return an invalid response code"
|
||||||
|
|
||||||
case errors.UNK_ERROR:
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -26,30 +26,28 @@
|
|||||||
|
|
||||||
package semaphore
|
package semaphore
|
||||||
|
|
||||||
import errors "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgSemaphore
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgSemaphore
|
||||||
ErrorWorkerNew
|
ErrorWorkerNew
|
||||||
ErrorWorkerWaitAll
|
ErrorWorkerWaitAll
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/semaphore"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case ErrorParamEmpty:
|
||||||
return ""
|
|
||||||
case ErrorParamsEmpty:
|
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorWorkerNew:
|
case ErrorWorkerNew:
|
||||||
return "error on acquire one new semaphore worker"
|
return "error on acquire one new semaphore worker"
|
||||||
@@ -57,5 +55,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "error on acquire to wait all pending thread"
|
return "error on acquire to wait all pending thread"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -29,10 +29,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
libsts "github.com/nabbar/golib/status/config"
|
||||||
|
|
||||||
libval "github.com/go-playground/validator/v10"
|
libval "github.com/go-playground/validator/v10"
|
||||||
libtls "github.com/nabbar/golib/certificates"
|
libtls "github.com/nabbar/golib/certificates"
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
libsts "github.com/nabbar/golib/status"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConfigModel struct {
|
type ConfigModel struct {
|
||||||
|
@@ -85,10 +85,10 @@ func (s *smtpClient) client(ctx context.Context, addr string, tlsConfig *tls.Con
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
if s.cfg.GetTlsMode() == TLS_STARTTLS && tlsConfig == nil {
|
if s.cfg.GetTlsMode() == TLS_STARTTLS && tlsConfig == nil {
|
||||||
err = ErrorParamsEmpty.Error(nil)
|
err = ErrorParamEmpty.Error(nil)
|
||||||
return
|
return
|
||||||
} else if s.cfg.GetTlsMode() == TLS_TLS && tlsConfig == nil {
|
} else if s.cfg.GetTlsMode() == TLS_TLS && tlsConfig == nil {
|
||||||
err = ErrorParamsEmpty.Error(nil)
|
err = ErrorParamEmpty.Error(nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,10 +26,14 @@
|
|||||||
|
|
||||||
package smtp
|
package smtp
|
||||||
|
|
||||||
import "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgSMTP
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgSMTP
|
||||||
ErrorConfigValidator
|
ErrorConfigValidator
|
||||||
ErrorConfigInvalidDSN
|
ErrorConfigInvalidDSN
|
||||||
ErrorConfigInvalidNetwork
|
ErrorConfigInvalidNetwork
|
||||||
@@ -47,22 +51,16 @@ const (
|
|||||||
ErrorSMTPLineCRLF
|
ErrorSMTPLineCRLF
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/smtp"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case ErrorParamEmpty:
|
||||||
return ""
|
|
||||||
case ErrorParamsEmpty:
|
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorConfigValidator:
|
case ErrorConfigValidator:
|
||||||
return "invalid config, validation error"
|
return "invalid config, validation error"
|
||||||
@@ -96,5 +94,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "smtp: A line must not contain CR or LF"
|
return "smtp: A line must not contain CR or LF"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/nabbar/golib/status/config"
|
||||||
|
|
||||||
libtls "github.com/nabbar/golib/certificates"
|
libtls "github.com/nabbar/golib/certificates"
|
||||||
|
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
@@ -70,8 +72,8 @@ type Config interface {
|
|||||||
SetTLSServerName(serverName string)
|
SetTLSServerName(serverName string)
|
||||||
GetTlSServerName() string
|
GetTlSServerName() string
|
||||||
|
|
||||||
SetStatusConfig(sts libsts.ConfigStatus)
|
SetStatusConfig(sts config.ConfigStatus)
|
||||||
GetStatusConfig() libsts.ConfigStatus
|
GetStatusConfig() config.ConfigStatus
|
||||||
|
|
||||||
GetDsn() string
|
GetDsn() string
|
||||||
}
|
}
|
||||||
@@ -102,7 +104,7 @@ func NewSMTP(cfg Config, tlsConfig *tls.Config) (SMTP, liberr.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cfg == nil {
|
if cfg == nil {
|
||||||
return nil, ErrorParamsEmpty.Error(nil)
|
return nil, ErrorParamEmpty.Error(nil)
|
||||||
} else {
|
} else {
|
||||||
return &smtpClient{
|
return &smtpClient{
|
||||||
mut: sync.Mutex{},
|
mut: sync.Mutex{},
|
||||||
|
@@ -26,32 +26,30 @@
|
|||||||
|
|
||||||
package static
|
package static
|
||||||
|
|
||||||
import "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgStatic
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgStatic
|
||||||
ErrorFileInfo
|
ErrorFileInfo
|
||||||
ErrorFileOpen
|
ErrorFileOpen
|
||||||
ErrorFiletemp
|
ErrorFiletemp
|
||||||
ErrorFileNotFound
|
ErrorFileNotFound
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/static"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case ErrorParamEmpty:
|
||||||
return ""
|
|
||||||
case ErrorParamsEmpty:
|
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorFileInfo:
|
case ErrorFileInfo:
|
||||||
return "cannot get file info"
|
return "cannot get file info"
|
||||||
@@ -63,5 +61,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "file not found"
|
return "file not found"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -43,6 +43,8 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/gin-gonic/gin/render"
|
"github.com/gin-gonic/gin/render"
|
||||||
|
|
||||||
@@ -77,16 +79,6 @@ func (s *staticHandler) _makeRoute(group, route string) string {
|
|||||||
return path.Join(group, route)
|
return path.Join(group, route)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *staticHandler) _IsInSlice(sl []string, val string) bool {
|
|
||||||
for _, v := range sl {
|
|
||||||
if v == val {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *staticHandler) _getSize() int64 {
|
func (s *staticHandler) _getSize() int64 {
|
||||||
s.m.Lock()
|
s.m.Lock()
|
||||||
defer s.m.Unlock()
|
defer s.m.Unlock()
|
||||||
@@ -297,7 +289,7 @@ func (s *staticHandler) _setRouter(val []string) {
|
|||||||
|
|
||||||
func (s *staticHandler) _listEmbed(root string) ([]fs.DirEntry, liberr.Error) {
|
func (s *staticHandler) _listEmbed(root string) ([]fs.DirEntry, liberr.Error) {
|
||||||
if root == "" {
|
if root == "" {
|
||||||
return nil, ErrorParamsEmpty.ErrorParent(fmt.Errorf("pathfile is empty"))
|
return nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("pathfile is empty"))
|
||||||
}
|
}
|
||||||
|
|
||||||
s.m.Lock()
|
s.m.Lock()
|
||||||
@@ -316,7 +308,7 @@ func (s *staticHandler) _listEmbed(root string) ([]fs.DirEntry, liberr.Error) {
|
|||||||
|
|
||||||
func (s *staticHandler) _fileGet(pathFile string) (fs.FileInfo, io.ReadCloser, liberr.Error) {
|
func (s *staticHandler) _fileGet(pathFile string) (fs.FileInfo, io.ReadCloser, liberr.Error) {
|
||||||
if pathFile == "" {
|
if pathFile == "" {
|
||||||
return nil, nil, ErrorParamsEmpty.ErrorParent(fmt.Errorf("pathfile is empty"))
|
return nil, nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("pathfile is empty"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if inf, err := s._fileInfo(pathFile); err != nil {
|
if inf, err := s._fileInfo(pathFile); err != nil {
|
||||||
@@ -332,7 +324,7 @@ func (s *staticHandler) _fileGet(pathFile string) (fs.FileInfo, io.ReadCloser, l
|
|||||||
|
|
||||||
func (s *staticHandler) _fileInfo(pathFile string) (fs.FileInfo, liberr.Error) {
|
func (s *staticHandler) _fileInfo(pathFile string) (fs.FileInfo, liberr.Error) {
|
||||||
if pathFile == "" {
|
if pathFile == "" {
|
||||||
return nil, ErrorParamsEmpty.ErrorParent(fmt.Errorf("pathfile is empty"))
|
return nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("pathfile is empty"))
|
||||||
}
|
}
|
||||||
|
|
||||||
s.m.Lock()
|
s.m.Lock()
|
||||||
@@ -364,7 +356,7 @@ func (s *staticHandler) _fileInfo(pathFile string) (fs.FileInfo, liberr.Error) {
|
|||||||
|
|
||||||
func (s *staticHandler) _fileBuff(pathFile string) (io.ReadCloser, liberr.Error) {
|
func (s *staticHandler) _fileBuff(pathFile string) (io.ReadCloser, liberr.Error) {
|
||||||
if pathFile == "" {
|
if pathFile == "" {
|
||||||
return nil, ErrorParamsEmpty.ErrorParent(fmt.Errorf("pathfile is empty"))
|
return nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("pathfile is empty"))
|
||||||
}
|
}
|
||||||
|
|
||||||
s.m.Lock()
|
s.m.Lock()
|
||||||
@@ -383,7 +375,7 @@ func (s *staticHandler) _fileBuff(pathFile string) (io.ReadCloser, liberr.Error)
|
|||||||
|
|
||||||
func (s *staticHandler) _fileTemp(pathFile string) (libiot.FileProgress, liberr.Error) {
|
func (s *staticHandler) _fileTemp(pathFile string) (libiot.FileProgress, liberr.Error) {
|
||||||
if pathFile == "" {
|
if pathFile == "" {
|
||||||
return nil, ErrorParamsEmpty.ErrorParent(fmt.Errorf("pathfile is empty"))
|
return nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("pathfile is empty"))
|
||||||
}
|
}
|
||||||
|
|
||||||
s.m.Lock()
|
s.m.Lock()
|
||||||
@@ -462,7 +454,7 @@ func (s *staticHandler) GetIndex(group, route string) string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if s._IsInSlice(r, route) {
|
if slices.Contains(r, route) {
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -533,7 +525,7 @@ func (s *staticHandler) IsIndexForRoute(pathFile, group, route string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return s._IsInSlice(val, s._makeRoute(group, route))
|
return slices.Contains(val, s._makeRoute(group, route))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *staticHandler) IsRedirect(group, route string) bool {
|
func (s *staticHandler) IsRedirect(group, route string) bool {
|
||||||
|
@@ -24,15 +24,17 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package status
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
libcfg "github.com/nabbar/golib/config"
|
"github.com/nabbar/golib/status"
|
||||||
|
|
||||||
|
libcfg "github.com/nabbar/golib/config"
|
||||||
|
libsts "github.com/nabbar/golib/status"
|
||||||
spfcbr "github.com/spf13/cobra"
|
spfcbr "github.com/spf13/cobra"
|
||||||
spfvpr "github.com/spf13/viper"
|
spfvpr "github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@@ -76,8 +78,8 @@ func DefaultConfig(indent string) []byte {
|
|||||||
|
|
||||||
func RegisterFlag(prefix string, Command *spfcbr.Command, Viper *spfvpr.Viper) error {
|
func RegisterFlag(prefix string, Command *spfcbr.Command, Viper *spfvpr.Viper) error {
|
||||||
_ = Command.PersistentFlags().Bool(prefix+".mandatory", true, "define if the component must be available for the api. If yes, api status will be KO if this component is down. If no, api status can be OK if this component is down.")
|
_ = Command.PersistentFlags().Bool(prefix+".mandatory", true, "define if the component must be available for the api. If yes, api status will be KO if this component is down. If no, api status can be OK if this component is down.")
|
||||||
_ = Command.PersistentFlags().String(prefix+".message_ok", DefMessageOK, "define the message if the status is OK.")
|
_ = Command.PersistentFlags().String(prefix+".message_ok", status.DefMessageOK, "define the message if the status is OK.")
|
||||||
_ = Command.PersistentFlags().String(prefix+".message_ko", DefMessageKO, "define the message if the status is KO.")
|
_ = Command.PersistentFlags().String(prefix+".message_ko", status.DefMessageKO, "define the message if the status is KO.")
|
||||||
_ = Command.PersistentFlags().Duration(prefix+".cache_timeout_info", time.Hour, "define the time between checking the component information (name, release, ...), to prevent asking it too many.")
|
_ = Command.PersistentFlags().Duration(prefix+".cache_timeout_info", time.Hour, "define the time between checking the component information (name, release, ...), to prevent asking it too many.")
|
||||||
_ = Command.PersistentFlags().Duration(prefix+".cache_timeout_health", 5*time.Second, "define the time between checking the component health to prevent asking it too many.")
|
_ = Command.PersistentFlags().Duration(prefix+".cache_timeout_health", 5*time.Second, "define the time between checking the component health to prevent asking it too many.")
|
||||||
|
|
||||||
@@ -98,20 +100,20 @@ func RegisterFlag(prefix string, Command *spfcbr.Command, Viper *spfvpr.Viper) e
|
|||||||
|
|
||||||
func (c *ConfigStatus) fctMessage() (msgOk string, msgKO string) {
|
func (c *ConfigStatus) fctMessage() (msgOk string, msgKO string) {
|
||||||
if c.MessageOK == "" {
|
if c.MessageOK == "" {
|
||||||
c.MessageOK = DefMessageOK
|
c.MessageOK = status.DefMessageOK
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.MessageKO == "" {
|
if c.MessageKO == "" {
|
||||||
c.MessageKO = DefMessageKO
|
c.MessageKO = status.DefMessageKO
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.MessageOK, c.MessageKO
|
return c.MessageOK, c.MessageKO
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfigStatus) RegisterStatus(sts RouteStatus, key string, fctInfo FctInfo, fctHealth FctHealth) {
|
func (c *ConfigStatus) RegisterStatus(sts libsts.RouteStatus, key string, fctInfo libsts.FctInfo, fctHealth libsts.FctHealth) {
|
||||||
sts.ComponentNew(key, NewComponent(c.Mandatory, fctInfo, fctHealth, c.fctMessage, c.CacheTimeoutInfo, c.CacheTimeoutHealth))
|
sts.ComponentNew(key, status.NewComponent(c.Mandatory, fctInfo, fctHealth, c.fctMessage, c.CacheTimeoutInfo, c.CacheTimeoutHealth))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfigStatus) Component(fctInfo FctInfo, fctHealth FctHealth) Component {
|
func (c *ConfigStatus) Component(fctInfo libsts.FctInfo, fctHealth libsts.FctHealth) libsts.Component {
|
||||||
return NewComponent(c.Mandatory, fctInfo, fctHealth, c.fctMessage, c.CacheTimeoutInfo, c.CacheTimeoutHealth)
|
return status.NewComponent(c.Mandatory, fctInfo, fctHealth, c.fctMessage, c.CacheTimeoutInfo, c.CacheTimeoutHealth)
|
||||||
}
|
}
|
@@ -93,7 +93,7 @@ func (s *status) Get(x *gin.Context) StatusResponse {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
c.Status = DefMessageKO
|
c.Status = DefMessageKO
|
||||||
c.Message = msgKO
|
c.Message = msgKO
|
||||||
liblog.ErrorLevel.LogGinErrorCtx(liblog.DebugLevel, "get health status", err, x)
|
liblog.ErrorLevel.LogErrorCtx(liblog.DebugLevel, "get health status", err)
|
||||||
} else {
|
} else {
|
||||||
c.Status = DefMessageOK
|
c.Status = DefMessageOK
|
||||||
c.Message = msgOk
|
c.Message = msgOk
|
||||||
|
@@ -27,64 +27,14 @@ package status
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
librtr "github.com/nabbar/golib/router"
|
librtr "github.com/nabbar/golib/router"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
libver "github.com/nabbar/golib/version"
|
libver "github.com/nabbar/golib/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefMessageOK = "OK"
|
|
||||||
const DefMessageKO = "KO"
|
|
||||||
|
|
||||||
type Response struct {
|
|
||||||
InfoResponse
|
|
||||||
StatusResponse
|
|
||||||
|
|
||||||
m sync.Mutex
|
|
||||||
Components []CptResponse `json:"components"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r Response) IsOk() bool {
|
|
||||||
if len(r.Components) < 1 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, c := range r.Components {
|
|
||||||
if c.Status != DefMessageOK {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r Response) IsOkMandatory() bool {
|
|
||||||
if len(r.Components) < 1 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, c := range r.Components {
|
|
||||||
if !c.Mandatory {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.Status != DefMessageOK {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Response) appendNewCpt(cpt CptResponse) {
|
|
||||||
r.m.Lock()
|
|
||||||
defer r.m.Unlock()
|
|
||||||
|
|
||||||
r.Components = append(r.Components, cpt)
|
|
||||||
}
|
|
||||||
|
|
||||||
type RouteStatus interface {
|
type RouteStatus interface {
|
||||||
MiddlewareAdd(mdw ...gin.HandlerFunc)
|
MiddlewareAdd(mdw ...gin.HandlerFunc)
|
||||||
HttpStatusCode(codeOk, codeKO, codeWarning int)
|
HttpStatusCode(codeOk, codeKO, codeWarning int)
|
||||||
|
@@ -21,21 +21,58 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package config
|
package status
|
||||||
|
|
||||||
func stringIsInSlice(list []string, key string) bool {
|
import "sync"
|
||||||
if len(list) < 1 {
|
|
||||||
return false
|
const DefMessageOK = "OK"
|
||||||
|
const DefMessageKO = "KO"
|
||||||
|
|
||||||
|
type Response struct {
|
||||||
|
InfoResponse
|
||||||
|
StatusResponse
|
||||||
|
|
||||||
|
m sync.Mutex
|
||||||
|
Components []CptResponse `json:"components"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Response) IsOk() bool {
|
||||||
|
if len(r.Components) < 1 {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, k := range list {
|
for _, c := range r.Components {
|
||||||
if k == key {
|
if c.Status != DefMessageOK {
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Response) IsOkMandatory() bool {
|
||||||
|
if len(r.Components) < 1 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range r.Components {
|
||||||
|
if !c.Mandatory {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Status != DefMessageOK {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Response) appendNewCpt(cpt CptResponse) {
|
||||||
|
r.m.Lock()
|
||||||
|
defer r.m.Unlock()
|
||||||
|
|
||||||
|
r.Components = append(r.Components, cpt)
|
||||||
}
|
}
|
@@ -26,31 +26,29 @@
|
|||||||
|
|
||||||
package version
|
package version
|
||||||
|
|
||||||
import errors "github.com/nabbar/golib/errors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
liberr "github.com/nabbar/golib/errors"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgVersion
|
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgVersion
|
||||||
ErrorGoVersionInit
|
ErrorGoVersionInit
|
||||||
ErrorGoVersionRuntime
|
ErrorGoVersionRuntime
|
||||||
ErrorGoVersionConstraint
|
ErrorGoVersionConstraint
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
panic(fmt.Errorf("error code collision with package golib/version"))
|
||||||
|
}
|
||||||
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code errors.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case errors.UNK_ERROR:
|
case ErrorParamEmpty:
|
||||||
return ""
|
|
||||||
case ErrorParamsEmpty:
|
|
||||||
return "given parameters is empty"
|
return "given parameters is empty"
|
||||||
case ErrorGoVersionInit:
|
case ErrorGoVersionInit:
|
||||||
return "init GoVersion contraint error"
|
return "init GoVersion contraint error"
|
||||||
@@ -60,5 +58,5 @@ func getMessage(code errors.CodeError) (message string) {
|
|||||||
return "current binary is build with a non-compatible version of Go"
|
return "current binary is build with a non-compatible version of Go"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,8 @@
|
|||||||
package viper
|
package viper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
liberr "github.com/nabbar/golib/errors"
|
liberr "github.com/nabbar/golib/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -44,21 +46,15 @@ const (
|
|||||||
ErrorConfigIsDefault
|
ErrorConfigIsDefault
|
||||||
)
|
)
|
||||||
|
|
||||||
var isCodeError = false
|
|
||||||
|
|
||||||
func IsCodeError() bool {
|
|
||||||
return isCodeError
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
isCodeError = liberr.ExistInMapMessage(ErrorParamEmpty)
|
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||||
|
panic(fmt.Errorf("error code collision with package golib/viper"))
|
||||||
|
}
|
||||||
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessage(code liberr.CodeError) (message string) {
|
func getMessage(code liberr.CodeError) (message string) {
|
||||||
switch code {
|
switch code {
|
||||||
case liberr.UNK_ERROR:
|
|
||||||
return ""
|
|
||||||
case ErrorParamMissing:
|
case ErrorParamMissing:
|
||||||
return "at least one parameter is missing"
|
return "at least one parameter is missing"
|
||||||
case ErrorHomePathNotFound:
|
case ErrorHomePathNotFound:
|
||||||
@@ -81,5 +77,5 @@ func getMessage(code liberr.CodeError) (message string) {
|
|||||||
return "cannot read config, use default config"
|
return "cannot read config, use default config"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return liberr.NullMessage
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user