gogoapi

package module
v0.0.0-...-17e4a8a Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2017 License: CC0-1.0, MIT Imports: 10 Imported by: 0

README

gogoapi

JSON web api micro framework written in Go.

Working With GitHub Keys

  # create ssh key, if need be
  # Reference: https://help.github.com/articles/generating-ssh-keys/
  ssh-keygen -t rsa -C "your_email@example.com"

  # add ssh key to session using the sh shell
  sh
  eval "$(ssh-agent -s)"
  ssh-add ~/.ssh/id_rsa

Documentation

Index

Constants

View Source
const (
	GET    = "GET"
	POST   = "POST"
	PUT    = "PUT"
	DELETE = "DELETE"
	HEAD   = "HEAD"
	PATCH  = "PATCH"

	HTTP_UNPROCESSABLE = 422
)
View Source
const (
	DEFAULT_TOKEN_DURATION = 24 * 60 // 24 hours, probably too long
)
View Source
const (
	READ_BUFFER_SIZE = 1024 * 1024 // 1 meg
)

Variables

This section is empty.

Functions

func AuthorizationFailed

func AuthorizationFailed() (int, interface{}, http.Header)

canned failure response

func Logger

func Logger(request *http.Request, inner HandlerFunc) (int, interface{}, http.Header)

func MethodNotAllowed

func MethodNotAllowed(
	httpRequest *http.Request,
) (int, interface{}, http.Header)

func PageNotFound

func PageNotFound(
	httpRequest *http.Request,
) (int, interface{}, http.Header)

Types

type API

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

func NewAPI

func NewAPI(wrapperFuncs []WrapperFunc) *API

func (*API) AddResource

func (api *API) AddResource(
	resource interface{},
	path string,
	resourceWrapperFuncs []WrapperFunc,
)

func (*API) AddRoute

func (api *API) AddRoute(
	method, path string,
	inner HandlerFunc,
)

func (*API) HttpRequestHandler

func (api *API) HttpRequestHandler(
	inner HandlerFunc,
) http.HandlerFunc

func (*API) Start

func (api *API) Start(host string, port int) error

func (*API) WrapHandler

func (api *API) WrapHandler(
	handler HandlerFunc,
	wrapperFuncs []WrapperFunc,
) HandlerFunc

type AuthResource

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

func NewAuthResource

func NewAuthResource(privateKeyPath, publicKeyPath string, tokenDuration time.Duration, validator AuthValidator) *AuthResource

func (*AuthResource) AuthTokenResponse

func (auth *AuthResource) AuthTokenResponse(claims map[string]interface{}) (int, interface{}, http.Header)

func (*AuthResource) AuthorizationRequired

func (auth *AuthResource) AuthorizationRequired(request *http.Request, inner HandlerFunc) (int, interface{}, http.Header)

authorization wrapper

func (*AuthResource) IsAuthorized

func (auth *AuthResource) IsAuthorized(request *http.Request) (bool, *jwt.Token, error)

authorization test using this method will require a reference to the auth object

func (*AuthResource) Post

func (auth *AuthResource) Post(request *http.Request) (int, interface{}, http.Header)

get token

type AuthResponse

type AuthResponse struct {
	AccessToken string `json:"access_token"`
}

type AuthValidator

type AuthValidator func(request *http.Request) (bool, map[string]interface{}, StatusResponse)

type DeleteResource

type DeleteResource interface {
	Delete(*http.Request) (int, interface{}, http.Header)
}

type DummyAuthCredentials

type DummyAuthCredentials struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type DummyAuthUserInfo

type DummyAuthUserInfo struct {
	Username string `json:"username"`
	Type     string `json:"type"`
}

type GetResource

type GetResource interface {
	Get(*http.Request) (int, interface{}, http.Header)
}

type HandlerFunc

type HandlerFunc func(*http.Request) (int, interface{}, http.Header)

type HeadResource

type HeadResource interface {
	Head(*http.Request) (int, interface{}, http.Header)
}

type JSONData

type JSONData struct {
	StatusCode int         `json:"status"`
	Data       interface{} `json:"data"`
}

func (JSONData) Status

func (response JSONData) Status() int

type JSONError

type JSONError struct {
	StatusCode int    `json:"status"`
	Error      string `json:"error"`
}

func (JSONError) Status

func (response JSONError) Status() int

type JSONMessage

type JSONMessage struct {
	StatusCode int    `json:"status"`
	Message    string `json:"message"`
}

func (JSONMessage) Status

func (response JSONMessage) Status() int

type PatchResource

type PatchResource interface {
	Patch(*http.Request) (int, interface{}, http.Header)
}

type PostResource

type PostResource interface {
	Post(*http.Request) (int, interface{}, http.Header)
}

type PutResource

type PutResource interface {
	Put(*http.Request) (int, interface{}, http.Header)
}

type StatusResponse

type StatusResponse interface {
	Status() int
}

func DummyAuthValidator

func DummyAuthValidator(request *http.Request) (bool, map[string]interface{}, StatusResponse)

type WrapperFunc

type WrapperFunc func(*http.Request, HandlerFunc) (int, interface{}, http.Header)

Jump to

Keyboard shortcuts

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