api

package
v0.0.0-...-dae269f Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package api implements a common handler used by the api routes

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	component.Base
	Dependencies struct {
		Auth *auth.Auth
	}
}

func (*API) HandleRoute

func (a *API) HandleRoute(ctx context.Context, path string) (http.Handler, error)

func (*API) Routes

func (api *API) Routes() component.Routes

type AuthInfo

type AuthInfo struct {
	// User returns the authenticated user.
	// If there is no user, contains the empty string.
	User string

	// Token indicates if the user is authenticated with a token.
	Token bool
}

type Handler

type Handler[T any] struct {
	Config *config.Config
	Auth   *auth.Auth // Handler to handle Auth

	Methods []string // HTTP methods to allow

	Scope      scopes.Scope
	ScopeParam func(*http.Request) string
	Handler    func(string, *http.Request) (T, error)
	// contains filtered or unexported fields
}

Handler represents an API handler that returns a REST response. The response is automatically marshaled using T.

func (*Handler[T]) ServeHTTP

func (handler *Handler[T]) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP servers an api call

type Response

type Response struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
	// contains filtered or unexported fields
}

Response represents a generic response to any request. Response objects cache response serialization

func (*Response) ServeHTTP

func (g *Response) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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