apicontroller

package module
v0.0.0-...-75bcb3f Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: GPL-3.0 Imports: 8 Imported by: 1

README

Golang Simple API

Golang Simple API is small library to enable simple Authenticated API calls

Install
go get "github.com/Alex-Eftimie/api-controller
Import
import apicontroller "github.com/Alex-Eftimie/api-controller"
Example

Check the examples dir for a complete working example

Documentation

Index

Constants

View Source
const (
	// KeyAuthID returns the context Value of the Auth set by the defaultAuthMiddleware func on successful auth
	KeyAuthID key = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthCallback

type AuthCallback func(token string, req *http.Request) (payload interface{}, err error)

AuthCallback is the function called when doing bearer authentication

type Controller

type Controller struct {
	AuthCallback AuthCallback
	// contains filtered or unexported fields
}

Controller runs the controller

func NewController

func NewController() *Controller

NewController creates a new HTTP API controller

func (*Controller) AddHandler

func (c *Controller) AddHandler(path string, fn HTTPHandler, methods ...string)

AddHandler adds a handler

func (*Controller) Run

func (c *Controller) Run(addr string)

Run runs the controller and the listener

func (*Controller) Stop

func (c *Controller) Stop()

Stop stops the http listener

type HTTPHandler

type HTTPHandler func(w http.ResponseWriter, r *http.Request)

HTTPHandler is the handler that is called when path is accessed

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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