server

package
v0.0.0-...-3df1e6d Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authorizer

type Authorizer interface {
	AuthenticateRead(http.Handler) http.Handler
	AuthenticateWrite(http.Handler) http.Handler
	AuthenticateCreate(http.Handler) http.Handler
}

Authorizer defines a type that can be used to authorize to the API

type Config

type Config struct {
	ListenAddr                 string
	TLSListenAddr              string
	TLS                        *TLSConfig
	TLSOnly                    bool
	ReadAuthToken              string
	WriteAuthToken             string
	AllowPublicCreateGenerated bool // If true, WriteAuthToken is NOT required when creating an entry that does not contain a custom ID
	GeneratedIDLen             int
	Verbose                    bool

	// General backend settings
	PrettyJSON bool

	// File backend settings
	FileBackendPath string
}

Config represents a server config

type DefaultAuthorizer

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

DefaultAuthorizer is the default authorizing middleware

func NewAuthorizer

func NewAuthorizer(readToken string, writeToken string, allowPublicCreateGenerated bool) *DefaultAuthorizer

NewAuthorizer creates a new instance of a default authorizer

func (*DefaultAuthorizer) AuthenticateCreate

func (h *DefaultAuthorizer) AuthenticateCreate(next http.Handler) http.Handler

AuthenticateCreate Authenticates for creating a new entry where it can be possible to only authenticate when creating custom tiny URLs

func (*DefaultAuthorizer) AuthenticateRead

func (h *DefaultAuthorizer) AuthenticateRead(next http.Handler) http.Handler

AuthenticateRead Authenticates for read permissions

func (*DefaultAuthorizer) AuthenticateWrite

func (h *DefaultAuthorizer) AuthenticateWrite(next http.Handler) http.Handler

AuthenticateWrite Authenticates for write permissions

type DefaultHandlers

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

DefaultHandlers implements Handlers with the default implementation

func NewDefaultHandlers

func NewDefaultHandlers(b *business.Logic) (*DefaultHandlers, error)

NewDefaultHandlers creates a new Default handlers instance with provided logic instance

func (*DefaultHandlers) APISpec

func (h *DefaultHandlers) APISpec(res http.ResponseWriter, req *http.Request)

APISpec Shows API spec

func (*DefaultHandlers) CreateTinyURL

func (h *DefaultHandlers) CreateTinyURL(res http.ResponseWriter, req *http.Request)

CreateTinyURL Create a new tiny URL entry

func (*DefaultHandlers) ExpandURL

func (h *DefaultHandlers) ExpandURL(res http.ResponseWriter, req *http.Request)

ExpandURL Get info for the tiny URL ID entry

func (*DefaultHandlers) FollowURL

func (h *DefaultHandlers) FollowURL(res http.ResponseWriter, req *http.Request)

FollowURL Get redirected to full URL

func (*DefaultHandlers) List

func (h *DefaultHandlers) List(res http.ResponseWriter, req *http.Request)

List Lists all tiny URL entries

func (*DefaultHandlers) RemoveTinyURL

func (h *DefaultHandlers) RemoveTinyURL(res http.ResponseWriter, req *http.Request)

RemoveTinyURL Remove a tiny URL entry

func (*DefaultHandlers) UpdateTinyURL

func (h *DefaultHandlers) UpdateTinyURL(res http.ResponseWriter, req *http.Request)

UpdateTinyURL Update a tiny URL entry

type Handlers

type Handlers interface {
	APISpec(http.ResponseWriter, *http.Request)
	List(http.ResponseWriter, *http.Request)
	CreateTinyURL(http.ResponseWriter, *http.Request)
	FollowURL(http.ResponseWriter, *http.Request)
	UpdateTinyURL(http.ResponseWriter, *http.Request)
	ExpandURL(http.ResponseWriter, *http.Request)
	RemoveTinyURL(http.ResponseWriter, *http.Request)
}

Handlers represents the handlers needed for the API

type Server

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

Server represents a server instance

func New

func New(c *Config) (*Server, error)

New creates a new server instance

func (*Server) AddAPIRoutes

func (s *Server) AddAPIRoutes(r *mux.Router, b *business.Logic) error

AddAPIRoutes adds the API routes with default handlers

func (*Server) AddAPIRoutesAndHandlers

func (s *Server) AddAPIRoutesAndHandlers(r *mux.Router, handlers Handlers, auth Authorizer) error

AddAPIRoutesAndHandlers adds the API routes with provided handlers and authorizers

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(handler http.Handler)

ListenAndServe listens for requests and serves them

func (*Server) ListenAndServeAPI

func (s *Server) ListenAndServeAPI(handlers Handlers) error

ListenAndServeAPI sets the API routes only with provided backend and listens for requests and serves them

func (*Server) ListenAndServeFileBackedAPI

func (s *Server) ListenAndServeFileBackedAPI() error

ListenAndServeFileBackedAPI sets the API routes only with a file backend and listens for requests and serves them

type TLSConfig

type TLSConfig struct {
	KeyFile  string
	CertFile string
}

TLSConfig represents a TLS configuration

Jump to

Keyboard shortcuts

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