libHttpServer

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const CookieSameSiteDefaultMode = CookieSameSite(1)
View Source
const CookieSameSiteDisabled = CookieSameSite(0)
View Source
const CookieSameSiteLaxMode = CookieSameSite(2)
View Source
const CookieSameSiteNoneMode = CookieSameSite(4)
View Source
const CookieSameSiteStrictMode = CookieSameSite(3)
View Source
const HttpReturnCode200Ok int = 200
View Source
const HttpReturnCode404NotFound int = 404
View Source
const HttpReturnCode500ServerError int = 500

Variables

This section is empty.

Functions

func RegisterServer

func RegisterServer(server HttpServer)

RegisterServer allows registering a server instance in a map allowing to known listened port <--> server.

func SaveStreamToFile

func SaveStreamToFile(reader io.Reader, outFilePath string) error

Types

type CookieSameSite

type CookieSameSite int

type HttpCookie

type HttpCookie interface {
	IsHTTPOnly() bool
	IsSecure() bool
	GetSameSiteType() CookieSameSite
	GetKey() string
	GetDomain() string
	GetValue() string
	GetExpireTime() time.Time
	GetMaxAge() int
}

type HttpCookieOptions

type HttpCookieOptions struct {
	IsHttpOnly   bool
	IsSecure     bool
	SameSiteType CookieSameSite
	Domaine      string
	ExpireTime   int64
	MaxAge       int
}

type HttpHost

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

func NewHttpHost

func NewHttpHost(hostName string, server HttpServer, impl HttpHostImpl) *HttpHost

func (*HttpHost) CONNECT

func (m *HttpHost) CONNECT(path string, h HttpMiddleware)

func (*HttpHost) DELETE

func (m *HttpHost) DELETE(path string, h HttpMiddleware)

func (*HttpHost) GET

func (m *HttpHost) GET(path string, h HttpMiddleware)

func (*HttpHost) GetHostName

func (m *HttpHost) GetHostName() string

func (*HttpHost) GetServer

func (m *HttpHost) GetServer() HttpServer

func (*HttpHost) GetUrlResolver

func (m *HttpHost) GetUrlResolver(methodCode HttpMethod) *UrlResolver

func (*HttpHost) HEAD

func (m *HttpHost) HEAD(path string, h HttpMiddleware)

func (*HttpHost) Impl

func (m *HttpHost) Impl() HttpHostImpl

func (*HttpHost) OPTIONS

func (m *HttpHost) OPTIONS(path string, h HttpMiddleware)

func (*HttpHost) OnError

func (m *HttpHost) OnError(req HttpRequest, err error)

func (*HttpHost) OnNotFound

func (m *HttpHost) OnNotFound(req HttpRequest)

func (*HttpHost) PATCH

func (m *HttpHost) PATCH(path string, h HttpMiddleware)

func (*HttpHost) POST

func (m *HttpHost) POST(path string, h HttpMiddleware)

func (*HttpHost) PUT

func (m *HttpHost) PUT(path string, h HttpMiddleware)

func (*HttpHost) Reset

func (m *HttpHost) Reset()

func (*HttpHost) TRACE

func (m *HttpHost) TRACE(path string, h HttpMiddleware)

func (*HttpHost) VERB

func (m *HttpHost) VERB(verb string, path string, h HttpMiddleware)

type HttpHostImpl

type HttpHostImpl interface {
	Reset(host *HttpHost)
}

type HttpHostInfos

type HttpHostInfos struct {
	HostName string
	Port     int
}

HttpHostInfos allows designing a host by his hostname and port.

type HttpMethod

type HttpMethod int
const (
	HttpMethodGET HttpMethod = iota
	HttpMethodPOST
	HttpMethodHEAD
	HttpMethodPUT
	HttpMethodDELETE
	HttpMethodCONNECT
	HttpMethodOPTIONS
	HttpMethodTRACE
	HttpMethodPATCH
)

func MethodNameToMethodCode

func MethodNameToMethodCode(method string) HttpMethod

type HttpMiddleware

type HttpMiddleware func(call HttpRequest) error

HttpMiddleware is a function the system can call when a request occurs.

type HttpMultiPartForm

type HttpMultiPartForm struct {
	Values map[string][]string
	Files  map[string][]*multipart.FileHeader
}

type HttpRequest

type HttpRequest interface {
	GetMethodName() string
	GetMethodCode() HttpMethod
	GetContentLength() int

	IsBodySend() bool

	GetContentType() string
	SetContentType(contentType string)
	SetHeader(key, value string)

	GetHeaders() map[string]string

	ReturnString(status int, text string)

	GetQueryArgs() ValueSet
	GetPostArgs() ValueSet

	IsMultipartForm() bool
	GetMultipartForm() (*HttpMultiPartForm, error)

	GetCookie(name string) (map[string]any, error)
	GetCookies() (map[string]map[string]any, error)
	SetCookie(key string, value string, cookie HttpCookieOptions) error

	Path() string
	URI() string

	UserAgent() string
	RemoteIP() string

	GetHost() *HttpHost

	Return500ErrorPage(err error)
	Return404UnknownPage()

	SetUnlockMutex(mutex *sync.Mutex)
	UnlockMutex()

	MustStop() bool
	StopRequest()

	GetWildcards() []string
	GetRemainingSegment() []string
}

type HttpServer

type HttpServer interface {
	GetPort() int
	IsStarted() bool
	Shutdown()
	StartServer() error
	GetHost(hostName string) *HttpHost
	SetStartServerParams(params HttpServerStartParams)
}

func GetHttpServer

func GetHttpServer(port int) HttpServer

GetHttpServer allows to get the server instance listening to the given port. Return nil if no one.

type HttpServerStartParams

type HttpServerStartParams struct {
}

HttpServerStartParams will contains information on how to configure the server instance to create.

type UrlResolver

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

UrlResolver allows to bind an listener to an url part. It's a router.

func NewUrlResolver

func NewUrlResolver() *UrlResolver

func (*UrlResolver) Add

func (m *UrlResolver) Add(path string, handler any, tag any)

func (*UrlResolver) AppendMiddleware

func (m *UrlResolver) AppendMiddleware(path string, handler any, tag any)

AppendMiddleware add a handler which is always executed before the other handlers.

func (*UrlResolver) DumpTree

func (m *UrlResolver) DumpTree() []UrlResolverTreeItem

func (*UrlResolver) Find

func (m *UrlResolver) Find(path string) UrlResolverResult

func (*UrlResolver) Print

func (m *UrlResolver) Print()

type UrlResolverResult

type UrlResolverResult struct {
	Segments          []string
	RemainingSegments []string
	Target            any

	Middlewares []any
	// contains filtered or unexported fields
}

func (*UrlResolverResult) GetWildcards

func (m *UrlResolverResult) GetWildcards() []string

type UrlResolverTreeItem

type UrlResolverTreeItem struct {
	Path    string
	Handler any
	Tag     any
}

type ValueSet

type ValueSet interface {
	Len() int
	QueryString() []byte
	VisitAll(f func(key, value []byte))

	Has(key string) bool

	GetUfloat(key string) (float64, error)
	GetUfloatOrZero(key string) float64

	GetUint(key string) (int, error)
	GetUintOrZero(key string) int

	GetBool(key string) bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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