models

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Colors = map[ColorName]Color{
		ColorRed: {
			Hex: "#EF4444",
		},
		ColorOrange: {
			Hex: "#F97316",
		},
		ColorYellow: {
			Hex: "#FCD34D",
		},
		ColorGreen: {
			Hex: "#10B981",
		},
		ColorBlue: {
			Hex: "#3B82F6",
		},
		ColorIndigo: {
			Hex: "#6366F1",
		},
		ColorViolet: {
			Hex: "#8B5CF6",
		},
		ColorGray: {
			Hex: "#6B7280",
		},
		ColorBrown: {
			Hex: "#B45309",
		},
		ColorPink: {
			Hex: "#EC4899",
		},
		ColorPurple: {
			Hex: "#9333EA",
		},
	}
	ColorsName = func() (cN []string) {
		for colorName := range Colors {
			cN = append(cN, colorName.String())
		}
		return cN
	}
)
View Source
var (
	ErrNotFound      = errors.New("not found")
	ErrInvalid       = errors.New("invalid")
	ErrIsEmpty       = errors.New("is empty")
	ErrAlreadyExists = errors.New("already exists")
)

Functions

func IsNotFound

func IsNotFound(err error) bool

func IsValidColor

func IsValidColor(name ColorName) (isValid bool, err error)

IsValidColor checks if the color name is valid.

func IsValidUUID

func IsValidUUID(uuid string) bool

IsValidUUID checks if the given string is a valid UUID.

Types

type APIResponse

type APIResponse[T any] struct {
	ID     string            `json:"id" example:"05aebb0d-0169-4bde-bc6d-8662e4680108"` // ID is the unique identifier of the request
	Method string            `json:"method" example:"link.list"`                        // Method is the text representation of the request (link.get)
	Params map[string]string `json:"params" example:"param:value,param2:value2"`        // Params is the parameters of the request
	Data   T                 `json:"data" swaggerignore:"true"`                         // Data is the data of the request
}

type APIResponseError

type APIResponseError[I any] struct {
	ID     string            `json:"id" example:"05aebb0d-0169-4bde-bc6d-8662e4680108"` // ID is the unique identifier of the request
	Method string            `json:"method" example:"link.list"`                        // Method is the text representation of the request (link.get)
	Params map[string]string `json:"params" example:"param:value,param2:value2"`        // Params is the parameters of the request
	Error  I                 `json:"error" swaggerignore:"true"`                        // Error is the error of the request
}

type APIResponseError400

type APIResponseError400 struct {
	Code    int    `json:"code" example:"400"`
	Message string `json:"message" example:"Bad Request"`
}

type APIResponseError404

type APIResponseError404 struct {
	Code    int    `json:"code" example:"404"`
	Message string `json:"message" example:"Not Found"`
}

type APIResponseError409

type APIResponseError409 struct {
	Code    int    `json:"code" example:"409"`
	Message string `json:"message" example:"Conflict"`
}

409 Conflict.

type APIResponseError500

type APIResponseError500 struct {
	Code    int    `json:"code" example:"500"`
	Message string `json:"message" example:"Internal Server Error"`
}

type Color

type Color struct {
	// Hex is the hex code of the color
	Hex string `json:"hex"`
}

Color is the model for the color.

func GetColor

func GetColor(name ColorName) (Color, error)

GetColor returns the color based on the name. return ErrNotFound if the color name is not found.

func GetDefaultColor

func GetDefaultColor() Color

GetDefaultColor returns the default color.

type ColorName

type ColorName string

Name is the name of the color.

const (
	ColorDefault           = ColorGray
	ColorRed     ColorName = "red"
	ColorOrange  ColorName = "orange"
	ColorYellow  ColorName = "yellow"
	ColorGreen   ColorName = "green"
	ColorBlue    ColorName = "blue"
	ColorIndigo  ColorName = "indigo"
	ColorViolet  ColorName = "violet"
	ColorGray    ColorName = "gray"
	ColorBrown   ColorName = "brown"
	ColorPink    ColorName = "pink"
	ColorPurple  ColorName = "purple"
)

func (ColorName) String

func (c ColorName) String() string

String returns the string representation of the name.

type Enabled

type Enabled bool

func (Enabled) String

func (e Enabled) String() string

type Label

type Label struct {
	// ID is the unique identifier of the label
	ID LabelID `json:"id,omitempty" example:"f7c5c4a0-6a1f-4d4b-8a9f-5b5d6d9b8c4d"`
	LabelRequest
}

Label is the model for the label.

func (Label) MarshalJSON

func (l Label) MarshalJSON() ([]byte, error)

MarshalJSON marshal the JSON value.

func (*Label) UnmarshalJSON

func (l *Label) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the JSON value into a LabelID.

func (*Label) Validate

func (l *Label) Validate() error

Validate validates the label. If ID is invalid the ErrInvalid is returned. If Name is empty the ErrIsEmpty is returned. If Color is not found in table the ErrNotFound is returned.

type LabelID

type LabelID string

func (LabelID) String

func (l LabelID) String() string

String returns the string representation of the label ID.

type LabelRequest

type LabelRequest struct {
	// Name is the name of the label
	Name string `json:"name" example:"example" validate:"required"`

	// Color is the color of the label
	// If color is empty, set default color
	Color ColorName `json:"color,omitempty" example:"red" default:"gray" validate:"optional"`
}
type Link struct {
	// ID is the unique identifier of the link in the database
	ID LinkID `json:"id" example:"84214e93-437e-434d-96c2-22c3a63b3c67"`

	// CreatedAt is the time the link was created - RFC3339
	CreatedAt string `json:"createdAt" example:"2021-07-04T15:04:05.999999999Z"`

	// UpdatedAt is the time the link was last modified - RFC3339
	UpdatedAt string `json:"lastModified" example:"2021-07-04T15:04:05.999999999Z"`

	// Namespace is the group the link belongs to
	NameSpace string `json:"namespace" example:"prod"`

	LinkRequest
}

Link is the model for the shortened link.

func (*Link) MarshalJSON

func (l *Link) MarshalJSON() ([]byte, error)

MarshalJSON marshal the JSON value.

func (*Link) UnmarshalJSON

func (l *Link) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the JSON value into a LinkID.

func (*Link) Validate

func (l *Link) Validate() error

Validate validates the link.

type LinkID

type LinkID string

func (LinkID) String

func (l LinkID) String() string

String returns the string representation of the link ID.

type LinkRequest

type LinkRequest struct {
	// Name is the name of the link
	Name string `json:"name" example:"example" validate:"required"`

	// SourcePath is the path of the link
	SourcePath string `json:"sourcePath" example:"/example" validate:"required"`

	// TargetURL is the original URL
	TargetURL string `json:"targetUrl" example:"https://example.com" validate:"required"`

	// Labels is the list of labels associated with the link
	Labels []LabelID `json:"labels,omitempty" example:"a54abdd8-776c-4982-bba7-34caa58596c4,fcb0726f-9701-492c-afe7-aa7121afc9cf"`

	// Enabled is the status of the link
	Enabled Enabled `json:"enabled" example:"true" validate:"required"`
}

LinkRequest is the model for the link request.

type Model

type Model interface {
	Validate() error
	MarshalJSON() ([]byte, error)
	UnmarshalJSON([]byte) error
}

type Namespace

type Namespace struct {
	NamespaceRequest

	// Links is the list of links associated with the namespace
	Links []Link `json:"links"`

	// Enabled is the status of the namespace
	Enabled Enabled `json:"enabled"`
}

Namespace is the model for the namespace.

func (*Namespace) MarshalJSON

func (g *Namespace) MarshalJSON() ([]byte, error)

MarshalJSON marshal the JSON value.

func (*Namespace) UnmarshalJSON

func (g *Namespace) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the JSON value into a NamespaceID.

func (*Namespace) Validate

func (g *Namespace) Validate() error

Validate validates the namespace.

type NamespaceRequest

type NamespaceRequest struct {
	// Name is the name of the namespace
	Name string `json:"name"`
}

func (*NamespaceRequest) Validate

func (g *NamespaceRequest) Validate() error

Validate validates the namespace request.

Jump to

Keyboard shortcuts

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