handlers

package
v0.0.0-...-ebd6d4f Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package handlers defines available HTTP handlers

Index

Constants

View Source
const AuthorizationCtxKey contextKey = 0

AuthorizationCtxKey is the key for the authorization value that is passed to the context, when the authentication middleware is used.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountHandler

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

func NewAccountHandler

func NewAccountHandler(accountService *services.AccountService) *AccountHandler

func (*AccountHandler) Activate

func (h *AccountHandler) Activate(w http.ResponseWriter, r *http.Request) error

Handle API endpoint for activating an account. This endpoint should be protected with an account activation token.

func (*AccountHandler) Create

Handle API endpoint for creating a new account.

func (*AccountHandler) GetAccountByID

func (h *AccountHandler) GetAccountByID(w http.ResponseWriter, r *http.Request) error

Handle API endpoint for getting account information.

func (*AccountHandler) GetCloudFeedAuthStatuses

func (h *AccountHandler) GetCloudFeedAuthStatuses(w http.ResponseWriter, r *http.Request) error

Handle API endpoint for getting connected cloud feed auths.

type AdminHandler

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

AdminHandler can be used in an RPC server. It also has an HTTP middleware to verify admin tokens with admin accounts.

func NewAdminHandler

func NewAdminHandler(service *services.AdminService) *AdminHandler

func (*AdminHandler) Create

func (h *AdminHandler) Create(admin admin.Admin, token *string) error

func (*AdminHandler) Delete

func (h *AdminHandler) Delete(admin admin.Admin, reply *admin.Admin) error

func (*AdminHandler) List

func (h *AdminHandler) List(input int, reply *[]admin.Admin) error

func (*AdminHandler) Middleware

func (h *AdminHandler) Middleware(next Handler) Handler

HTTP middleware to check if admin in admin auth token is valid.

func (*AdminHandler) Reactivate

func (h *AdminHandler) Reactivate(admin admin.Admin, reply *admin.Admin) error

func (*AdminHandler) SetExpiry

func (h *AdminHandler) SetExpiry(admin admin.Admin, reply *admin.Admin) error

type AppHandler

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

func NewAppHandler

func NewAppHandler(service *services.AppService) *AppHandler

func (*AppHandler) Create

func (h *AppHandler) Create(w http.ResponseWriter, r *http.Request) error

type AuthorizationHandler

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

func NewAuthorizationHandler

func NewAuthorizationHandler(service *services.AuthorizationService) *AuthorizationHandler

Create a new AuthorizationHandler.

func (*AuthorizationHandler) Middleware

func (h *AuthorizationHandler) Middleware(kind authorization.AuthKind) func(next Handler) Handler

type BuildingHandler

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

func NewBuildingHandler

func NewBuildingHandler(service *services.BuildingService) *BuildingHandler

Create a new BuildingHandler.

func (*BuildingHandler) GetBuildingByID

func (h *BuildingHandler) GetBuildingByID(w http.ResponseWriter, r *http.Request) error

Handle API endpoint for getting building information.

type CampaignHandler

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

func NewCampaignHandler

func NewCampaignHandler(service *services.CampaignService) *CampaignHandler

Create a new CampaignHandler.

func (*CampaignHandler) Create

Handle API endpoint for creating a new campaign.

type CloudFeedAuthHandler

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

func NewCloudFeedAuthHandler

func NewCloudFeedAuthHandler(service *services.CloudFeedAuthService) *CloudFeedAuthHandler

Create a new CloudFeedAuthHandler.

func (*CloudFeedAuthHandler) Create

Handle API endpoint for creating a new cloud feed.

func (*CloudFeedAuthHandler) Download

func (h *CloudFeedAuthHandler) Download(args DownloadArgs, reply *string) error

Handle RPC endpoint for downloading data from a cloud feed.

type CloudFeedHandler

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

func NewCloudFeedHandler

func NewCloudFeedHandler(service *services.CloudFeedService) *CloudFeedHandler

Create a new CloudFeedHandler.

func (*CloudFeedHandler) Create

Handle API endpoint for creating a new cloud feed.

type DeviceHandler

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

func NewDeviceHandler

func NewDeviceHandler(service *services.DeviceService) *DeviceHandler

Create a new DeviceHandler.

func (*DeviceHandler) Activate

func (h *DeviceHandler) Activate(w http.ResponseWriter, r *http.Request) error

Handle API endpoint for activating a device.

func (*DeviceHandler) Create

Handle API endpoint for creating a new device.

func (*DeviceHandler) GetDeviceByName

func (h *DeviceHandler) GetDeviceByName(w http.ResponseWriter, r *http.Request) error

Handle API endpoint for getting device information.

func (*DeviceHandler) GetDeviceMeasurements

func (h *DeviceHandler) GetDeviceMeasurements(w http.ResponseWriter, r *http.Request) error

Handle API endpoint for getting device measurements

func (*DeviceHandler) GetDeviceProperties

func (h *DeviceHandler) GetDeviceProperties(w http.ResponseWriter, r *http.Request) error

Handle API endpoint for getting device properties

type DeviceTypeHandler

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

func NewDeviceTypeHandler

func NewDeviceTypeHandler(service *services.DeviceTypeService) *DeviceTypeHandler

Create a new DeviceTypeHandler.

func (*DeviceTypeHandler) Create

Handle API endpoint for creating a new device type.

type DocsHandler

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

func NewDocsHandler

func NewDocsHandler(files fs.FS, baseURL string) (*DocsHandler, error)

Create a new DocsHandler.

func (*DocsHandler) OpenAPISpec

func (h *DocsHandler) OpenAPISpec(w http.ResponseWriter, r *http.Request) error

Handle API endpoint for displaying OpenAPI spec. This file should be displayed as openapi.yml.

func (*DocsHandler) RedirectDocs

func (h *DocsHandler) RedirectDocs(redirectCode int) func(http.ResponseWriter, *http.Request) error

Handle redirection from /docs to /docs/ to serve static files.

type DownloadArgs

type DownloadArgs struct {
	AccountID   uint
	CloudFeedID uint
	StartPeriod time.Time
	EndPeriod   time.Time
}

type Handler

type Handler func(http.ResponseWriter, *http.Request) error

Handler is an HTTP handler that returns an error.

func (Handler) ServeHTTP

func (fn Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Implement the http.Handler interface.

type HandlerError

type HandlerError struct {
	Err             error
	ResponseMessage string
	ResponseCode    int
	LogMessage      string
	LogLevel        logrus.Level
}

A HandlerError contains information about an error that occured inside a Handler.

func InternalServerError

func InternalServerError(err error) *HandlerError

Helper function to easily create a HandlerError with status 500 (internal server error).

func NewHandlerError

func NewHandlerError(err error, responseMessage string, responseCode int) *HandlerError

Create a new HandlerError. The log level will be set to info.

func (HandlerError) Error

func (e HandlerError) Error() string

Returns the error message.

func (HandlerError) Log

func (e HandlerError) Log()

Log the HandlerError with according level.

func (*HandlerError) WithLevel

func (e *HandlerError) WithLevel(level logrus.Level) *HandlerError

Set the log level of a HandlerError.

func (*HandlerError) WithMessage

func (e *HandlerError) WithMessage(message string) *HandlerError

Set the log message of a HandlerError.

type UploadHandler

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

func NewUploadHandler

func NewUploadHandler(service *services.UploadService) *UploadHandler

Create a new UploadHandler.

func (*UploadHandler) Create

Handle API endpoint for creating a new upload.

Jump to

Keyboard shortcuts

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