http

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

README

github.com/AlvinRamoutar/go-framework/http

HTTP server module for HTTP APIs

Documentation

Index

Constants

This section is empty.

Variables

View Source
var VERSION string = "0.0.1"

Functions

func ShiftPath

func ShiftPath(p string) (head, tail string)

ShiftPath splits off the first component of p, which will be cleaned of relative components before processing. head will never contain a slash and tail will always be a rooted path without trailing slash.

Types

type Http

type Http struct {
	Config             HttpConfig
	Routes             []Route
	DefaultRoutes      []Route
	Closer             io.Closer
	DefaultRouteRegexp *regexp.Regexp
}

func (*Http) AddRoute

func (h *Http) AddRoute(route Route) error

func (*Http) AddRoutes

func (h *Http) AddRoutes(routes []Route) error

func (*Http) AsyncStart

func (h *Http) AsyncStart() error

func (*Http) Init

func (h *Http) Init(config *HttpConfig) error

func (*Http) RemoveRoute

func (h *Http) RemoveRoute(name string) error

func (*Http) Restart

func (h *Http) Restart() error

func (*Http) Serve

func (h *Http) Serve() error

func (*Http) ServeHTTP

func (h *Http) ServeHTTP(res http.ResponseWriter, req *http.Request)

func (*Http) Start

func (h *Http) Start() error

func (*Http) Status

func (h *Http) Status() (string, error)

func (*Http) Stop

func (h *Http) Stop() error

func (*Http) Version

func (h *Http) Version() string

type HttpConfig

type HttpConfig struct {
	Host string `yaml:"host"`
	Port int    `yaml:"port"`
}

func (*HttpConfig) New

func (h *HttpConfig) New() *HttpConfig

type HttpError

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

func (*HttpError) Error

func (e *HttpError) Error() string

type Method

type Method byte
const (
	GET Method = iota
	HEAD
	POST
	PUT
	PATCH
	DELETE
	CONNECT
	OPTIONS
	TRACE
	STATUS
)

func (Method) Byte

func (m Method) Byte() byte

type PathType

type PathType byte
const (
	EXACT PathType = iota
	REGEX
)

func (PathType) Byte

func (pt PathType) Byte() byte

type ResponseResult

type ResponseResult struct {
	ResponseCode int
	Error        error
}

type Route

type Route struct {
	Name         string
	Method       Method
	Path         string
	PathType     PathType
	CompiledPath *regexp.Regexp
	Action       actionDef
}

Jump to

Keyboard shortcuts

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