nix

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: GPL-3.0 Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Nix

Nix is a wrapper for the http standard library

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultErrTemplate

func DefaultErrTemplate() *template.Template

func IsWebSocketRequest added in v0.1.0

func IsWebSocketRequest(r *http.Request) bool

func NewHandler

func NewHandler(handler func(ctx *Context), opts ...Option) http.HandlerFunc

func NewWrapper

func NewWrapper(handler http.Handler, opts ...Option) http.HandlerFunc

func NewWrapperFunc

func NewWrapperFunc(handler http.HandlerFunc, opts ...Option) http.HandlerFunc

Types

type CapturedError

type CapturedError struct {
	Code int

	Data     []byte
	DataType string
	// contains filtered or unexported fields
}

func (CapturedError) Error

func (err CapturedError) Error() string

func (CapturedError) Internal

func (err CapturedError) Internal() string

func (CapturedError) Message

func (err CapturedError) Message() string

type Context

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

func GetMain

func GetMain(r *http.Request) *Context

func (*Context) AddInteralMessage

func (ctx *Context) AddInteralMessage(a ...any)

func (*Context) Body

func (ctx *Context) Body() ([]byte, error)

Body returns the response body bytes

func (*Context) BodyString

func (ctx *Context) BodyString() (string, error)

BodyString returns the response body as a string

func (*Context) DeleteCookie

func (ctx *Context) DeleteCookie(name string)

func (*Context) DisableErrorCapture

func (ctx *Context) DisableErrorCapture()

func (*Context) DisableLogging

func (ctx *Context) DisableLogging()

func (*Context) Error

func (ctx *Context) Error(statusCode int, message string, a ...any)

Error is used to manually report an HTTP Error to send to the client.

It sets the http status code (so it should not be set before) and if the connection is done via a GET request, it will try to serve the html Error template with the status code and Error message in it, otherwise if the Error template does not exist or the request is done via another method (like POST), the Error message will be sent as a plain text.

The last optional list of elements can be used just for logging or debugging: the elements will be saved in the logs

func (*Context) GetCookie

func (ctx *Context) GetCookie(name string, value any) error

func (*Context) GetCookiePerm

func (ctx *Context) GetCookiePerm(name string, value any) error

func (*Context) Header

func (ctx *Context) Header() http.Header

Header is the equivalent of the http.ResponseWriter method

func (*Context) Hijack added in v0.1.0

func (ctx *Context) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*Context) IsSecure

func (ctx *Context) IsSecure() bool

func (*Context) IsWebSocketRequest added in v0.1.0

func (ctx *Context) IsWebSocketRequest() bool

func (*Context) JSON

func (ctx *Context) JSON(data []byte)

func (*Context) Logger

func (ctx *Context) Logger() *logger.Logger

func (*Context) Main

func (ctx *Context) Main() *Context

func (*Context) Method

func (ctx *Context) Method() string

func (*Context) MimeType added in v0.0.3

func (ctx *Context) MimeType(mime string)

func (*Context) NewReverseProxy

func (ctx *Context) NewReverseProxy(dest string, prefix string, base string) (http.Handler, *httputil.ReverseProxy, *websocketproxy.WebsocketProxy, error)

func (*Context) R

func (ctx *Context) R() *http.Request

func (*Context) ReadJSON

func (ctx *Context) ReadJSON(value any) error

func (*Context) Redirect

func (ctx *Context) Redirect(url string, code int)

func (*Context) RemoteAddr added in v0.1.2

func (ctx *Context) RemoteAddr() string

func (*Context) RequestHeader

func (ctx *Context) RequestHeader() http.Header

func (*Context) RequestPath

func (ctx *Context) RequestPath() string

func (*Context) ReverseProxy

func (ctx *Context) ReverseProxy(dest string, prefix string, base string) error

ReverseProxy runs a reverse proxy to the provided url. Returns an error is the url could not be parsed or if an error has occurred during the connection

func (*Context) ServeCached added in v0.0.3

func (ctx *Context) ServeCached(uri string)

func (*Context) ServeContent

func (ctx *Context) ServeContent(name string, modtime time.Time, content io.ReadSeeker)

func (*Context) ServeFile

func (ctx *Context) ServeFile(name string)

func (*Context) ServeFileFS

func (ctx *Context) ServeFileFS(dir fs.FS, name string)

func (*Context) ServePHP

func (ctx *Context) ServePHP(php *PHPProcessor, dir string)

func (*Context) ServeStatic

func (ctx *Context) ServeStatic()

func (*Context) SetCookie

func (ctx *Context) SetCookie(name string, value any, maxAge int, opts ...middleware.CookieOption) error

func (*Context) SetCookiePerm

func (ctx *Context) SetCookiePerm(name string, value any, maxAge int, opts ...middleware.CookieOption) error

func (*Context) SetCustomHostLog

func (ctx *Context) SetCustomHostLog(host string)

func (*Context) SetErrorTemplate

func (ctx *Context) SetErrorTemplate(t *template.Template)

func (*Context) SetLogger

func (ctx *Context) SetLogger(l *logger.Logger)

func (*Context) SetRemoteAddr added in v0.1.2

func (ctx *Context) SetRemoteAddr(addr string)

func (*Context) String

func (ctx *Context) String(s string)

ServeText serves a string (as raw bytes) to the client

func (*Context) W

func (ctx *Context) W() http.ResponseWriter

func (*Context) Write

func (ctx *Context) Write(data []byte) (int, error)

Write is the equivalent of the http.ResponseWriter method

func (*Context) WriteHeader

func (ctx *Context) WriteHeader(statusCode int)

WriteHeader is the equivalent of the http.ResponseWriter method but handles multiple calls, using only the first one used

type Nix

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

func New

func New(opts ...Option) *Nix

func (*Nix) Handle

func (n *Nix) Handle(handler func(ctx *Context)) http.HandlerFunc

func (*Nix) Wrap

func (n *Nix) Wrap(handler http.Handler) http.HandlerFunc

func (*Nix) WrapFunc

func (n *Nix) WrapFunc(handler http.HandlerFunc) http.HandlerFunc

type Option

type Option func(ctx *Context)

func CacheOption

func CacheOption(cache *middleware.Cache) Option

func ConnectToMainOption

func ConnectToMainOption() Option

func CookieManagerOption

func CookieManagerOption(cm *middleware.CookieManager) Option

func CustomHostLogOption

func CustomHostLogOption(host string) Option

func EnableErrorCaptureOption

func EnableErrorCaptureOption() Option

func EnableLoggingOption

func EnableLoggingOption() Option

func EnableRecoveryOption

func EnableRecoveryOption() Option

func ErrorTemplateOption

func ErrorTemplateOption(t *template.Template) Option

func LoggerOption

func LoggerOption(l *logger.Logger) Option

func MainOption

func MainOption() Option

type PHPProcessor

type PHPProcessor struct {
	Process *process.Process
	Logger  *logger.Logger
	// contains filtered or unexported fields
}

func NewPHPProcessor

func NewPHPProcessor(port int, args ...string) (php *PHPProcessor, err error)

func (*PHPProcessor) Start

func (php *PHPProcessor) Start() error

func (*PHPProcessor) Stop

func (php *PHPProcessor) Stop() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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