middleware

package
v1.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachApiClient

func AttachApiClient(client remote.Client) gin.HandlerFunc

AttachApiClient attaches the application API client which allows routes to access server resources from the Panel easily.

func AttachRequestID

func AttachRequestID() gin.HandlerFunc

AttachRequestID attaches a unique ID to the incoming HTTP request so that any errors that are generated or returned to the client will include this reference allowing for an easier time identifying the specific request that failed for the user.

If you are using a tool such as Sentry or Bugsnag for error reporting this is a great location to also attach this request ID to your error handling logic so that you can easily cross-reference the errors.

func AttachServerManager

func AttachServerManager(m *server.Manager) gin.HandlerFunc

AttachServerManager attaches the server manager to the request context which allows routes to access the underlying server collection.

func CaptureAndAbort

func CaptureAndAbort(c *gin.Context, err error)

CaptureAndAbort aborts the request and attaches the provided error to the gin context, so it can be reported properly. If the error is missing a stacktrace at the time it is called the stack will be attached.

func CaptureErrors

func CaptureErrors() gin.HandlerFunc

CaptureErrors is custom handler function allowing for errors bubbled up by c.Error() to be returned in a standardized format with tracking UUIDs on them for easier log searching.

func ExtractApiClient

func ExtractApiClient(c *gin.Context) remote.Client

ExtractApiClient returns the API client defined for the routes.

func ExtractLogger

func ExtractLogger(c *gin.Context) *log.Entry

ExtractLogger pulls the logger out of the request context and returns it. By default this will include the request ID, but may also include the server ID if that middleware has been used in the chain by the time it is called.

func ExtractManager

func ExtractManager(c *gin.Context) *server.Manager

ExtractManager returns the server manager instance set on the request context.

func ExtractServer

func ExtractServer(c *gin.Context) *server.Server

ExtractServer will return the server from the gin.Context or panic if it is not present.

func RemoteDownloadEnabled

func RemoteDownloadEnabled() gin.HandlerFunc

RemoteDownloadEnabled checks if remote downloads are enabled for this instance and if not aborts the request.

func RequireAuthorization

func RequireAuthorization() gin.HandlerFunc

RequireAuthorization authenticates the request token against the given permission string, ensuring that if it is a server permission, the token has control over that server. If it is a global token, this will ensure that the request is using a properly signed global token.

func ServerExists

func ServerExists() gin.HandlerFunc

ServerExists will ensure that the requested server exists in this setup. Returns a 404 if we cannot locate it. If the server is found it is set into the request context, and the logger for the context is also updated to include the server ID in the fields list.

func SetAccessControlHeaders

func SetAccessControlHeaders() gin.HandlerFunc

SetAccessControlHeaders sets the access request control headers on all of the requests.

Types

type RequestError

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

RequestError is a custom error type returned when something goes wrong with any of the HTTP endpoints.

func NewError

func NewError(err error) *RequestError

NewError returns a new RequestError for the provided error.

func (*RequestError) Abort

func (re *RequestError) Abort(c *gin.Context, status int)

Abort aborts the given HTTP request with the specified status code and then logs the event into the logs. The error that is output will include the unique request ID if it is present.

func (*RequestError) Cause

func (re *RequestError) Cause() error

Cause returns the underlying error.

func (*RequestError) Error

func (re *RequestError) Error() string

Error returns the underlying error message for this request.

func (*RequestError) SetMessage

func (re *RequestError) SetMessage(m string)

SetMessage allows for a custom error message to be set on an existing RequestError instance.

func (*RequestError) SetStatus

func (re *RequestError) SetStatus(s int)

SetStatus sets the HTTP status code for the error response. By default this is a HTTP-500 error.

Jump to

Keyboard shortcuts

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