api

package
v0.0.0-...-6d50a0b Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const ERROR_BASE_URL = "http://edrlab.org/pubstore/error/"

Error types

View Source
const SERVER_ERROR = ERROR_BASE_URL + "server"

Variables

View Source
var ErrNotFound = &ErrResponse{
	HTTPStatusCode: 404,
	Type:           "about:blank",
	Title:          "Resource not found.",
}

Functions

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

func ErrRender

func ErrRender(err error) render.Renderer

func ErrServer

func ErrServer(err error) render.Renderer

func NewPublicationListResponse

func NewPublicationListResponse(publications []stor.Publication) []render.Renderer

NewPublicationListResponse creates a rendered list of publications

func NewUserListResponse

func NewUserListResponse(users []stor.User) []render.Renderer

NewUserListResponse creates a rendered list of users

Types

type Api

type Api struct {
	*conf.Config
	*stor.Store
}

func Init

func Init(c *conf.Config, s *stor.Store) Api

func (*Api) Router

func (a *Api) Router(r chi.Router)

type ErrResponse

type ErrResponse struct {
	//not serialized
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code
	//mandatory
	Type  string `json:"type"`
	Title string `json:"title"`
	//optional
	Detail   string `json:"detail,omitempty"` // application-level error message
	Instance string `json:"instance,omitempty"`
}

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

type Pagination

type Pagination struct {
	Page     int
	PageSize int
}

Pagination defines a page and pageSize, used for api pagination

type PublicationRequest

type PublicationRequest struct {
	*stor.Publication
}

PublicationRequest is the request publication payload.

func (*PublicationRequest) Bind

func (p *PublicationRequest) Bind(r *http.Request) error

Bind post-processes requests after unmarshalling.

type PublicationResponse

type PublicationResponse struct {
	*stor.Publication
	// do not serialize the following properties
	ID        omit `json:"ID,omitempty"`
	CreatedAt omit `json:"CreatedAt,omitempty"`
	UpdatedAt omit `json:"UpdatedAt,omitempty"`
	DeletedAt omit `json:"DeletedAt,omitempty"`
}

PublicationResponse is the response publication payload.

func NewPublicationResponse

func NewPublicationResponse(pub *stor.Publication) *PublicationResponse

NewPublicationResponse creates a rendered publication.

func (*PublicationResponse) Render

Render processes responses before marshalling.

type UserRequest

type UserRequest struct {
	*stor.User
}

UserRequest is the request user payload.

func (*UserRequest) Bind

func (p *UserRequest) Bind(r *http.Request) error

Bind post-processes requests after unmarshalling.

type UserResponse

type UserResponse struct {
	*stor.User
	// do not serialize the following properties
	ID          omit `json:"ID,omitempty"`
	CreatedAt   omit `json:"CreatedAt,omitempty"`
	UpdatedAt   omit `json:"UpdatedAt,omitempty"`
	DeletedAt   omit `json:"DeletedAt,omitempty"`
	Password    omit `json:"password,omitempty"`
	Passphrase  omit `json:"passphrase,omitempty"`
	HPassword   omit `json:"hpassword,omitempty"`
	HPassphrase omit `json:"hpassphrase,omitempty"`
}

UserResponse is the response user payload.

func NewUserResponse

func NewUserResponse(user *stor.User) *UserResponse

NewUserResponse creates a rendered user.

func (*UserResponse) Render

func (pub *UserResponse) Render(w http.ResponseWriter, r *http.Request) error

Render processes responses before marshalling.

Jump to

Keyboard shortcuts

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