http

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MiddlewareTypeAll special type
	MiddlewareTypeAll = "*"
)
View Source
const (
	// USER constant key for user in iris.Context
	USER = "USER"
)

Variables

This section is empty.

Functions

func DecorateHandlerFunc

func DecorateHandlerFunc(handlerFunc iris.HandlerFunc, mws ...Middleware) []iris.HandlerFunc

DecorateHandlerFunc prepend all the given middlewares

func GetMiddlewareHandlerFunc

func GetMiddlewareHandlerFunc(mws ...Middleware) []iris.HandlerFunc

GetMiddlewareHandlerFunc get only the functions from middlewares

func NewStLogFunc

func NewStLogFunc(logger log.StLogger) iris.HandlerFunc

NewStLogFunc returns a middleware print function using StLogger

func NewStandardLogFunc

func NewStandardLogFunc(logger log.StandardLogger) iris.HandlerFunc

NewStandardLogFunc returns a middleware print function using StandardLogger

func NewStructuredLogFunc

func NewStructuredLogFunc(logger log.StructuredLogger) iris.HandlerFunc

NewStructuredLogFunc returns a middleware print function using StructuredLogger

Types

type AddRoutesFunc

type AddRoutesFunc func(router *iris.Router, server *Server)

AddRoutesFunc a function to add a route

type AlaudaError

type AlaudaError struct {
	Errors []error `json:"errors"`
}

AlaudaError structure to represent alauda's standard error format

func NewAlaudaError

func NewAlaudaError(err ...error) *AlaudaError

NewAlaudaError constructor function for the errors

type Config

type Config struct {
	Host               string
	Port               string
	AddLog             bool
	LogFunc            iris.HandlerFunc
	AddHealthCheck     bool
	TreatNotFoundError bool
	NotFoundFunc       iris.HandlerFunc
	Component          string
	MaxReadBufferSize  int
	AllowedOrigins     []string
}

Config configuration for the HTTP server

func (Config) GetCorsOptions

func (c Config) GetCorsOptions() cors.Options

GetCorsOptions return cors options for iris http router

func (Config) GetIrisOptions

func (c Config) GetIrisOptions() []iris.OptionSetter

GetIrisOptions returns the options for the iris http server

func (Config) SaneDefaults

func (c Config) SaneDefaults() Config

SaneDefaults verifies the options and sets some sane defaults if the set values are not setup or not valid

type DiagnoseRouter

type DiagnoseRouter struct {
	*diagnose.HealthChecker
}

DiagnoseRouter struct to add a route

func NewDiagnoser

func NewDiagnoser(checker *diagnose.HealthChecker) *DiagnoseRouter

NewDiagnoser constructor for a diagnose checker

func (*DiagnoseRouter) AddRoutes

func (h *DiagnoseRouter) AddRoutes(router *iris.Router, server *Server)

AddRoutes will add a route for diagnose endpoint

type Handler

type Handler struct {
}

Handler base handler with common shared methods can be composed to provide default behaviour

func (Handler) GetContext

func (Handler) GetContext(ctx *iris.Context, attach bool) context.Context

GetContext get context with predefined keys

func (Handler) HandleError

func (Handler) HandleError(err error, ctx *iris.Context, log log.Logger)

HandleError Function to handle errors and return a message

func (Handler) HandleErrors

func (Handler) HandleErrors(errs []error, ctx *iris.Context, log log.Logger) bool

HandleErrors Function to handle errors and return a message

type Middleware

type Middleware interface {
	Serve(ctx *iris.Context)
}

Middleware adding middleware

type Router

type Router interface {
	AddRoutes(router *iris.Router, server *Server)
}

Router interface for http endpoints

type Server

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

Server Full HTTP server

func NewServer

func NewServer(config Config, log log.Logger) *Server

NewServer constructor function for the HTTP server

func (*Server) AddEndpoint

func (h *Server) AddEndpoint(relativePath string, handler Router) *Server

AddEndpoint ands a handler for the given relative path should be executed before the Start method and after the Init method

func (*Server) AddMiddleware

func (h *Server) AddMiddleware(mw Middleware, kinds ...string) *Server

AddMiddleware adds a middleware for the given types

func (*Server) AddMiddlewares

func (h *Server) AddMiddlewares(mws []Middleware, kinds ...string) *Server

AddMiddlewares adds a middleware for the given types

func (*Server) AddVersion

func (h *Server) AddVersion(version int) *Server

AddVersion Adds a version number to the API route

func (*Server) AddVersionEndpoint

func (h *Server) AddVersionEndpoint(version int, relativePath string, handler Router) *Server

AddVersionEndpoint add a root endpoint to a version specific API Used like AddEndpoint but will add on a specific version instead. If the version was not created previously will then be created automatically

func (*Server) AddVersionEndpointFunc

func (h *Server) AddVersionEndpointFunc(version int, relativePath string, addRoutesFunc AddRoutesFunc) *Server

AddVersionEndpointFunc add a root endpoint to a version specific API Used like AddEndpoint but will add on a specific version instead. If the version was not created previously will then be created automatically

func (*Server) AuthHealthcheck

func (h *Server) AuthHealthcheck(ctx *iris.Context)

AuthHealthcheck healthcheck endpoint

func (*Server) GetApp

func (h *Server) GetApp() *iris.Framework

GetApp returns the iris app, used for testing

func (*Server) GetMiddlewareHandlerFun

func (h *Server) GetMiddlewareHandlerFun(kind string) []iris.HandlerFunc

GetMiddlewareHandlerFun returns all the handler functions of a middleware kind

func (*Server) GetMiddlewares

func (h *Server) GetMiddlewares(kind string) []Middleware

GetMiddlewares get all midlewares of a kind

func (*Server) GetMiddlewaresDecorated

func (h *Server) GetMiddlewaresDecorated(handlerFunc iris.HandlerFunc, kinds ...string) []iris.HandlerFunc

GetMiddlewaresDecorated gets all the handler functions of a collection of kinds and decorate the target function

func (*Server) Healthcheck

func (h *Server) Healthcheck(ctx *iris.Context)

Healthcheck healthcheck endpoint

func (*Server) Init

func (h *Server) Init() *Server

Init will setup any necessary data

func (*Server) Start

func (h *Server) Start()

Start will start serving the http server this method will block while serving http

Jump to

Keyboard shortcuts

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