handler

package
v0.0.0-...-a659c4b Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	JWTLifetime          = 24 * time.Hour
	RefreshTokenLifetime = 7 * 24 * time.Hour
)
View Source
var (
	ErrNoFileUploaded     = errors.New("no file uploaded")
	ErrFileAlreadyExists  = errors.New("file already exists")
	ErrInvalidLimitRange  = errors.New("limit should be integer in [0..200]")
	ErrInvalidOffsetRange = errors.New("offset should be positive integer")
)
View Source
var (
	ScopeWriteAPIs          = "apis.write"
	ScopeWriteTags          = "tags.write"
	ScopeWriteCategories    = "categories.write"
	ScopeWriteLinks         = "links.write"
	ScopeWriteNotifications = "notifications.write"
	ScopeReadUsers          = "users.read"
	ScopeWriteUsers         = "users.write"
	ScopeReadGroups         = "groups.read"
	ScopeWriteGroups        = "groups.write"
	ScopeReadRoles          = "roles.read"
	ScopeWriteRoles         = "roles.write"
	ScopeWriteConfig        = "config.write"
	ScopeReadScopes         = "scopes.read"

	ScopesAvailable = map[string]string{
		ScopeWriteAPIs:          "update or delete apis",
		ScopeWriteTags:          "update or delete tags",
		ScopeWriteCategories:    "update or delete categories",
		ScopeWriteLinks:         "update or delete links",
		ScopeWriteNotifications: "update or delete notifications",
		ScopeReadUsers:          "read or list users",
		ScopeWriteUsers:         "update or delete users",
		ScopeReadGroups:         "read or list groups",
		ScopeWriteGroups:        "update or delete groups",
		ScopeReadRoles:          "read or list roles",
		ScopeWriteRoles:         "update or delete roles",
		ScopeWriteConfig:        "update or delete configurations",
		ScopeReadScopes:         "list available scopes",
	}
)
View Source
var (
	ErrInvalidUserPassword = errors.New("invalud user password")
)
View Source
var (
	ErrNotificationTypeInvalid = errors.New("notification type is invalid")
)
View Source
var (
	ErrRefreshTokenExpired = errors.New("refresh token has expired")
)

Functions

func CreateObject

func CreateObject[T Object](h *Handler, c echo.Context, object T) error

func DeleteObject

func DeleteObject[T Object](h *Handler, c echo.Context, object T, builder QueryBuilderFunc, associations ...string) error

func GetObject

func GetObject[T Object](h *Handler, c echo.Context, object T, builder QueryBuilderFunc, associations ...string) error

func ListObjects

func ListObjects[T Object](h *Handler, c echo.Context, objects []T, builder QueryBuilderFunc, associations ...string) error

func ReplaceObject

func ReplaceObject[T Object](h *Handler, c echo.Context, object T, builder QueryBuilderFunc, associations ...string) error

Types

type API

type API struct {
	ID          string        `json:"id" gorm:"primary_key;size:36"`
	Title       string        `json:"title"`
	Description string        `json:"description"`
	Visibility  string        `json:"visibility"` // public, internal, private
	Tags        []*Tag        `json:"tags" gorm:"many2many:api_tags"`
	Categories  []*Category   `json:"categories" gorm:"many2many:api_categories"`
	Attachments []*Attachment `json:"attachments" gorm:"foreignKey:ApiID"`
	OwnerUser   string        `json:"owner_user" gorm:"size:36"`
	CreatedAt   time.Time     `json:"created_at"`
	UpdatedAt   time.Time     `json:"updated_at"`
	DeletedAt   *time.Time    `json:"-" sql:"index"`
}

func (*API) Field

func (a *API) Field(field string) any

func (*API) Load

func (a *API) Load(form url.Values, multipartForm *multipart.Form, db *gorm.DB) error

type Attachment

type Attachment struct {
	ID          string     `json:"id" gorm:"primary_key;size:36"`
	ApiID       string     `json:"-" gorm:"size:36"`
	Filename    string     `json:"filename"`
	Size        int64      `json:"size"`
	ContentType string     `json:"-"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
	DeletedAt   *time.Time `json:"-" sql:"index"`
}

func (*Attachment) Field

func (l *Attachment) Field(field string) any

func (*Attachment) Load

func (l *Attachment) Load(form url.Values, multipartForm *multipart.Form, db *gorm.DB) error

type Category

type Category struct {
	ID          string     `json:"id" gorm:"primary_key;size:36"`
	Title       string     `json:"title" gorm:"unique"`
	Description string     `json:"description"`
	APIs        []*API     `json:"-" gorm:"many2many:api_categories"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
	DeletedAt   *time.Time `json:"-" sql:"index"`
}

func (*Category) Field

func (c *Category) Field(field string) any

func (*Category) Load

func (c *Category) Load(form url.Values, multipartForm *multipart.Form, db *gorm.DB) error

type Configuration

type Configuration struct {
	Title         string    `json:"title"`
	Description   string    `json:"description"`
	SigningSecret []byte    `json:"-"`
	CreatedAt     time.Time `json:"-"`
	UpdatedAt     time.Time `json:"-"`
}

func (*Configuration) Field

func (c *Configuration) Field(field string) any

func (*Configuration) Load

func (c *Configuration) Load(form url.Values, db *gorm.DB) error

func (*Configuration) LoadFromDB

func (c *Configuration) LoadFromDB(db *gorm.DB) error

type Document

type Document struct {
	ID          string     `json:"id" gorm:"primary_key;size:36"`
	ApiID       string     `json:"-" gorm:"size:36"`
	Title       string     `json:"title"`
	Description string     `json:"description"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
	DeletedAt   *time.Time `json:"-" sql:"index"`
}

func (*Document) Field

func (d *Document) Field(field string) any

func (*Document) Load

func (d *Document) Load(form url.Values, multipartForm *multipart.Form, db *gorm.DB) error

type Group

type Group struct {
	ID          string     `json:"id" gorm:"primary_key;size:36"`
	Name        string     `json:"name" gorm:"unique"`
	Description string     `json:"description"`
	Users       []*User    `json:"-" gorm:"many2many:user_groups"`
	Roles       []*Role    `json:"roles" gorm:"many2many:group_roles"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
	DeletedAt   *time.Time `json:"-" sql:"index"`
}

func (*Group) Field

func (g *Group) Field(field string) any

func (*Group) Load

func (g *Group) Load(form url.Values, multipartForm *multipart.Form, db *gorm.DB) error

type Handler

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

func New

func New(db *gorm.DB, config *Configuration) (*Handler, error)

func (*Handler) CleanJWTs

func (h *Handler) CleanJWTs() error

func (*Handler) CreateAPI

func (h *Handler) CreateAPI(c echo.Context) error

func (*Handler) CreateAttachment

func (h *Handler) CreateAttachment(c echo.Context) error

func (*Handler) CreateCategory

func (h *Handler) CreateCategory(c echo.Context) error

func (*Handler) CreateDocument

func (h *Handler) CreateDocument(c echo.Context) error

func (*Handler) CreateDocumentFile

func (h *Handler) CreateDocumentFile(c echo.Context) error

func (*Handler) CreateGroup

func (h *Handler) CreateGroup(c echo.Context) error
func (h *Handler) CreateLink(c echo.Context) error

func (*Handler) CreateNotification

func (h *Handler) CreateNotification(c echo.Context) error

func (*Handler) CreateRole

func (h *Handler) CreateRole(c echo.Context) error

func (*Handler) CreateSpecification

func (h *Handler) CreateSpecification(c echo.Context) error

func (*Handler) CreateTag

func (h *Handler) CreateTag(c echo.Context) error

func (*Handler) CreateUser

func (h *Handler) CreateUser(c echo.Context) error

func (*Handler) DeleteAPI

func (h *Handler) DeleteAPI(c echo.Context) error

func (*Handler) DeleteAccount

func (h *Handler) DeleteAccount(c echo.Context) error

func (*Handler) DeleteAttachment

func (h *Handler) DeleteAttachment(c echo.Context) error

func (*Handler) DeleteCategory

func (h *Handler) DeleteCategory(c echo.Context) error

func (*Handler) DeleteDocument

func (h *Handler) DeleteDocument(c echo.Context) error

func (*Handler) DeleteDocumentFile

func (h *Handler) DeleteDocumentFile(c echo.Context) error

func (*Handler) DeleteFileOrDir

func (h *Handler) DeleteFileOrDir(dirname string, filename string) error

func (*Handler) DeleteGroup

func (h *Handler) DeleteGroup(c echo.Context) error

func (*Handler) DeleteJWT

func (h *Handler) DeleteJWT(c echo.Context) error
func (h *Handler) DeleteLink(c echo.Context) error

func (*Handler) DeleteNotification

func (h *Handler) DeleteNotification(c echo.Context) error

func (*Handler) DeleteRole

func (h *Handler) DeleteRole(c echo.Context) error

func (*Handler) DeleteSpecification

func (h *Handler) DeleteSpecification(c echo.Context) error

func (*Handler) DeleteTag

func (h *Handler) DeleteTag(c echo.Context) error

func (*Handler) DeleteUser

func (h *Handler) DeleteUser(c echo.Context) error

func (*Handler) Error

func (h *Handler) Error(c echo.Context, code int, err error) error

func (*Handler) GenerateToken

func (h *Handler) GenerateToken(c echo.Context) error

func (*Handler) GetAPI

func (h *Handler) GetAPI(c echo.Context) error

func (*Handler) GetAPIThumbnail

func (h *Handler) GetAPIThumbnail(c echo.Context) error

func (*Handler) GetAttachment

func (h *Handler) GetAttachment(c echo.Context) error

func (*Handler) GetAttachmentBlob

func (h *Handler) GetAttachmentBlob(c echo.Context) error

func (*Handler) GetBlob

func (h *Handler) GetBlob(c echo.Context, dirname string, filename string) error

func (*Handler) GetCategory

func (h *Handler) GetCategory(c echo.Context) error

func (*Handler) GetConfigurations

func (h *Handler) GetConfigurations(c echo.Context) error

func (*Handler) GetDocument

func (h *Handler) GetDocument(c echo.Context) error

func (*Handler) GetDocumentBlob

func (h *Handler) GetDocumentBlob(c echo.Context) error

func (*Handler) GetDocumentFile

func (h *Handler) GetDocumentFile(c echo.Context) error

func (*Handler) GetGroup

func (h *Handler) GetGroup(c echo.Context) error
func (h *Handler) GetLink(c echo.Context) error

func (*Handler) GetLinkThumbnail

func (h *Handler) GetLinkThumbnail(c echo.Context) error

func (*Handler) GetNotification

func (h *Handler) GetNotification(c echo.Context) error

func (*Handler) GetRole

func (h *Handler) GetRole(c echo.Context) error

func (*Handler) GetSpecification

func (h *Handler) GetSpecification(c echo.Context) error

func (*Handler) GetSpecificationBlob

func (h *Handler) GetSpecificationBlob(c echo.Context) error

func (*Handler) GetTag

func (h *Handler) GetTag(c echo.Context) error

func (*Handler) GetUser

func (h *Handler) GetUser(c echo.Context) error

func (*Handler) GetUserIcon

func (h *Handler) GetUserIcon(c echo.Context) error

func (*Handler) GuestAccess

func (h *Handler) GuestAccess(c echo.Context) bool

func (*Handler) ListAPIs

func (h *Handler) ListAPIs(c echo.Context) error

func (*Handler) ListAttachments

func (h *Handler) ListAttachments(c echo.Context) error

func (*Handler) ListCategories

func (h *Handler) ListCategories(c echo.Context) error

func (*Handler) ListDocumentFiles

func (h *Handler) ListDocumentFiles(c echo.Context) error

func (*Handler) ListDocuments

func (h *Handler) ListDocuments(c echo.Context) error

func (*Handler) ListGroups

func (h *Handler) ListGroups(c echo.Context) error

func (*Handler) ListJWTs

func (h *Handler) ListJWTs(c echo.Context) error
func (h *Handler) ListLinks(c echo.Context) error

func (*Handler) ListNotifications

func (h *Handler) ListNotifications(c echo.Context) error

func (*Handler) ListRoles

func (h *Handler) ListRoles(c echo.Context) error

func (*Handler) ListScopes

func (h *Handler) ListScopes(c echo.Context) error

func (*Handler) ListSpecifications

func (h *Handler) ListSpecifications(c echo.Context) error

func (*Handler) ListTags

func (h *Handler) ListTags(c echo.Context) error

func (*Handler) ListUsers

func (h *Handler) ListUsers(c echo.Context) error

func (*Handler) NotImplemented

func (h *Handler) NotImplemented(c echo.Context) error

func (*Handler) ReplaceAPI

func (h *Handler) ReplaceAPI(c echo.Context) error

func (*Handler) ReplaceAccount

func (h *Handler) ReplaceAccount(c echo.Context) error

func (*Handler) ReplaceAccountIcon

func (h *Handler) ReplaceAccountIcon(c echo.Context) error

func (*Handler) ReplaceCategory

func (h *Handler) ReplaceCategory(c echo.Context) error

func (*Handler) ReplaceConfigurations

func (h *Handler) ReplaceConfigurations(c echo.Context) error

func (*Handler) ReplaceDocument

func (h *Handler) ReplaceDocument(c echo.Context) error

func (*Handler) ReplaceGroup

func (h *Handler) ReplaceGroup(c echo.Context) error
func (h *Handler) ReplaceLink(c echo.Context) error

func (*Handler) ReplaceNotification

func (h *Handler) ReplaceNotification(c echo.Context) error

func (*Handler) ReplaceRole

func (h *Handler) ReplaceRole(c echo.Context) error

func (*Handler) ReplaceSpecification

func (h *Handler) ReplaceSpecification(c echo.Context) error

func (*Handler) ReplaceTag

func (h *Handler) ReplaceTag(c echo.Context) error

func (*Handler) ReplaceUser

func (h *Handler) ReplaceUser(c echo.Context) error

func (*Handler) RequestUser

func (h *Handler) RequestUser(c echo.Context) (*User, error)

func (*Handler) RevokeToken

func (h *Handler) RevokeToken(c echo.Context) error

func (*Handler) SaveFile

func (h *Handler) SaveFile(fileHeader *multipart.FileHeader, dirname string) error

func (*Handler) SaveFormFiles

func (h *Handler) SaveFormFiles(c echo.Context, dirname string) ([]*multipart.FileHeader, error)

func (*Handler) SetAPIThumbnail

func (h *Handler) SetAPIThumbnail(c echo.Context) error

func (*Handler) SetLinkThumbnail

func (h *Handler) SetLinkThumbnail(c echo.Context) error

func (*Handler) SetUserIcon

func (h *Handler) SetUserIcon(c echo.Context) error

func (*Handler) UnsetAPIThumbnail

func (h *Handler) UnsetAPIThumbnail(c echo.Context) error

func (*Handler) UnsetLinkThumbnail

func (h *Handler) UnsetLinkThumbnail(c echo.Context) error

func (*Handler) UnsetUserIcon

func (h *Handler) UnsetUserIcon(c echo.Context) error

func (*Handler) UpdateAccountPassword

func (h *Handler) UpdateAccountPassword(c echo.Context) error

func (*Handler) UpdateUserPassword

func (h *Handler) UpdateUserPassword(c echo.Context) error

func (*Handler) UserScopes

func (h *Handler) UserScopes(userId string) []string

type JWT

type JWT struct {
	ID             string     `json:"id" gorm:"size:36;primarykey"`
	UserID         string     `json:"user_id" gorm:"size:36"`
	Token          string     `json:"-"`
	Expires        int64      `json:"expires"`
	RefreshToken   string     `json:"-"`
	RefreshExpires int64      `json:"refresh_expires"`
	CreatedAt      time.Time  `json:"created_at"`
	DeletedAt      *time.Time `json:"-" gorm:"index"`
}
type Link struct {
	ID          string     `json:"id" gorm:"primary_key;size:36"`
	Title       string     `json:"title"`
	Description string     `json:"description"`
	URL         string     `json:"url"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
	DeletedAt   *time.Time `json:"-" sql:"index"`
}

func (*Link) Field

func (l *Link) Field(field string) any

func (*Link) Load

func (l *Link) Load(form url.Values, multipartForm *multipart.Form, db *gorm.DB) error

type Notification

type Notification struct {
	ID          string     `json:"id" gorm:"primary_key;size:36"`
	Title       string     `json:"title"`
	Description string     `json:"description"`
	Type        string     `json:"type"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
	DeletedAt   *time.Time `json:"-" sql:"index"`
}

func (*Notification) Field

func (n *Notification) Field(field string) any

func (*Notification) Load

func (n *Notification) Load(form url.Values, multipartForm *multipart.Form, db *gorm.DB) error

type Object

type Object interface {
	Load(url.Values, *multipart.Form, *gorm.DB) error
	Field(string) any
}

type QueryBuilderFunc

type QueryBuilderFunc func() (*gorm.DB, error)

type Role

type Role struct {
	ID          string     `json:"id" gorm:"primary_key;size:36"`
	Name        string     `json:"name" gorm:"unique"`
	Description string     `json:"description"`
	Scopes      []*Scope   `json:"scopes" gorm:"many2many:role_scopes"`
	Users       []*User    `json:"-" gorm:"many2many:user_roles"`
	Groups      []*Group   `json:"-" gorm:"many2many:group_roles"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
	DeletedAt   *time.Time `json:"-" sql:"index"`
}

func (*Role) Field

func (r *Role) Field(field string) any

func (*Role) Load

func (r *Role) Load(form url.Values, multipartForm *multipart.Form, db *gorm.DB) error

type Scope

type Scope struct {
	ID          string  `json:"id" gorm:"primary_key;size:36"`
	Name        string  `json:"name"`
	Description string  `json:"description"`
	Roles       []*Role `json:"-" gorm:"many2many:role_scopes"`
}

func (*Scope) Field

func (s *Scope) Field(string) any

func (*Scope) Load

func (s *Scope) Load(url.Values, *multipart.Form, *gorm.DB) error

type Specification

type Specification struct {
	ID          string     `json:"id" gorm:"primary_key;size:36"`
	ApiID       string     `json:"-" gorm:"size:36"`
	Title       string     `json:"title`
	Description string     `json:"description`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
	DeletedAt   *time.Time `json:"-" sql:"index"`
}

func (*Specification) Field

func (s *Specification) Field(field string) any

func (*Specification) Load

func (s *Specification) Load(form url.Values, multipartForm *multipart.Form, db *gorm.DB) error

type Tag

type Tag struct {
	ID        string     `json:"id" gorm:"primary_key;size:36"`
	Name      string     `json:"name" gorm:"unique"`
	APIs      []*API     `json:"-" gorm:"many2many:api_tags"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"-" sql:"index"`
}

func (*Tag) Field

func (t *Tag) Field(field string) any

func (*Tag) Load

func (t *Tag) Load(form url.Values, multipartForm *multipart.Form, db *gorm.DB) error

type User

type User struct {
	ID        string     `json:"id" gorm:"primary_key;size:36"`
	Username  string     `json:"username" gorm:"unique"`
	Email     string     `json:"email" gorm:"unique"`
	Firstname string     `json:"firstname"`
	Lastname  string     `json:"lastname"`
	Password  string     `json:"-"`
	Groups    []*Group   `json:"groups" gorm:"many2many:user_groups"`
	Roles     []*Role    `json:"roles" gorm:"many2many:user_roles"`
	JWTs      []*JWT     `json:"-" gorm:"foreignKey:UserID"`
	APIs      []*API     `json:"-" gorm:"foreignKey:OwnerUser"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"-" sql:"index"`
}

func (*User) Field

func (u *User) Field(field string) any

func (*User) Load

func (u *User) Load(form url.Values, multipartForm *multipart.Form, db *gorm.DB) error

Jump to

Keyboard shortcuts

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