Documentation ¶
Index ¶
- func AttachApiClient(client remote.Client) gin.HandlerFunc
- func AttachRequestID() gin.HandlerFunc
- func AttachServerManager(m *server.Manager) gin.HandlerFunc
- func CaptureAndAbort(c *gin.Context, err error)
- func CaptureErrors() gin.HandlerFunc
- func ExtractApiClient(c *gin.Context) remote.Client
- func ExtractLogger(c *gin.Context) *log.Entry
- func ExtractManager(c *gin.Context) *server.Manager
- func ExtractServer(c *gin.Context) *server.Server
- func RemoteDownloadEnabled() gin.HandlerFunc
- func RequireAuthorization() gin.HandlerFunc
- func ServerExists() gin.HandlerFunc
- func SetAccessControlHeaders() gin.HandlerFunc
- type RequestError
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 ¶
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 ¶
ExtractApiClient returns the API client defined for the routes.
func ExtractLogger ¶
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 ¶
ExtractManager returns the server manager instance set on the request context.
func ExtractServer ¶
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.