api

package
v0.0.0-...-c7bd76e Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRegisterAuthToken = fmt.Errorf("invalid register auth token")
	ErrInvalidRequestBodyData   = fmt.Errorf("invalid request body data")
	ErrCouldNotInsertToDatabase = fmt.Errorf("could not insert to database")
	ErrWrongLogin               = fmt.Errorf("wrong password or email")
	ErrInvalidHash              = fmt.Errorf("invalid hash")
	ErrImageNotFound            = fmt.Errorf("image not found")
	ErrInvalidJSON              = fmt.Errorf("invalid json body")
)

Functions

This section is empty.

Types

type API

type API struct {
	Router *chi.Mux
	// contains filtered or unexported fields
}

API type represents the API HTTP server with JWT authentication capabilities.

func New

func New(secret, registerAuthToken string, database *db.Database) *API

New creates a new API HTTP server. It does not start the server. Use Start() for that.

func (*API) EnablePrometheusMetrics

func (a *API) EnablePrometheusMetrics(prometheusID string)

EnablePrometheusMetrics enables go-chi prometheus metrics under specified ID. If ID empty, the default "gochi_http" is used.

func (*API) Start

func (a *API) Start(host string, port int)

Start starts the API HTTP server (non blocking).

type HTTPContext

type HTTPContext struct {
	Writer  http.ResponseWriter
	Request *http.Request
}

HTTPContext is the Context for an HTTP request.

func (*HTTPContext) Send

func (h *HTTPContext) Send(msg []byte, httpStatusCode int) error

Send replies the request with the provided message.

func (*HTTPContext) URLParam

func (h *HTTPContext) URLParam(key string) string

URLParam is a wrapper around go-chi to get a URL parameter (specified in the path pattern as {key})

type Image

type Image struct {
	Name string `json:"name"`
	Data []byte `json:"data"`
	Hash string `json:"hash,omitempty"`
}

type Info

type Info struct {
	Users      int               `json:"users"`
	Tools      int               `json:"tools"`
	Categories []db.ToolCategory `json:"categories"`
	Transports []db.Transport    `json:"transports"`
}

type Login

type Login struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

type LoginResponse

type LoginResponse struct {
	Token    string    `json:"token"`
	Expirity time.Time `json:"expirity"`
}

type Register

type Register struct {
	UserEmail         string `json:"email"`
	RegisterAuthToken string `json:"invitationToken"`
	UserProfile
}

type Request

type Request struct {
	Data    []byte
	Path    []string
	Context *HTTPContext
	UserID  string
}

Request represents an HTTP request to the API. It contains the request Body data, the URL path and the HTTP context. The context can be used for obtaining URL parameters and sending responses.

type Response

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

Response is the default response of the API

type ResponseHeader

type ResponseHeader struct {
	Success   bool   `json:"success"`
	Message   string `json:"message,omitempty"`
	ErrorCode int    `json:"errorCode,omitempty"`
}

ResponseHeader is the header of the response

type RouterHandlerFn

type RouterHandlerFn = func(r *Request) (interface{}, error)

RouterHandlerFn is the function signature for adding handlers to the HTTProuter.

type Tool

type Tool struct {
	ID               int64       `json:"id"`
	Title            string      `json:"title"`
	Description      string      `json:"description"`
	MayBeFree        *bool       `json:"mayBeFree"`
	AskWithFee       *bool       `json:"askWithFee"`
	Cost             *uint64     `json:"cost"`
	Images           [][]byte    `json:"images"`
	TransportOptions []int       `json:"transportOptions"`
	Category         int         `json:"category"`
	Location         db.Location `json:"location"`
	EstimatedValue   uint64      `json:"estimatedValue"`
	Height           uint32      `json:"height"`
	Weight           uint32      `json:"weight"`
}

Tool is the type of the tool

type ToolID

type ToolID struct {
	ID int64 `json:"id"`
}

type ToolSearch

type ToolSearch struct {
	Term          string  `json:"term"`
	Categories    []int   `json:"categories"`
	Distance      int     `json:"distance"`
	MaxCost       *uint64 `json:"maxCost"`
	MayBeFree     *bool   `json:"mayBeFree"`
	AvailableFrom int     `json:"availableFrom"`
}

ToolSearch is the type of the tool search

type ToolsWrapper

type ToolsWrapper struct {
	Tools []db.Tool `json:"tools"`
}

type UserProfile

type UserProfile struct {
	Name      string       `json:"name"`
	Community string       `json:"community"`
	Location  *db.Location `json:"location,omitempty"`
	Active    *bool        `json:"active,omitempty"`
	Avatar    []byte       `json:"avatar,omitempty"`
	Password  string       `json:"password,omitempty"`
}

type UsersWrapper

type UsersWrapper struct {
	Users []db.User `json:"users"`
}

Jump to

Keyboard shortcuts

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