common

package
v0.0.0-...-0baf869 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SortAsc     = "asc"
	SortDesc    = "desc"
	MaxIDLength = 255
)

Variables

View Source
var (
	ErrNotExistCorporateAlarmPattern          = ValidationError{/* contains filtered or unexported fields */}
	ErrNotExistCorporateEntityPattern         = ValidationError{/* contains filtered or unexported fields */}
	ErrNotExistCorporatePbehaviorPattern      = ValidationError{/* contains filtered or unexported fields */}
	ErrNotExistCorporateWeatherServicePattern = ValidationError{/* contains filtered or unexported fields */}
)
View Source
var CanopsisUnderMaintenanceResponse = ErrorResponse{Error: "canopsis is under maintenance"}
View Source
var ForbiddenResponse = ErrorResponse{Error: http.StatusText(http.StatusForbidden)}
View Source
var InternalServerErrorResponse = ErrorResponse{Error: "Internal server error"}
View Source
var MethodNotAllowedResponse = ErrorResponse{Error: http.StatusText(http.StatusMethodNotAllowed)}
View Source
var NotFoundResponse = ErrorResponse{Error: "Not found"}
View Source
var RequestTimeoutResponse = ErrorResponse{Error: http.StatusText(http.StatusRequestTimeout)}
View Source
var UnauthorizedResponse = ErrorResponse{Error: http.StatusText(http.StatusUnauthorized)}

Functions

func GetForbiddenFieldsInAlarmPattern

func GetForbiddenFieldsInAlarmPattern(collection string) []string

func GetForbiddenFieldsInEntityPattern

func GetForbiddenFieldsInEntityPattern(collection string) []string

func GetOnlyAbsoluteTimeCondFieldsInAlarmPattern

func GetOnlyAbsoluteTimeCondFieldsInAlarmPattern(collection string) []string

func GetRealFormatTime

func GetRealFormatTime(f string) string

func GetSearchQuery

func GetSearchQuery(search string, searchBy []string) bson.M

GetSearchQuery returns search query, it returns parsed search filter if it can be parsed or regex search filter by searchBy otherwise.

func GetSortQuery

func GetSortQuery(sortBy, sort string) bson.M

GetSortQuery returns sort query which support consistent sort : sort by "_id" is added if sortBy is not "_id".

func NewValidationErrorFastJsonValue

func NewValidationErrorFastJsonValue(ar *fastjson.Arena, err error, request interface{}) *fastjson.Value

func NewValidationErrorResponse

func NewValidationErrorResponse(err error, request interface{}) interface{}

NewValidationErrorResponse creates response by validation errors. @Failure 400 {object} ValidationErrorResponse

func ValidateAlarmPattern

func ValidateAlarmPattern(fl validator.FieldLevel) bool

func ValidateColorOrEmpty

func ValidateColorOrEmpty(fl validator.FieldLevel) bool

func ValidateCpsTimeType

func ValidateCpsTimeType(field reflect.Value) interface{}

ValidateCpsTimeType implements CustomTypeFunc and returns value to validate.

func ValidateEntityPattern

func ValidateEntityPattern(fl validator.FieldLevel) bool

func ValidateEventPattern

func ValidateEventPattern(fl validator.FieldLevel) bool

func ValidateFilteredQuery

func ValidateFilteredQuery(sl validator.StructLevel)

func ValidateID

func ValidateID(fl validator.FieldLevel) bool

func ValidateInfoValue

func ValidateInfoValue(fl validator.FieldLevel) bool

func ValidateOneOfOrEmpty

func ValidateOneOfOrEmpty(fl validator.FieldLevel) bool

func ValidatePbehaviorPattern

func ValidatePbehaviorPattern(fl validator.FieldLevel) bool

func ValidateTimeFormat

func ValidateTimeFormat(fl validator.FieldLevel) bool

func ValidateWeatherServicePattern

func ValidateWeatherServicePattern(fl validator.FieldLevel) bool

Types

type AlarmPatternFieldsRequest

type AlarmPatternFieldsRequest struct {
	AlarmPattern          pattern.Alarm `json:"alarm_pattern" binding:"alarm_pattern"`
	CorporateAlarmPattern string        `json:"corporate_alarm_pattern"`

	CorporatePattern savedpattern.SavedPattern `json:"-"`
}

func (AlarmPatternFieldsRequest) ToModel

func (AlarmPatternFieldsRequest) ToModelWithoutFields

func (r AlarmPatternFieldsRequest) ToModelWithoutFields(forbiddenFields, onlyTimeAbsoluteFields []string) savedpattern.AlarmPatternFields

type AlarmStep

type AlarmStep struct {
	Type      string            `bson:"_t" json:"_t"`
	Timestamp *datetime.CpsTime `bson:"t" json:"t" swaggertype:"integer"`
	Author    string            `bson:"a" json:"a"`
	UserID    string            `bson:"user_id,omitempty" json:"user_id"`
	Message   string            `bson:"m" json:"m"`
	Value     types.CpsNumber   `bson:"val" json:"val"`
	Initiator string            `bson:"initiator" json:"initiator"`
	Execution string            `bson:"exec,omitempty" json:"-"`
	IconName  string            `bson:"icon_name,omitempty" json:"icon_name,omitempty"`
	Color     string            `bson:"color,omitempty" json:"color,omitempty"`

	// Ticket related fields
	types.TicketInfo `bson:",inline"`

	InPbehaviorInterval bool `bson:"in_pbh,omitempty" json:"in_pbh,omitempty"`
}

type BulkCrudAPI

type BulkCrudAPI interface {
	CrudAPI
	BulkCreate(c *gin.Context)
	BulkUpdate(c *gin.Context)
	BulkDelete(c *gin.Context)
}

type CrudAPI

type CrudAPI interface {
	Create(c *gin.Context)
	List(c *gin.Context)
	Get(c *gin.Context)
	Update(c *gin.Context)
	Delete(c *gin.Context)
}

type EntityPatternFieldsRequest

type EntityPatternFieldsRequest struct {
	EntityPattern          pattern.Entity `json:"entity_pattern" binding:"entity_pattern"`
	CorporateEntityPattern string         `json:"corporate_entity_pattern"`

	CorporatePattern savedpattern.SavedPattern `json:"-"`
}

func (EntityPatternFieldsRequest) ToModel

func (EntityPatternFieldsRequest) ToModelWithoutFields

func (r EntityPatternFieldsRequest) ToModelWithoutFields(forbiddenFields []string) savedpattern.EntityPatternFields

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse is base failed response.

func NewErrorResponse

func NewErrorResponse(err error) ErrorResponse

NewErrorResponse @Failure 500 {object} ErrorResponse

type FieldValidator

type FieldValidator interface {
	Validate(ctx context.Context, sl validator.StructLevel)
}

func NewExistFieldValidator

func NewExistFieldValidator(
	db mongo.DbClient,
	collection string,
	field string,
) FieldValidator

func NewUniqueFieldValidator

func NewUniqueFieldValidator(
	db mongo.DbClient,
	collection string,
	field string,
) FieldValidator

type PaginatedData

type PaginatedData interface {
	GetData() interface{}
	GetTotal() int64
}

PaginatedData provides access to inner data and total count

type PaginatedListResponse

type PaginatedListResponse struct {
	Data interface{}   `json:"data"`
	Meta PaginatedMeta `json:"meta"`
}

PaginatedListResponse is response for paginated list data.

func NewPaginatedResponse

func NewPaginatedResponse(q pagination.Query, d PaginatedData) (PaginatedListResponse, error)

type PaginatedMeta

type PaginatedMeta struct {
	Page       int64 `json:"page"`
	PerPage    int64 `json:"per_page"`
	PageCount  int64 `json:"page_count"`
	TotalCount int64 `json:"total_count"`
}

PaginatedMeta is meta for paginated list data.

func NewPaginatedMeta

func NewPaginatedMeta(q pagination.Query, total int64) (PaginatedMeta, error)

type PatternFieldsTransformer

type PatternFieldsTransformer interface {
	TransformAlarmPatternFieldsRequest(ctx context.Context, r AlarmPatternFieldsRequest) (AlarmPatternFieldsRequest, error)
	TransformEntityPatternFieldsRequest(ctx context.Context, r EntityPatternFieldsRequest) (EntityPatternFieldsRequest, error)
	TransformPbehaviorPatternFieldsRequest(ctx context.Context, r PbehaviorPatternFieldsRequest) (PbehaviorPatternFieldsRequest, error)
	TransformWeatherServicePatternFieldsRequest(ctx context.Context, r WeatherServicePatternFieldsRequest) (WeatherServicePatternFieldsRequest, error)
}

func NewPatternFieldsTransformer

func NewPatternFieldsTransformer(client mongo.DbClient) PatternFieldsTransformer

type PbehaviorPatternFieldsRequest

type PbehaviorPatternFieldsRequest struct {
	PbehaviorPattern          pattern.PbehaviorInfo `json:"pbehavior_pattern" binding:"pbehavior_pattern"`
	CorporatePbehaviorPattern string                `json:"corporate_pbehavior_pattern"`

	CorporatePattern savedpattern.SavedPattern `json:"-"`
}

func (PbehaviorPatternFieldsRequest) ToModel

type ValidationError

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

func NewValidationError

func NewValidationError(field, errMsg string) ValidationError

func (ValidationError) Error

func (v ValidationError) Error() string

func (ValidationError) ValidationErrorResponse

func (v ValidationError) ValidationErrorResponse() ValidationErrorResponse

type ValidationErrorResponse

type ValidationErrorResponse struct {
	Errors map[string]string `json:"errors"`
}

ValidationErrorResponse is response for failed validation.

func TransformValidationErrors

func TransformValidationErrors(errs validator.ValidationErrors, request interface{}) ValidationErrorResponse

type WeatherServicePatternFieldsRequest

type WeatherServicePatternFieldsRequest struct {
	WeatherServicePattern          pattern.WeatherServicePattern `json:"weather_service_pattern" binding:"weather_service_pattern"`
	CorporateWeatherServicePattern string                        `json:"corporate_weather_service_pattern"`

	CorporatePattern savedpattern.SavedPattern `json:"-"`
}

func (WeatherServicePatternFieldsRequest) ToModel

Jump to

Keyboard shortcuts

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