server

package
v0.0.0-...-ec15290 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbortWithError

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

AbortWithError aborts a Gin context and sends a response with an error message. Pass an ErrorResponse object to be able to customize the status code; it defaults to 500 otherwise. If the status code is >= 500, the message is not sent to users directly.

func AbortWithErrorJSON

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

AbortWithErrorJSON aborts a Gin context and sends a response with a JSON error message. Pass an ErrorResponse object to be able to customize the status code; it defaults to 500 otherwise. If the status code is >= 500, the message is not sent to users directly.

Types

type GetAPIVerifyResponse

type GetAPIVerifyResponse struct {
	Valid  bool           `json:"valid"`
	Claims map[string]any `json:"claims"`
}

GetAPIVerifyResponse is the response from RouteGetAPIVerify

type NewServerOpts

type NewServerOpts struct {
	Log  *zerolog.Logger
	Auth auth.Provider
	// contains filtered or unexported fields
}

NewServerOpts contains options for the NewServer method

type ResponseError

type ResponseError struct {
	// Error message
	Message string
	// Status code
	Code int
}

ResponseError is used to send JSON responses with an error

func NewResponseError

func NewResponseError(code int, message string) ResponseError

NewResponseError creates a new ErrorResponse with the code and message

func NewResponseErrorf

func NewResponseErrorf(code int, messageFmt string, args ...any) ResponseError

NewResponseErrorf creates a new ErrorResponse with the code and formatted message

func (ResponseError) Error

func (e ResponseError) Error() string

Error implements the error interface

func (ResponseError) MarshalJSON

func (e ResponseError) MarshalJSON() ([]byte, error)

MarshalJSON implements a JSON marshaller that returns an object with the error key

type Server

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

Server is the server based on Gin

func NewServer

func NewServer(opts NewServerOpts) (*Server, error)

NewServer creates a new Server object and initializes it

func (*Server) MiddlewareLoadAuthCookie

func (s *Server) MiddlewareLoadAuthCookie(c *gin.Context)

MiddlewareLoadAuthCookie is a middleware that checks if the request contains a valid authentication token in the cookie.

func (*Server) MiddlewareLogger

func (s *Server) MiddlewareLogger(parentLog *zerolog.Logger) func(c *gin.Context)

MiddlewareLogger is a Gin middleware that uses zerlog for logging

func (*Server) MiddlewareLoggerMask

func (s *Server) MiddlewareLoggerMask(exp *regexp.Regexp, replace string) gin.HandlerFunc

MiddlewareLoggerMask returns a Gin middleware that adds the "log-mask" to mask the path using a regular expression

func (*Server) MiddlewareProxyHeaders

func (s *Server) MiddlewareProxyHeaders(c *gin.Context)

MiddlewareProxyHeaders is a middleware that gets values for source IP and port from the headers set by Traefik. It stops the request if the headers aren't set. This middleware should be used first in the chain.

func (*Server) MiddlewareRequestId

func (s *Server) MiddlewareRequestId(c *gin.Context)

MiddlewareRequestId is a middleware that generates a unique request ID for each request

func (*Server) MiddlewareRequireClientCertificate

func (s *Server) MiddlewareRequireClientCertificate(c *gin.Context)

MiddlewareRequireClientCertificate is a middleware that requires a valid client certificate to be present. This is meant to be used to enforce mTLS on specific routes, when the server's TLS is configured with VerifyClientCertIfGiven.

func (*Server) RouteGetAPIVerify

func (s *Server) RouteGetAPIVerify(c *gin.Context)

RouteGetAPIVerify is the handler for GET /api/verify This API validates a token and returns the list of claims The token can be passed in the Authorization header or in the session cookie

func (*Server) RouteGetLogout

func (s *Server) RouteGetLogout(c *gin.Context)

RouteGetLogout is the handler for GET /logout This removes the session cookie

func (*Server) RouteGetOAuth2Callback

func (s *Server) RouteGetOAuth2Callback(provider auth.OAuth2Provider) func(c *gin.Context)

RouteGetOAuth2Callback is the handler for GET /oauth2/callback when using an OAuth2-based provider This handles redirects from OAuth2 identity providers after successful callbacks

func (*Server) RouteGetOAuth2Root

func (s *Server) RouteGetOAuth2Root(provider auth.OAuth2Provider) func(c *gin.Context)

RouteGetOAuth2Root is the handler for GET / when using an OAuth2-based provider This handles requests from Traefik and redirects users to auth servers if needed

func (*Server) RouteGetProfile

func (s *Server) RouteGetProfile(c *gin.Context)

RouteGetProfile is the handler for GET /profile This handler serves the profile of authenticated users in clear-text

func (*Server) RouteGetSeamlessAuthRoot

func (s *Server) RouteGetSeamlessAuthRoot(provider auth.SeamlessProvider) func(c *gin.Context)

RouteGetSeamlessAuthRoot is the handler for GET / when using a seamless auth provider This handles requests from Traefik

func (*Server) RouteHealthzHandler

func (s *Server) RouteHealthzHandler(w http.ResponseWriter, r *http.Request)

RouteHealthzHandler is the handler for the route GET /healthz - as a http.Handler. It can be used to ping the server and ensure everything is working.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run the web server Note this function is blocking, and will return only when the servers are shut down via context cancellation.

Jump to

Keyboard shortcuts

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