common

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SymmetricKeyLen = 32

	EventTypeCreate = "create"
	EventTypeUpdate = "update"
	EventTypeDelete = "delete"
)

Variables

View Source
var (
	ErrAuthentication  = errors.New("token authentication failed")
	ErrInvalidDateTime = errors.New("invalid date time format (RFC 3339 needed)")
	ErrKeyLen          = errors.New("PASETO_KEY must be 32 bytes long once base64-decoded")
)

Functions

func CustomErrorHandler

func CustomErrorHandler(ctx *fiber.Ctx, err error) error

func DuplicateField added in v1.1.0

func DuplicateField(err error) *string

DuplicateField reports whether err is a unique constraint violation. Returns nil if it is not. Returns a pointer to the API field name that caused it (e.g. "alternativeId", "codeHosting.url") if it is, or a pointer to an empty string if the field cannot be determined.

func GenerateErrorDetails added in v0.8.0

func GenerateErrorDetails(validationErrors []ValidationError) string

func NormalizeEmail added in v0.5.1

func NormalizeEmail(email *string) *string

func NormalizeURL added in v1.1.0

func NormalizeURL(rawURL string) string

func ValidateRequestEntity added in v0.5.1

func ValidateRequestEntity(ctx *fiber.Ctx, request any, errorMessage string) error

Types

type AnalysisData added in v1.2.0

type AnalysisData map[string]json.RawMessage //nolint:recvcheck

AnalysisData is a map of { namespace: arbitrary JSON object } External software components (scanners, enrichers, security checkers, etc.) write under their own key. Every namespace must have "v" (schema version, int).

func WithTimestamps added in v1.2.0

func WithTimestamps(analysis AnalysisData, now time.Time) (AnalysisData, error)

WithTimestamps checks that each namespace is a JSON object with an integer "v", then injects "t" (current time, RFC 3339).

func (*AnalysisData) Scan added in v1.2.0

func (a *AnalysisData) Scan(value any) error

func (AnalysisData) Value added in v1.2.0

func (a AnalysisData) Value() (driver.Value, error)

type Base64Key

type Base64Key [SymmetricKeyLen]byte

func (*Base64Key) UnmarshalText

func (k *Base64Key) UnmarshalText(text []byte) error

type CatalogPatch added in v1.2.0

type CatalogPatch struct {
	Name                *string        `json:"name" validate:"omitempty,min=1,max=255"`
	AlternativeID       *string        `json:"alternativeId" validate:"omitempty,max=255"`
	Active              *bool          `json:"active"`
	PublishersNamespace *string        `json:"publishersNamespace" validate:"omitempty,max=255"`
	Sources             *[]SourceInput `json:"sources" validate:"omitempty,gt=0,dive"`
}

type CatalogPost added in v1.2.0

type CatalogPost struct {
	Name                string        `json:"name" validate:"required,min=1,max=255"`
	AlternativeID       *string       `json:"alternativeId" validate:"omitempty,min=1,max=255"`
	Active              *bool         `json:"active"`
	PublishersNamespace *string       `json:"publishersNamespace" validate:"omitempty,max=255"`
	Sources             []SourceInput `json:"sources" validate:"required,gt=0,dive"`
}

type CodeHosting

type CodeHosting struct {
	URL   string `json:"url" validate:"required,url"`
	Group *bool  `json:"group"`
}

type Environment

type Environment struct {
	MaxRequests        int        `env:"MAX_REQUESTS" envDefault:"0"`
	CurrentEnvironment string     `env:"ENVIRONMENT" envDefault:"production"`
	Database           string     `env:"DATABASE_DSN"`
	PasetoKey          *Base64Key `env:"PASETO_KEY"`
}
var EnvironmentConfig Environment //nolint:gochecknoglobals

func (*Environment) IsTest

func (e *Environment) IsTest() bool

type Log

type Log struct {
	Message string `json:"message" validate:"required,gt=1"`
}

type ProblemJSONError

type ProblemJSONError struct {
	Code             string            `json:"code,omitempty"`
	Title            string            `json:"title"`
	Detail           string            `json:"detail,omitempty"`
	Status           int               `json:"status"`
	ValidationErrors []ValidationError `json:"validationErrors,omitempty"`
}

func Error

func Error(status int, title string, detail string) ProblemJSONError

func ErrorWithValidationErrors

func ErrorWithValidationErrors(
	status int, title string, validationErrors []ValidationError,
) ProblemJSONError

func InternalServerError added in v0.9.0

func InternalServerError(title string) ProblemJSONError

func (ProblemJSONError) Error

func (pj ProblemJSONError) Error() string

type PublisherPatch added in v0.5.1

type PublisherPatch struct {
	CodeHosting   *[]CodeHosting `json:"codeHosting" validate:"omitempty,gt=0,dive"`
	Description   *string        `json:"description"`
	Email         *string        `json:"email" validate:"omitempty,email"`
	Active        *bool          `json:"active"`
	AlternativeID *string        `json:"alternativeId" validate:"omitempty,max=255"`
}

type PublisherPost added in v0.5.1

type PublisherPost struct {
	CodeHosting   []CodeHosting `json:"codeHosting" validate:"required,gt=0,dive"`
	Description   string        `json:"description" validate:"required"`
	Email         *string       `json:"email" validate:"omitempty,email"`
	Active        *bool         `json:"active"`
	AlternativeID *string       `json:"alternativeId" validate:"omitempty,min=1,max=255"`
}

type Response

type Response struct {
	Data any `json:"data,omitempty"`
}

func NewResponse

func NewResponse(data any) *Response

type SoftwarePatch added in v0.5.0

type SoftwarePatch struct {
	URL           *string   `json:"url" validate:"omitempty,url"`
	Aliases       *[]string `json:"aliases" validate:"omitempty,dive,url"`
	PubliccodeYml *string   `json:"publiccodeYml"`
	Active        *bool     `json:"active"`
	Vitality      *string   `json:"vitality"`
}

type SoftwarePost added in v0.5.0

type SoftwarePost struct {
	URL           string   `json:"url" validate:"required,url"`
	Aliases       []string `json:"aliases" validate:"dive,url"`
	PubliccodeYml string   `json:"publiccodeYml" validate:"required"`
	Active        *bool    `json:"active"`
	Vitality      *string  `json:"vitality"`
}

type SourceInput added in v1.2.0

type SourceInput struct {
	Driver *string  `json:"driver" validate:"omitempty,min=1,max=64"`
	URL    string   `json:"url" validate:"required,url"`
	Args   []string `json:"args" validate:"omitempty,dive,min=1"`
}

type ValidationError

type ValidationError struct {
	Field string `json:"field"`
	Rule  string `json:"rule"`
	Value string `json:"value"`
}

func ValidateStruct

func ValidateStruct(validateStruct any) []ValidationError

type Webhook added in v0.3.0

type Webhook struct {
	URL    string `json:"url" validate:"required,url"`
	Secret string `json:"secret"`
}

Jump to

Keyboard shortcuts

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