Documentation ¶
Index ¶
- type Authorizer
- type Config
- type DefaultAuthorizer
- type DefaultHandlers
- func (h *DefaultHandlers) APISpec(res http.ResponseWriter, req *http.Request)
- func (h *DefaultHandlers) CreateTinyURL(res http.ResponseWriter, req *http.Request)
- func (h *DefaultHandlers) ExpandURL(res http.ResponseWriter, req *http.Request)
- func (h *DefaultHandlers) FollowURL(res http.ResponseWriter, req *http.Request)
- func (h *DefaultHandlers) List(res http.ResponseWriter, req *http.Request)
- func (h *DefaultHandlers) RemoveTinyURL(res http.ResponseWriter, req *http.Request)
- func (h *DefaultHandlers) UpdateTinyURL(res http.ResponseWriter, req *http.Request)
- type Handlers
- type Server
- func (s *Server) AddAPIRoutes(r *mux.Router, b *business.Logic) error
- func (s *Server) AddAPIRoutesAndHandlers(r *mux.Router, handlers Handlers, auth Authorizer) error
- func (s *Server) ListenAndServe(handler http.Handler)
- func (s *Server) ListenAndServeAPI(handlers Handlers) error
- func (s *Server) ListenAndServeFileBackedAPI() error
- type TLSConfig
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 (*Server) AddAPIRoutes ¶
AddAPIRoutes adds the API routes with default handlers
func (*Server) AddAPIRoutesAndHandlers ¶
AddAPIRoutesAndHandlers adds the API routes with provided handlers and authorizers
func (*Server) ListenAndServe ¶
ListenAndServe listens for requests and serves them
func (*Server) ListenAndServeAPI ¶
ListenAndServeAPI sets the API routes only with provided backend and listens for requests and serves them
func (*Server) ListenAndServeFileBackedAPI ¶
ListenAndServeFileBackedAPI sets the API routes only with a file backend and listens for requests and serves them