utils

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: GPL-3.0, GPL-3.0-or-later Imports: 31 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlertNotFound = errors.New("Alert not found")

ErrAlertNotFound contains "Alert not found" error

View Source
var ErrClusterNotFound = errors.New("Cluster not found")

ErrClusterNotFound contains "Cluster not found" error

View Source
var ErrEventEnqueue = errors.New("Failed to enqueue event")

ErrEventEnqueue contains "Failed to enqueue event" error

View Source
var ErrHostNotFound = errors.New("Host not found")

ErrHostNotFound contains "Host not found" error

View Source
var ErrLicenseNotFound = errors.New("License not found")

ErrLicenseNotFound contains "License not found" error

View Source
var ErrNotInClusterHostNotFound = errors.New("Not in cluster host not found")

ErrNotInClusterHostNotFound contains "Baremetal host not found" error

View Source
var ErrOracleDatabaseAgreementInvalidPartID = errors.New("Invalid PartID in request")

ErrOracleDatabaseAgreementInvalidPartID contains "Invalid PartID in request" error

View Source
var ErrOracleDatabaseAgreementNotFound = errors.New("Agreement not found")

ErrOracleDatabaseAgreementNotFound contains "Agreement not found" error

View Source
var ErrOracleDatabaseAssociatedPartNotFound = errors.New("Associated Part not found")

ErrOracleDatabaseAssociatedPartNotFound Associated Part not found

View Source
var ErrPatchingFunctionNotFound = errors.New("Patching Function not found")
View Source
var MAX_TIME time.Time = time.Now().AddDate(1000, 0, 0)
View Source
var MIN_TIME time.Time = time.Unix(0, 0)

Functions

func AssertFuncAreTheSame

func AssertFuncAreTheSame(t *testing.T, funcExpected interface{}, funcActual interface{})

AssertFuncAreTheSame tests if funcExpected is the same of funcActual

func Btc

func Btc(t time.Time) func() time.Time

Btc break the time continuum and return a function that return the time t

func Contains

func Contains(a []string, x string) bool

Contains return true if a contains x, otherwise false.

func CustomLoggingHandler

func CustomLoggingHandler(router http.Handler, log *logrus.Logger) http.Handler

CustomLoggingHandler return a loggingHandler using ercole formatting

func DownloadFile

func DownloadFile(filepath string, url string) (err error)

DownloadFile download the file from url into the filepath

func FileExists

func FileExists(filename string) bool

FileExists checks if a file exists and is not a directory before we try using it to prevent further errors.

func FindNamedMatches

func FindNamedMatches(regex *regexp.Regexp, str string) map[string]string

FindNamedMatches return the map of the groups of str

func FromJSON

func FromJSON(str []byte) interface{}

FromJSON convert a json str to interface containing the equivalent json rappresentation

func Intptr

func Intptr(v int64) *int64

Intptr return a point to the int passed in the argument

func IsVersionLessThan

func IsVersionLessThan(a, b string) bool

IsVersionLessThan return true if a is a version less than b

func LoadFixtureHostData

func LoadFixtureHostData(t *testing.T, filename string) model.HostDataBE

LoadFixtureHostData load the hostdata in the filename and return it

func LoadFixtureHostDataMap

func LoadFixtureHostDataMap(t *testing.T, filename string) model.RawObject

LoadFixtureHostDataMap load the hostdata in the filename and return it

func LoadFixtureMongoHostDataMap

func LoadFixtureMongoHostDataMap(t *testing.T, filename string) model.RawObject

LoadFixtureMongoHostDataMap load the mongohostdata in the filename and return it

func LoadFixtureMongoHostDataMapAsHostData

func LoadFixtureMongoHostDataMapAsHostData(t *testing.T, filename string) model.HostDataBE

LoadFixtureMongoHostDataMapAsHostData load the mongohostdata in the filename and return it as hostdata

func LogErr

func LogErr(log *logrus.Logger, err error)

LogErr log the error to the stdout

func NewAPIUrl

func NewAPIUrl(baseURL string, username string, password string, path string, params url.Values) *url.URL

NewAPIUrl return a new url crafted using the parameters

func NewAPIUrlNoParams

func NewAPIUrlNoParams(baseURL string, username string, password string, path string) *url.URL

NewAPIUrlNoParams return a new url crafted using the parameters

func NewLogger

func NewLogger(componentName string) *logrus.Logger

NewLogger return a logrus.Logger initialized with ercole log standard

func NewObjectIDForTests

func NewObjectIDForTests() func() primitive.ObjectID

NewObjectIDForTests is a function to replace NewObjectID in tests that return ids increasing

func P

func P(s string) time.Time

P parse the string s and return the equivalent time

func PDT

func PDT(s string) primitive.DateTime

PDT parse the string s and return the equivalent bson primitive time

func Remove

func Remove(slice []string, i int) []string

Remove return slice without element at position i, mantaining order

func SliceToSliceOfInterface

func SliceToSliceOfInterface(slice interface{}) []interface{}

SliceToSliceOfInterface convert a interface to a slice of interface

func Str2oid

func Str2oid(str string) primitive.ObjectID

Str2oid parse the objectid and return the parsed value

func ToIdentedJSON

func ToIdentedJSON(v interface{}) string

ToIdentedJSON convert v to a string containing the equivalent idented json rappresentation

func ToJSON

func ToJSON(v interface{}) string

ToJSON convert v to a string containing the equivalent json rappresentation

func ToJSONMongoCursor

func ToJSONMongoCursor(cur *mongo.Cursor) string

ToJSONMongoCursor extract all items from a cursors and return its json rappresentation

func ToMongoJSON

func ToMongoJSON(v interface{}) string

ToMongoJSON convert v to a string containing the equivalent json rappresentation

func WriteAndLogError

func WriteAndLogError(log *logrus.Logger, w http.ResponseWriter, statusCode int, err error)

WriteAndLogError write the error to the w with the statusCode as statusCode and log the error to the stdout

func WriteExtJSONResponse

func WriteExtJSONResponse(log *logrus.Logger, w http.ResponseWriter, statusCode int, resp interface{})

WriteExtJSONResponse write the statuscode and the response to w

func WriteJSONResponse

func WriteJSONResponse(w http.ResponseWriter, statusCode int, resp interface{})

WriteJSONResponse write the statuscode and the response to w

func WriteNoContentResponse

func WriteNoContentResponse(w http.ResponseWriter)

WriteNoContentResponse 204

func WriteXLSMResponse

func WriteXLSMResponse(w http.ResponseWriter, resp *excelize.File)

WriteXLSMResponse for .xlsm files

func WriteXLSXResponse

func WriteXLSXResponse(w http.ResponseWriter, resp *excelize.File)

WriteXLSXResponse for .xlsx fils

Types

type AdvancedError

type AdvancedError struct {
	// Err contains the base error of the AdvancedError
	Err error `json:"err"`
	// Class contains the class of the error
	Class string `json:"class"`
	// File contains the filename of the source code where the error was detected
	Source string `json:"source"`
	// LineNumber contains the number of the line where the error was detected
	Line int `json:"line"`
}

AdvancedError is a struct that contains informations and class about a error

func NewAdvancedError

func NewAdvancedError(err error, class string) AdvancedError

NewAdvancedError return a new AdvancedError using the err as base error and class as class name

func NewAdvancedErrorPtr

func NewAdvancedErrorPtr(err error, class string) *AdvancedError

NewAdvancedErrorPtr return a pointer to a new AdvancedError using the err as base error and class as class name

func (*AdvancedError) Error

func (ae *AdvancedError) Error() string

Error return the representation string of the error

func (*AdvancedError) ErrorClass

func (ae *AdvancedError) ErrorClass() string

ErrorClass return the class of the error

func (*AdvancedError) LineNumber

func (ae *AdvancedError) LineNumber() int

LineNumber return the line number of the error

func (*AdvancedError) SourceFilename

func (ae *AdvancedError) SourceFilename() string

SourceFilename return the source filename of the error

type AdvancedErrorInterface

type AdvancedErrorInterface interface {
	error
	// ErrorClass returns the class of the error
	ErrorClass() string
	// SourceFilename returns the filename of the source code where the error was detected
	SourceFilename() string
	// LineNumber returns the number of the line where the error was detected
	LineNumber() int
}

AdvancedErrorInterface is a extension of the error interface with other informations

var AerrAlertNotFound AdvancedErrorInterface = NewAdvancedErrorPtr(ErrAlertNotFound, "DB ERROR")
var AerrClusterNotFound AdvancedErrorInterface = NewAdvancedErrorPtr(ErrClusterNotFound, "DB ERROR")
var AerrHostNotFound AdvancedErrorInterface = NewAdvancedErrorPtr(ErrHostNotFound, "DB ERROR")
var AerrLicenseNotFound AdvancedErrorInterface = NewAdvancedErrorPtr(ErrLicenseNotFound, "DB ERROR")
var AerrNotInClusterHostNotFound AdvancedErrorInterface = NewAdvancedErrorPtr(ErrNotInClusterHostNotFound, "DB ERROR")
var AerrOracleDatabaseAgreementInvalidPartID AdvancedErrorInterface = NewAdvancedErrorPtr(ErrOracleDatabaseAgreementInvalidPartID, "CLIENT ERROR")
var AerrOracleDatabaseAgreementNotFound AdvancedErrorInterface = NewAdvancedErrorPtr(ErrOracleDatabaseAgreementNotFound, "DB ERROR")
var AerrOracleDatabaseAssociatedPartNotFound AdvancedErrorInterface = NewAdvancedErrorPtr(ErrOracleDatabaseAssociatedPartNotFound, "DB ERROR")
var AerrPatchingFunctionNotFound AdvancedErrorInterface = NewAdvancedErrorPtr(ErrPatchingFunctionNotFound, "DB ERROR")

func ParsePrivateKey

func ParsePrivateKey(raw []byte) (interface{}, interface{}, AdvancedErrorInterface)

ParsePrivateKey converts a private key expressed as []byte to interface{}

func ParsePublicKey

func ParsePublicKey(raw []byte) (interface{}, AdvancedErrorInterface)

ParsePublicKey converts a private key expressed as []byte to interface{}

func PatchHostdata

PatchHostdata patch a single hostdata using the pf PatchingFunction. It doesn't check if pf.Hostname equals hostdata["Hostname"]

func Str2bool

func Str2bool(in string, defaultValue bool) (bool, AdvancedErrorInterface)

Str2bool parse a string to a boolean

func Str2float64

func Str2float64(in string, defaultValue float64) (float64, AdvancedErrorInterface)

Str2float64 parse a string to a float64

func Str2int

func Str2int(in string, defaultValue int) (int, AdvancedErrorInterface)

Str2int parse a string to a int

func Str2time

func Str2time(in string, defaultValue time.Time) (time.Time, AdvancedErrorInterface)

Str2time parse a string to a time

type ErrorResponseFE

type ErrorResponseFE struct {
	// Error contains the (generic) class of the error
	Error string `json:"error"`
	// ErrorDescription contains detailed informations about the error
	ErrorDescription string `json:"errorDescription"`
	// File contains the filename of the source code where the error was detected
	SourceFilename string `json:"sourceFilename"`
	// LineNumber contains the number of the line where the error was detected
	LineNumber int `json:"lineNumber"`
}

ErrorResponseFE is a struct that contains informations about a error

Jump to

Keyboard shortcuts

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