api

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateEndpointKey

func GenerateEndpointKey(method, url string) string

GenerateEndpointKey generates a key used to identify urls using a request method and url

func GeneratePrivateKey

func GeneratePrivateKey(keySize int) (*rsa.PrivateKey, error)

func NewEngine

func NewEngine(certSubject CertificateSubject, privateKey *rsa.PrivateKey, config Config) (*engine, error)

func NewScope

func NewScope(w http.ResponseWriter, r *http.Request) *scope

NewScope creates a Handler's scope instance

func NewTestRequest added in v0.0.2

func NewTestRequest() *request

func NewTestScope

func NewTestScope(method string, req Request, c Controller) *scopeTest

NewTestScope creates a Handler's scope instance for testing purposes

func NotFound

func NotFound(scope Scope)

NotFound is the default handler used if no handler matched the request

Types

type CertificateSubject

type CertificateSubject struct {
	Organization  []string
	Country       []string
	Province      []string
	Locality      []string
	StreetAddress []string
	PostalCode    []string
	SerialNumber  int64
	CertNotBefore time.Time
	CertNotAfter  time.Time
}

type Config

type Config struct {
	Service Service
}

type Controller

type Controller interface {
	Url() string
	Routes() map[string]Handler
	GetHandler(method, url string) Handler
}

type Endpoints

type Endpoints struct {
	Get    Handler
	Post   Handler
	Put    Handler
	Patch  Handler
	Delete Handler
}

type Handler

type Handler func(scope Scope)

Handler handles HTTP requests with a given scope

type Interceptor

type Interceptor func(s *scope) error

Interceptor can be executed before and after a request with the given scope

type InterceptorI

type InterceptorI interface {
	Before(s *scope) error
	After(s *scope) error
}

type Measurement

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

Measurement logs information about the the api and its performance

func (*Measurement) After

func (m *Measurement) After(s *scope) error

After gets called after the endpoint gets called

func (*Measurement) Before

func (m *Measurement) Before(s *scope) error

Before gets called before the endpoint gets called

type Request added in v0.0.2

type Request interface {
	QueryValue(k, v string)
	EncodedQuery() string
	HeaderValue(k, v string)
}

type Resource

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

func NewResource

func NewResource(url string, handlers Endpoints) Resource

func (*Resource) GetHandler

func (r *Resource) GetHandler(method, url string) Handler

func (*Resource) Routes

func (r *Resource) Routes() map[string]Handler

func (*Resource) Url

func (r *Resource) Url() string

type Scope

type Scope interface {
	GetData(key string) (any, error)
	SetData(key string, val any) error
	OverrideData(key string, val any)
	Method() string
	Path() string
	Reply(status int, body interface{})
	QueryValue(key string) string
	ValidateQuery(payload interface{}) error
	ValidateJsonBody(payload interface{}) error
	ValidateHeaders(payload interface{}) error
}

type ScopeTest

type ScopeTest interface {
	Scope
	IsStatus(status int) error
	ReplyWas(body interface{}) error
}

type Service

type Service struct {
	Id       string `json:"id,omitempty"`
	Name     string `json:"name,omitempty"`
	Internal string `json:"internal,omitempty"`
	External string `json:"external,omitempty"`
}

Service holds information about a server which references an individual conf within a cluster of servers

type ValidationRule

type ValidationRule func(cv any) bool

type ValidationRuleError

type ValidationRuleError struct {
	Field      string
	FailedTags []string
	Value      string
}

Jump to

Keyboard shortcuts

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