api

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

README

Golang Simple API

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

Install
go get go.ideatocode.tech/api
Import
import api "go.ideatocode.tech/api"
Example

Check the examples dir for a complete working example# go-simpleapi-builder

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(list ...SetOptFunc) *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) Addr

func (c *Controller) Addr() net.Addr

Addr returns the underlying net.Addr that this server listens on

func (*Controller) Run

func (c *Controller) Run(addr string) error

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

type SetOptFunc added in v1.2.1

type SetOptFunc func(*Controller)

func WithAnonymousRequests added in v1.2.1

func WithAnonymousRequests() SetOptFunc

WithAnonymousRequests allows requests with no auth headers through to the auth middleware

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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