web

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// UsersURL is the URL path to manage Users
	UsersURL = "/" + apiVersion + "/users"

	// PostsURL is the URL path to manage Posts
	PostsURL = "/" + apiVersion + "/posts"

	// FollowURL is the URL path to perform following/unfollowing actions
	FollowURL = "/" + apiVersion + "/follow"

	// FollowersURL is the URL path to manage your followers
	FollowersURL = "/" + apiVersion + "/followers"

	// FollowingURL is the URL path to manage users you follow
	FollowingURL = "/" + apiVersion + "/following"
)

Variables

This section is empty.

Functions

func BasicCredentialsExtractor

func BasicCredentialsExtractor(r *http.Request) (string, string, error)

BasicCredentialsExtractor extract credentials from basic auth header

func WriteResponse

func WriteResponse(w http.ResponseWriter, status int, payload interface{})

WriteResponse writes a payload to the provided writer

Types

type API

type API struct {
	// Controllers contains the registered controllers
	Controllers []Controller

	// Filters contains registered filters for this API
	Filters []Filter
}

API is the primary point for REST API registration

type Controller

type Controller interface {
	// Routes returns the set of routes for this controller
	Routes() []Route
}

Controller is an entity that wraps a set of HTTP Routes

type CredentialsExtractor

type CredentialsExtractor interface {
	Extract(*http.Request) (string, string, error)
}

CredentialsExtractor is a generic interface for extracting credentials from different auth mechanism

type CredentialsExtractorFunc

type CredentialsExtractorFunc func(*http.Request) (string, string, error)

CredentialsExtractorFunc is a wrapper of CredentialsExtractor so a normal function could be used as CredentialsExtractor

func (CredentialsExtractorFunc) Extract

Extract extract the credentials and satisfy the CredentialsExtractor interface

type Endpoint

type Endpoint struct {
	Method string
	Path   string
}

Endpoint is a combination of a Path and an HTTP Method

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse defines an error response payload

type Filter

type Filter interface {

	// Filter filters http request on some conditions
	Filter(r *http.Request) (int, error)

	// MatchingEndpoints returns all the endpoints that the filter should be attached before.
	MatchingEndpoints() []Endpoint
}

Filter interface provides an interface for filtering http requests on some conditions

type Route

type Route struct {
	// Endpoint is the combination of Path and HTTP Method for the specified route
	Endpoint Endpoint

	// Handler is the function that should handle incoming requests for this endpoint
	Handler http.HandlerFunc
}

Route is a mapping between an Endpoint and a REST API Handler

Jump to

Keyboard shortcuts

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