common

package
v0.0.0-...-d841f61 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var ErrTimeoutResponse = ErrorResponse{Error: "Request timeout reached"}
View Source
var ForbiddenResponse = ErrorResponse{Error: "Forbidden"}
View Source
var InternalServerErrorResponse = ErrorResponse{Error: "Internal server error"}
View Source
var NotFoundResponse = ErrorResponse{Error: "Not found"}
View Source
var UnauthorizedResponse = ErrorResponse{Error: "Unauthorized"}

Functions

func GetRealFormatTime

func GetRealFormatTime(f string) string

func GetSortQuery

func GetSortQuery(sortBy, sort string) bson.M

func NewPaginatedResponse

func NewPaginatedResponse(q pagination.Query, d PaginatedData) (interface{}, error)

func NewValidationErrorResponse

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

NewValidationErrorResponse creates response by validation errors.

func ValidateAlarmPatterns

func ValidateAlarmPatterns(sl validator.FieldLevel) bool

func ValidateCpsTimeType

func ValidateCpsTimeType(field reflect.Value) interface{}

ValidateCpsTimeType implements CustomTypeFunc and returns value to validate.

func ValidateFilteredQuery

func ValidateFilteredQuery(sl validator.StructLevel)

func ValidateID

func ValidateID(fl validator.FieldLevel) bool

func ValidateOneOfOrEmpty

func ValidateOneOfOrEmpty(fl validator.FieldLevel) bool

func ValidateTimeFormat

func ValidateTimeFormat(fl validator.FieldLevel) bool

Types

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 ErrorResponse

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

ErrorResponse is base failed response.

func NewErrorResponse

func NewErrorResponse(err error) 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 NewUniqueBulkFieldValidator

func NewUniqueBulkFieldValidator(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.

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.

type ValidationErrorResponse

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

ValidationErrorResponse is response for failed validation.

Jump to

Keyboard shortcuts

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