silverlining

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Unlicense Imports: 23 Imported by: 4

README

GitHub last commit Go Reference

silverlining

Silverlining is a low-level HTTP Framework for Go Programming Language.

Installation

go get -u github.com/go-www/silverlining

Usage

package main

import "github.com/go-www/silverlining"

func main() {
	silverlining.ListenAndServe(":8080", func(r *silverlining.Context) {
		r.WriteFullBodyString(200, "Hello, World!")
	})
}

Documentation

Index

Constants

View Source
const (
	ServerStoped uint8 = iota
	ServerStarting
	ServerRunning
	ServerStopping
)
View Source
const (
	MethodGET     = h1.MethodGET
	MethodHEAD    = h1.MethodHEAD
	MethodPOST    = h1.MethodPOST
	MethodPUT     = h1.MethodPUT
	MethodDELETE  = h1.MethodDELETE
	MethodCONNECT = h1.MethodCONNECT
	MethodOPTIONS = h1.MethodOPTIONS
	MethodTRACE   = h1.MethodTRACE
	MethodPATCH   = h1.MethodPATCH
	MethodBREW    = h1.MethodBREW
)

Variables

View Source
var ErrBindPtrError = errors.New("bind function's parameter must be a pointer")
View Source
var ErrBindType = errors.New("bind type error")
View Source
var ErrBodyTooLarge = errors.New("body too large")
View Source
var ErrContentTypeInvalid = errors.New("content-type invalid")
View Source
var ErrPreforkChildIDNotFound = errors.New("child id not found")
View Source
var ErrUpgradeBadRequest = errors.New("upgrade request is not valid")

Functions

func DefineStatusLine

func DefineStatusLine(status int, statusText string)

func GetStatusLine

func GetStatusLine(status int) []byte

func ListenAndServe

func ListenAndServe(addr string, handler Handler) error

func ListenAndServePrefork

func ListenAndServePrefork(addr string, handler Handler) error

func ListenAndServeReusePort

func ListenAndServeReusePort(addr string, handler Handler) error

func PreforkChildID

func PreforkChildID() (int, error)

func PreforkIsChild

func PreforkIsChild() bool

func PutRequestContext

func PutRequestContext(ctx *Context)

func PutXWWWFormURLEncoded

func PutXWWWFormURLEncoded(x *XWWWFormURLEncoded)

Types

type ChunkedBodyWriter

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

func (ChunkedBodyWriter) Close

func (c ChunkedBodyWriter) Close() error

func (ChunkedBodyWriter) Write

func (c ChunkedBodyWriter) Write(p []byte) (int, error)

func (ChunkedBodyWriter) WriteString

func (c ChunkedBodyWriter) WriteString(p string) (int, error)

type Context

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

func GetRequestContext

func GetRequestContext(upstream io.Writer) *Context

func (*Context) BindHeader

func (r *Context) BindHeader(v any) error

func (*Context) BindJSON

func (r *Context) BindJSON(v any) error

func (*Context) BindQuery

func (r *Context) BindQuery(v any) error

func (*Context) BindWWWFormURLEncoded

func (r *Context) BindWWWFormURLEncoded(v any) error

func (*Context) Body

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

func (*Context) BodyReader

func (r *Context) BodyReader() *h1.BodyReader

func (*Context) ChunkedBodyWriter

func (r *Context) ChunkedBodyWriter() ChunkedBodyWriter

func (*Context) CloseBodyReader

func (r *Context) CloseBodyReader()

func (*Context) ConnID added in v1.3.0

func (r *Context) ConnID() uint64

(*Context).ConnID returns the connection ID.

func (*Context) ConnectionClose

func (r *Context) ConnectionClose()

func (*Context) FastBodyUnsafe

func (r *Context) FastBodyUnsafe(maxBufferSize int64) ([]byte, error)

func (*Context) Flush

func (r *Context) Flush() error

func (*Context) GetQueryParam

func (r *Context) GetQueryParam(name []byte) ([]byte, error)

func (*Context) GetQueryParamString

func (r *Context) GetQueryParamString(name string) (string, error)

func (*Context) HijackConn

func (r *Context) HijackConn() (bufR h1.HijackReader, bufW *h1.Response, conn net.Conn)

func (*Context) Host added in v1.3.0

func (r *Context) Host() string

(*Context).Host returns the value of the Host header. Returned value is valid until the next request.

func (*Context) HostBytes added in v1.3.0

func (r *Context) HostBytes() []byte

(*Context).HostBytes returns the value of the Host header. Returned value is valid until the next request.

func (*Context) KillConn

func (r *Context) KillConn() error

func (*Context) Method

func (r *Context) Method() h1.Method

func (*Context) MultipartReader

func (r *Context) MultipartReader() (*multipart.Reader, error)

func (*Context) Path

func (r *Context) Path() []byte

func (*Context) QueryParams

func (r *Context) QueryParams() []h1.Query

func (*Context) RawURI

func (r *Context) RawURI() []byte

func (*Context) ReadJSON

func (r *Context) ReadJSON(v any) error

func (*Context) Redirect

func (r *Context) Redirect(status int, url string)

func (*Context) RemoteAddr added in v1.3.0

func (r *Context) RemoteAddr() net.Addr

(*Context).RemoteAddr returns the remote address.

func (*Context) RequestHeaders

func (r *Context) RequestHeaders() RequestHeaders

func (*Context) ResponseHeaders

func (r *Context) ResponseHeaders() ResponseHeaders

func (*Context) ServerSentEventWriter

func (r *Context) ServerSentEventWriter() ServerSentEventWriter

func (*Context) SetContentLength

func (r *Context) SetContentLength(length int)

func (*Context) UpgradeWebSocket

func (r *Context) UpgradeWebSocket(op ws.OpCode) (brwc io.ReadWriteCloser, err error)

Upgrade the request to WebSocket protocol. param:

op: the opcode to use for the WebSocket connection. (ws.OpText|ws.OpBinary)

func (*Context) Write

func (r *Context) Write(p []byte) (n int, err error)

func (*Context) WriteFullBody

func (r *Context) WriteFullBody(status int, body []byte) error

func (*Context) WriteFullBodyString

func (r *Context) WriteFullBodyString(status int, body string) error

func (*Context) WriteHeader

func (r *Context) WriteHeader(status int)

func (*Context) WriteJSON

func (r *Context) WriteJSON(status int, v any) error

func (*Context) WriteJSONIndent

func (r *Context) WriteJSONIndent(status int, v any, prefix string, indent string) error

func (*Context) WriteJSONStream added in v1.2.0

func (r *Context) WriteJSONStream(status int, v any) error

func (*Context) WriteStream

func (r *Context) WriteStream(status int, stream io.Reader) error

func (*Context) WriteString

func (r *Context) WriteString(s string) (n int, err error)

func (*Context) XWWWFormURLEncoded

func (r *Context) XWWWFormURLEncoded(maxSize int64) (*XWWWFormURLEncoded, error)

type Handler

type Handler func(r *Context)
type Header struct {
	Disabled bool

	Name  string
	Value string
}

type KV

type KV = h1.Query

type Method

type Method = h1.Method

type RequestHeaders

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

func (RequestHeaders) Get

func (r RequestHeaders) Get(name string) (string, bool)

(RequestHeaders).Get returns the value of the header with the given name.

Returned value is valid until the next request.

func (RequestHeaders) GetBytes

func (r RequestHeaders) GetBytes(name []byte) ([]byte, bool)

(RequestHeaders).GetBytes returns the value of the header with the given name.

Returned value is valid until the next request.

func (RequestHeaders) List

func (r RequestHeaders) List() []h1.Header

(RequestHeaders).List returns a slice of all the headers.

Returned value is valid until the next request.

type Response

type Response struct {
	Headers []Header

	StatusCode int
}

type ResponseHeaders

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

func (ResponseHeaders) Del

func (r ResponseHeaders) Del(name string)

func (ResponseHeaders) Set

func (r ResponseHeaders) Set(name, value string)

type Server

type Server struct {
	Listener net.Listener // Listener for incoming connections

	MaxBodySize int64 // Max body size (default: 2MB)

	Handler Handler // Handler to invoke for each request

	ReadTimeout time.Duration
	// contains filtered or unexported fields
}

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

func (*Server) ServeConn

func (s *Server) ServeConn(conn net.Conn)

type ServerSentEventWriter

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

func (ServerSentEventWriter) Flush

func (s ServerSentEventWriter) Flush() error

func (ServerSentEventWriter) Send

func (s ServerSentEventWriter) Send(id, event, data string) error

func (ServerSentEventWriter) WriteHeartbeat

func (s ServerSentEventWriter) WriteHeartbeat() error

type XWWWFormURLEncoded

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

func (*XWWWFormURLEncoded) Close

func (x *XWWWFormURLEncoded) Close()

func (*XWWWFormURLEncoded) Get

func (x *XWWWFormURLEncoded) Get(key string) ([]byte, bool)

func (*XWWWFormURLEncoded) GetString

func (x *XWWWFormURLEncoded) GetString(key string) (string, bool)

func (*XWWWFormURLEncoded) GetStringUnsafe

func (x *XWWWFormURLEncoded) GetStringUnsafe(key string) (string, bool)

func (*XWWWFormURLEncoded) Len

func (x *XWWWFormURLEncoded) Len() int

Directories

Path Synopsis
examples
h1

Jump to

Keyboard shortcuts

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