handlers

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2021 License: MPL-2.0-no-copyleft-exception Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const SessionUsername = "username"

SessionUsername is the name of the session key that contains our username value.

Variables

View Source
var AllowOrigin = "*"

AllowOrigin changes the scope of CORS requests. By default they are insecure; this is intended to be overrided by commands as they set up this library along with their other standard init operations.

View Source
var ErrRedirect = errors.New("redirection")

ErrRedirect indicates that the error intends to redirect the user to the proper spot.

Functions

func Boot

func Boot(t *transport.HTTP, handler *H, finished chan struct{}) (chan struct{}, error)

Boot boots the service. Closing the channel returned will shutdown the service. At shutdown time, this routine will close the finished channel when it is finished shutting everything down, so the program can safely terminate.

func CORS

func CORS(ctx *gin.Context)

CORS primes OPTIONS and normal requests with the appropriate headers and also acts like a normal http.Handler so it can be used that way.

func TransformSwaggerRoute

func TransformSwaggerRoute(route string) string

TransformSwaggerRoute merely translates url params from {thisformat} to :thisformat

Types

type H

type H struct {
	Config HandlerConfig `yaml:"-"`
	Routes Routes        `yaml:"-"`

	config.UserConfig `yaml:",inline"`
	config.Service
}

H is a series of HTTP handlers for the UI service

func (*H) CreateClients

func (h *H) CreateClients() error

CreateClients creates the clients to be used based on configuration values.

func (*H) CreateRouter

func (h *H) CreateRouter() (*gin.Engine, error)

CreateRouter creates a *mux.Router capable of serving the UI server.

func (*H) CreateTransport

func (h *H) CreateTransport() (*transport.HTTP, error)

CreateTransport creates a transport with optional certification information.

func (*H) GetClient

func (h *H) GetClient(ctx *gin.Context) (github.Client, error)

GetClient returns a github client that works with the credentials in the given context.

func (*H) GetGithub

func (h *H) GetGithub(ctx *gin.Context) (u *model.User, outErr error)

GetGithub gets the github user from the session and loads it.

func (*H) GetUser

func (h *H) GetUser(ctx *gin.Context) (*model.User, error)

GetUser retrieves the user based on information in the gin context.

func (*H) GithubClient

func (h *H) GithubClient(token *types.OAuthToken) github.Client

GithubClient is a wrapper for config.GithubClient.

func (*H) Init

func (h *H) Init() error

Init initialize the handler and makes it available for requests.

func (*H) LogError

func (h *H) LogError(err error, ctx *gin.Context, code int)

LogError logs an HTTP error to the client.

func (*H) NewTracingSpan

func (h *H) NewTracingSpan(ctx *gin.Context, operation string) opentracing.Span

NewTracingSpan creates a new tracepoint span for opentracing instrumentation.

func (*H) OAuthRedirect

func (h *H) OAuthRedirect(ctx *gin.Context, scopes []string) error

OAuthRedirect redirects the user to the OAuth redirection URL.

func (*H) Session

func (h *H) Session(ctx *gin.Context) sessions.Session

Session returns the current user session.

func (*H) WriteError

func (h *H) WriteError(ctx *gin.Context, err error)

WriteError standardizes the writing of error states for easier typing. It is not intended to be used to write specific statuses, only 500 errors with JSON output. If UseSessions is on, it will populate the errors session store.

type HandlerConfig

type HandlerConfig interface {
	SetRoutes(*H)
	DBConfigure(*H) error
	Configure(Routes) error
	CustomInit(*H) error
	Validate(*H) error
}

HandlerConfig provides an interface to managing the HandlerConfig.

type HandlerFunc

type HandlerFunc func(context.Context, *H, *gin.Context) (interface{}, int, error)

HandlerFunc is the basic kind of HandlerFunc.

type Route

type Route struct {
	Method             string
	UseCORS            bool
	UseAuth            bool
	WebsocketProcessor WebsocketFunc
	Handler            func(*H, *gin.Context, HandlerFunc) error
	Processor          HandlerFunc
	ParamValidator     func(*H, *gin.Context) error
	Capability         model.Capability
	TokenScope         string
}

Route is a route management struct for generated services.

type Routes

type Routes map[string]map[string]*Route

Routes is a collection of Route structs.

func (Routes) SetProcessor

func (r Routes) SetProcessor(route string, method string, processor HandlerFunc)

SetProcessor allows you to more simply set the processor for a given route.

func (Routes) SetWebsocketProcessor

func (r Routes) SetWebsocketProcessor(route string, processor WebsocketFunc)

SetWebsocketProcessor allows you to more simply set the processor for a given route.

type WebsocketFunc

type WebsocketFunc func(context.Context, *H, *gin.Context, *websocket.Conn) error

WebsocketFunc is the controller for websocket operations.

Jump to

Keyboard shortcuts

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