server

package
v0.0.0-...-c42bc8f Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPMethod

type HTTPMethod string

HTTPMethod wraps all HTTP methods valid for a route

const (
	GET     HTTPMethod = "GET"
	HEAD    HTTPMethod = "HEAD"
	POST    HTTPMethod = "POST"
	PUT     HTTPMethod = "PUT"
	DELETE  HTTPMethod = "DELETE"
	CONNECT HTTPMethod = "CONNECT"
	OPTIONS HTTPMethod = "OPTIONS"
	TRACE   HTTPMethod = "TRACE"
	PATCH   HTTPMethod = "PATCH"
)

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods

func (HTTPMethod) String

func (h HTTPMethod) String() string

String converts HTTP method to string

type Option

type Option func(o *Options)

Option is a functional way of setting options for the server

func WithDirectory

func WithDirectory(dir directory.Service) Option

WithDirectory sets the Directory Service

func WithLogger

func WithLogger(l *zap.Logger) Option

WithLogger sets a logger on the Options struct

func WithOAuth

func WithOAuth(oAuth oauth.Service) Option

WithOAuth sets the OAuth service

func WithPort

func WithPort(p int) Option

WithPort sets the port for the server to boot up

func WithRole

func WithRole(r role.Service) Option

WithRole sets the Role Service

func WithRouter

func WithRouter(r *mux.Router) Option

WithRouter sets a router on the Options struct

type Options

type Options struct {
	Router    *mux.Router
	Logger    *zap.Logger
	Port      int
	OAuth     oauth.Service
	Directory directory.Service
	Role      role.Service
}

Options contain all server options

type Route

type Route struct {
	Path        string
	HandlerFunc func(http.ResponseWriter, *http.Request)
	Method      HTTPMethod
	// Accepts pairs of query values as a slice of strings
	Queries []string
}

Route wraps a route

type Server

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

Server runs a HTTP server with some helpers

func New

func New(setOpts ...Option) (*Server, error)

New returns a new instance of the server

func (*Server) CallbackHandler

func (s *Server) CallbackHandler(w http.ResponseWriter, req *http.Request)

CallbackHandler handles the OAuth callback https://developers.google.com/identity/protocols/OAuth2WebServer

func (*Server) CredentialHandler

func (s *Server) CredentialHandler(w http.ResponseWriter, req *http.Request)

CredentialHandler takes in a client access token, validates it, and then returns a set of credentials

func (*Server) HealthHandler

func (s *Server) HealthHandler(w http.ResponseWriter, req *http.Request)

HealthHandler is a health check endpoint that just returns a 200 to show the server is now alive and handling traffic.

func (*Server) LoginHandler

func (s *Server) LoginHandler(w http.ResponseWriter, req *http.Request)

LoginHandler redirects a client to the Google OAuth login page

func (*Server) RegisterRoute

func (s *Server) RegisterRoute(r *Route)

RegisterRoute registers a single route

func (*Server) RegisterRoutes

func (s *Server) RegisterRoutes(rs ...*Route)

RegisterRoutes registers multiple routes

func (*Server) Run

func (s *Server) Run() error

Run starts up the server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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