hemi

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: BSD-2-Clause Imports: 26 Imported by: 5

README

Hemi

Hemi is the engine of Gorox. It's a plain Go module that only depends on Go's standard library. It can be used as a Go module by your programs.

How to use

To use the Hemi Engine module, add a "require" line to your "go.mod" file:

require github.com/hexinfra/gorox vx.y.z

Where x.y.z is the version of Hemi. Then import it in your "main.go":

import "github.com/hexinfra/gorox/hemi"

If you would like to use the standard components too, import them with:

import _ "github.com/hexinfra/gorox/hemi/builtin"

For source code showing how to call the Hemi Engine in your programs, please see our examples in the "example/" sub directory.

Layout

In addition to the *.go files in current directory that implement the core of the Hemi Engine, we also have these sub directories that supplement Hemi:

  • builtin/ - Place standard Hemi components,
  • contrib/ - Place community contributed Hemi components,
  • library/ - Place general purpose libraries,
  • process/ - A process manager for programs using Hemi.

The following sub directories are some programs that use the Hemi Engine:

  • goroxio/ - A program that implements the official website of Gorox,
  • hemicar/ - A prototype program that is used to develop Hemi itself,
  • rockman/ - A program that can optionally be used to manage gorox clusters.

And something useful:

  • example/ - Place example programs showing how to use the Hemi Engine,
  • toolkit/ - Place auxiliary commands that are sometimes useful.

Architecture

Dependencies

A program (like Gorox) using Hemi Engine typically has these dependencies:

  +-------------------------------------------------------------+
  |                          <program>                          |
  +-------------+-------------------------------+----------+----+
                |                               |          |
                v                               v          v
  +------+   +---------------------------+   +------+ +---------+
  | libs |<--+        apps & svcs        +-->| exts | |<process>|
  +------+   +--+---------------------+--+   +--+---+ +----+----+
                |                     |         |          |
                v                     v         v          v
  +-----------------------+   +---------------------------------+
  | <builtin> & <contrib> +-->|              <hemi>             |
  +-----------------------+   +---------------------------------+

Processes

A Hemi powered program that is managed by "process/" normally has two processes when started - a leader process, and a worker process:

                  +----------------+         +----------------+ business traffic
         cmdConn  |                | admConn |                |<===============>
operator<-------->| leader process |<------->| worker process |<===============>
                  |                |         |                |<===============>
                  +----------------+         +----------------+

The leader process manages the worker process, which do the real and heavy work.

A program instance can be controlled by operators through the cmdui interface of the leader process. Using gorox as a controlling agent, operators can connect to the leader, send commands, then the leader executes the commands. Some commands are delivered to the worker process through admConn which is a TCP connection between the leader process and the worker process.

If operators prefer to use the Web UI, there is a webui interface in the leader process too. Run your program with "help" action and you will see there is a "-webui" option which controls what ip:port it should use. Start your program with that option and you'll get a Web UI to control your program instance.

Alternatively, leaders of program instances can choose to connect to a Rockman instance and delegate their administration to Rockman. In this way, the cmdui and the webui interface in the leader process are disabled.

Stages

A worker process has one stage most of the time. When an old stage is about to retire and a new stage is about to start, there may be many stages running at the same time. This happens when you have changed the config and is telling the worker to reload the config. The logical architecture of a stage in a worker process might looks like this:

   ^     +---------------------------------------------+  shutdown
   |     |                  cronjob(*)                 |     |
   |     +--------+--------------+-----------------+---+     |
   |     |        |    rpc[+]    |     web[+]      |   |     |
   |     | [quix] |    server    |     server      | s |     |
   |     | [tcpx] | <gate><conn> |  <gate><conn>   | e |     |
   |     | [udpx] +--------------+-----------------+ r |     |
   |     | router |              | webapp(*)  rule | v |     |
   |     |        |              | handlet reviser | e |     |
   |     |  case  |  service(*)  |     socklet     | r |     |
   |     | dealet |              +------+   +------+(*)|     |
   |     |        |              |hstate|   |hcache|   |     |
   |     +--------+--------------+------+---+------+---+     |
   |     |                  backend                    |     |
   |     |                   node                      |     |
   |     |                  <conn>                     |     |
   |     +-----------+---------------+-----------------+     |
   |     |   clock   |     fcache    |     resolv      |     |
prepare  +-----------+---------------+-----------------+     v
                              stage

Hacking

To be written.

TODO

  • net system design and implementation.
  • rpc system design and implementation.
  • web rewrite handlet design and implementation.
  • web reviser design and implementation.
  • webSocket implementation.
  • http/2 implementation.
  • quic and http/3 implementation.
  • hcache implementation.
  • hstate implementation.
  • socks 5 proxy implementation.
  • http tunnel proxy (tcp, udp, ip) implementation.
  • web application framework implementation.
  • documentation.
  • goroxio.
  • rperf design and implementation.
  • more unit tests.
  • black/white box tests.
  • online parsing algorithm for forms.
  • fetch config through url.
  • ktls support?
  • ...

Documentation

Index

Constants

View Source
const (
	CodeBug = 20
	CodeUse = 21
	CodeEnv = 22
)
View Source
const (
	K = 1 << 10
	M = 1 << 20
	G = 1 << 30
	T = 1 << 40
)
View Source
const (
	// version codes
	Version1_0 = 0 // must be 0, default value
	Version1_1 = 1
	Version2   = 2
	Version3   = 3

	// scheme codes
	SchemeHTTP  = 0 // must be 0, default value
	SchemeHTTPS = 1

	// best known http method codes
	MethodGET     = 0x00000001
	MethodHEAD    = 0x00000002
	MethodPOST    = 0x00000004
	MethodPUT     = 0x00000008
	MethodDELETE  = 0x00000010
	MethodCONNECT = 0x00000020
	MethodOPTIONS = 0x00000040
	MethodTRACE   = 0x00000080

	// status codes
	// 1XX
	StatusContinue           = 100
	StatusSwitchingProtocols = 101
	StatusProcessing         = 102
	StatusEarlyHints         = 103
	// 2XX
	StatusOK                         = 200
	StatusCreated                    = 201
	StatusAccepted                   = 202
	StatusNonAuthoritativeInfomation = 203
	StatusNoContent                  = 204
	StatusResetContent               = 205
	StatusPartialContent             = 206
	StatusMultiStatus                = 207
	StatusAlreadyReported            = 208
	StatusIMUsed                     = 226
	// 3XX
	StatusMultipleChoices   = 300
	StatusMovedPermanently  = 301
	StatusFound             = 302
	StatusSeeOther          = 303
	StatusNotModified       = 304
	StatusUseProxy          = 305
	StatusTemporaryRedirect = 307
	StatusPermanentRedirect = 308
	// 4XX
	StatusBadRequest                  = 400
	StatusUnauthorized                = 401
	StatusPaymentRequired             = 402
	StatusForbidden                   = 403
	StatusNotFound                    = 404
	StatusMethodNotAllowed            = 405
	StatusNotAcceptable               = 406
	StatusProxyAuthenticationRequired = 407
	StatusRequestTimeout              = 408
	StatusConflict                    = 409
	StatusGone                        = 410
	StatusLengthRequired              = 411
	StatusPreconditionFailed          = 412
	StatusContentTooLarge             = 413
	StatusURITooLong                  = 414
	StatusUnsupportedMediaType        = 415
	StatusRangeNotSatisfiable         = 416
	StatusExpectationFailed           = 417
	StatusMisdirectedRequest          = 421
	StatusUnprocessableEntity         = 422
	StatusLocked                      = 423
	StatusFailedDependency            = 424
	StatusTooEarly                    = 425
	StatusUpgradeRequired             = 426
	StatusPreconditionRequired        = 428
	StatusTooManyRequests             = 429
	StatusRequestHeaderFieldsTooLarge = 431
	StatusUnavailableForLegalReasons  = 451
	// 5XX
	StatusInternalServerError           = 500
	StatusNotImplemented                = 501
	StatusBadGateway                    = 502
	StatusServiceUnavailable            = 503
	StatusGatewayTimeout                = 504
	StatusHTTPVersionNotSupported       = 505
	StatusVariantAlsoNegotiates         = 506
	StatusInsufficientStorage           = 507
	StatusLoopDetected                  = 508
	StatusNotExtended                   = 510
	StatusNetworkAuthenticationRequired = 511
)
View Source
const Version = "0.2.4"

Variables

This section is empty.

Functions

func BugExitf

func BugExitf(f string, v ...any)

func BugExitln

func BugExitln(v ...any)

func ConstBytes added in v0.2.0

func ConstBytes(s string) (p []byte)

func DebugLevel added in v0.2.0

func DebugLevel() int32

func DevelMode added in v0.2.4

func DevelMode() bool

func EnvExitf

func EnvExitf(f string, v ...any)

func EnvExitln

func EnvExitln(v ...any)

func Errorf added in v0.1.5

func Errorf(f string, v ...any)

func Errorln added in v0.1.5

func Errorln(v ...any)

func FCGIReverseProxy added in v0.2.4

func FCGIReverseProxy(httpReq ServerRequest, httpResp ServerResponse, hcache Hcache, backend *FCGIBackend, proxyConfig *FCGIProxyConfig)

FCGIReverseProxy

func Get4K added in v0.2.0

func Get4K() []byte

func Get16K added in v0.2.0

func Get16K() []byte

func Get64K1 added in v0.2.0

func Get64K1() []byte

func GetNK added in v0.2.0

func GetNK(n int64) []byte

func HTTPReverseProxy added in v0.2.4

func HTTPReverseProxy(servReq ServerRequest, servResp ServerResponse, hcache Hcache, backend HTTPBackend, proxyConfig *HTTPProxyConfig)

HTTPReverseProxy

func LogDir added in v0.2.0

func LogDir() string

func Printf added in v0.1.5

func Printf(f string, v ...any)

func Println added in v0.1.5

func Println(v ...any)

func PutNK added in v0.2.0

func PutNK(p []byte)

func QUIXReverseProxy added in v0.2.0

func QUIXReverseProxy(servConn *QUIXConn, servStream *QUIXStream, backend *QUIXBackend, proxyConfig *QUIXProxyConfig)

QUIXReverseProxy

func RegisterBackend

func RegisterBackend(compSign string, create func(compName string, stage *Stage) Backend)

func RegisterCronjob

func RegisterCronjob(compSign string, create func(compName string, stage *Stage) Cronjob)

func RegisterHandlet

func RegisterHandlet(compSign string, create func(compName string, stage *Stage, webapp *Webapp) Handlet)

func RegisterHcache added in v0.2.1

func RegisterHcache(compSign string, create func(compName string, stage *Stage) Hcache)

func RegisterHstate added in v0.2.1

func RegisterHstate(compSign string, create func(compName string, stage *Stage) Hstate)

func RegisterLogger added in v0.2.4

func RegisterLogger(loggerSign string, create func(config *LogConfig) Logger)

func RegisterQUIXDealet added in v0.2.0

func RegisterQUIXDealet(compSign string, create func(compName string, stage *Stage, router *QUIXRouter) QUIXDealet)

func RegisterReviser

func RegisterReviser(compSign string, create func(compName string, stage *Stage, webapp *Webapp) Reviser)

func RegisterServer

func RegisterServer(compSign string, create func(compName string, stage *Stage) Server)

func RegisterServiceInit added in v0.2.0

func RegisterServiceInit(serviceName string, init func(service *Service) error)

func RegisterSocklet

func RegisterSocklet(compSign string, create func(compName string, stage *Stage, webapp *Webapp) Socklet)

func RegisterTCPXDealet added in v0.2.0

func RegisterTCPXDealet(compSign string, create func(compName string, stage *Stage, router *TCPXRouter) TCPXDealet)

func RegisterUDPXDealet added in v0.2.0

func RegisterUDPXDealet(compSign string, create func(compName string, stage *Stage, router *UDPXRouter) UDPXDealet)

func RegisterWebappInit added in v0.2.0

func RegisterWebappInit(webappName string, init func(webapp *Webapp) error)

func SCGIReverseProxy added in v0.2.4

func SCGIReverseProxy(httpReq ServerRequest, httpResp ServerResponse, hcache Hcache, backend *SCGIBackend, proxyConfig *SCGIProxyConfig)

SCGIReverseProxy

func SOCKReverseProxy added in v0.2.4

func SOCKReverseProxy(servReq ServerRequest, servSock ServerSocket, backend HTTPBackend, proxyConfig *SOCKProxyConfig)

SOCKReverseProxy

func SetDebugLevel added in v0.2.0

func SetDebugLevel(level int32)

func SetDevelMode added in v0.2.4

func SetDevelMode(devel bool)

func SetLogDir added in v0.2.0

func SetLogDir(dir string)

func SetTmpDir added in v0.2.0

func SetTmpDir(dir string)

func SetTopDir added in v0.2.0

func SetTopDir(dir string)

func SetVarDir added in v0.2.0

func SetVarDir(dir string)

func TCPXReverseProxy added in v0.2.0

func TCPXReverseProxy(servConn *TCPXConn, backend *TCPXBackend, proxyConfig *TCPXProxyConfig)

TCPXReverseProxy

func TmpDir added in v0.2.0

func TmpDir() string

func TopDir added in v0.2.0

func TopDir() string

func UDPXReverseProxy added in v0.2.0

func UDPXReverseProxy(servConn *UDPXConn, backend *UDPXBackend, proxyConfig *UDPXProxyConfig)

UDPXReverseProxy

func UseExitf

func UseExitf(f string, v ...any)

func UseExitln

func UseExitln(v ...any)

func VarDir added in v0.2.0

func VarDir() string

func WeakString added in v0.2.0

func WeakString(p []byte) (s string)

Types

type Backend

type Backend interface {
	// Imports
	Component
	// Methods
	Maintain() // runner
	CreateNode(compName string) Node
}

Backend component. A Backend is a group of nodes.

type BackendRequest added in v0.2.2

type BackendRequest interface {
	// contains filtered or unexported methods
}

BackendRequest is the backend-side http request.

type BackendResponse added in v0.2.2

type BackendResponse interface {
	KeepAlive() bool
	HeadResult() int16
	BodyResult() int16
	Status() int16
	HasContent() bool
	ContentSize() int64
	HasTrailers() bool
	IsVague() bool
	// contains filtered or unexported methods
}

BackendResponse is the backend-side http response.

type BackendSocket added in v0.2.2

type BackendSocket interface {
	Read(dst []byte) (int, error)
	Write(src []byte) (int, error)
	Close() error
}

BackendSocket is the backend-side webSocket.

type BackendStream added in v0.2.2

type BackendStream interface {
	Response() BackendResponse
	Request() BackendRequest
	Socket() BackendSocket
	// contains filtered or unexported methods
}

BackendStream is the backend-side http stream.

type Backend_ added in v0.2.0

type Backend_[N Node] struct {
	// Parent
	Component_
	// contains filtered or unexported fields
}

Backend_ is a parent.

func (*Backend_[N]) AddNode added in v0.2.0

func (b *Backend_[N]) AddNode(node N)

func (*Backend_[N]) ConfigureNodes added in v0.2.0

func (b *Backend_[N]) ConfigureNodes()

func (*Backend_[N]) DecNode added in v0.2.4

func (b *Backend_[N]) DecNode()

func (*Backend_[N]) Maintain added in v0.2.0

func (b *Backend_[N]) Maintain()

func (*Backend_[N]) OnConfigure added in v0.2.0

func (b *Backend_[N]) OnConfigure()

func (*Backend_[N]) OnCreate added in v0.2.0

func (b *Backend_[N]) OnCreate(compName string, stage *Stage)

func (*Backend_[N]) OnPrepare added in v0.2.0

func (b *Backend_[N]) OnPrepare()

func (*Backend_[N]) OnShutdown added in v0.2.0

func (b *Backend_[N]) OnShutdown()

func (*Backend_[N]) PrepareNodes added in v0.2.0

func (b *Backend_[N]) PrepareNodes()

func (*Backend_[N]) Stage added in v0.2.0

func (b *Backend_[N]) Stage() *Stage

type Bundlet added in v0.1.6

type Bundlet interface {
}

Bundlet is a collection of related procedures in a service. A service has many bundlets. Bundlets are not components.

type Bundlet_ added in v0.2.0

type Bundlet_ struct {
}

Bundlet_ is a parent.

type Chain added in v0.2.0

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

Chain is a linked-list of pieces.

func (*Chain) PushHead added in v0.2.0

func (c *Chain) PushHead(piece *Piece)

func (*Chain) PushTail added in v0.2.0

func (c *Chain) PushTail(piece *Piece)

func (*Chain) Qnty added in v0.2.0

func (c *Chain) Qnty() int

func (*Chain) Size added in v0.2.0

func (c *Chain) Size() (int64, bool)

type Component added in v0.2.0

type Component interface {
	MakeComp(compName string)
	CompName() string

	OnConfigure()
	Find(propName string) (propValue Value, ok bool)
	Prop(propName string) (propValue Value, ok bool)
	ConfigureBool(propName string, prop *bool, defaultValue bool)
	ConfigureInt64(propName string, prop *int64, check func(value int64) error, defaultValue int64)
	ConfigureInt32(propName string, prop *int32, check func(value int32) error, defaultValue int32)
	ConfigureInt16(propName string, prop *int16, check func(value int16) error, defaultValue int16)
	ConfigureInt8(propName string, prop *int8, check func(value int8) error, defaultValue int8)
	ConfigureInt(propName string, prop *int, check func(value int) error, defaultValue int)
	ConfigureString(propName string, prop *string, check func(value string) error, defaultValue string)
	ConfigureBytes(propName string, prop *[]byte, check func(value []byte) error, defaultValue []byte)
	ConfigureDuration(propName string, prop *time.Duration, check func(value time.Duration) error, defaultValue time.Duration)
	ConfigureStringList(propName string, prop *[]string, check func(value []string) error, defaultValue []string)
	ConfigureBytesList(propName string, prop *[][]byte, check func(value [][]byte) error, defaultValue [][]byte)
	ConfigureStringDict(propName string, prop *map[string]string, check func(value map[string]string) error, defaultValue map[string]string)

	OnPrepare()

	OnShutdown()
	// contains filtered or unexported methods
}

Component is the interface for all components.

type Component_

type Component_ struct {
	ShutChan chan struct{} // used to notify the component to shutdown
	// contains filtered or unexported fields
}

Component_ is a parent.

func (*Component_) CompName added in v0.2.1

func (c *Component_) CompName() string

func (*Component_) ConfigureBool added in v0.2.0

func (c *Component_) ConfigureBool(propName string, prop *bool, defaultValue bool)

func (*Component_) ConfigureBytes added in v0.2.0

func (c *Component_) ConfigureBytes(propName string, prop *[]byte, check func(value []byte) error, defaultValue []byte)

func (*Component_) ConfigureBytesList added in v0.2.0

func (c *Component_) ConfigureBytesList(propName string, prop *[][]byte, check func(value [][]byte) error, defaultValue [][]byte)

func (*Component_) ConfigureDuration added in v0.2.0

func (c *Component_) ConfigureDuration(propName string, prop *time.Duration, check func(value time.Duration) error, defaultValue time.Duration)

func (*Component_) ConfigureInt added in v0.2.0

func (c *Component_) ConfigureInt(propName string, prop *int, check func(value int) error, defaultValue int)

func (*Component_) ConfigureInt8 added in v0.2.0

func (c *Component_) ConfigureInt8(propName string, prop *int8, check func(value int8) error, defaultValue int8)

func (*Component_) ConfigureInt16 added in v0.2.0

func (c *Component_) ConfigureInt16(propName string, prop *int16, check func(value int16) error, defaultValue int16)

func (*Component_) ConfigureInt32 added in v0.2.0

func (c *Component_) ConfigureInt32(propName string, prop *int32, check func(value int32) error, defaultValue int32)

func (*Component_) ConfigureInt64 added in v0.2.0

func (c *Component_) ConfigureInt64(propName string, prop *int64, check func(value int64) error, defaultValue int64)

func (*Component_) ConfigureString added in v0.2.0

func (c *Component_) ConfigureString(propName string, prop *string, check func(value string) error, defaultValue string)

func (*Component_) ConfigureStringDict added in v0.2.0

func (c *Component_) ConfigureStringDict(propName string, prop *map[string]string, check func(value map[string]string) error, defaultValue map[string]string)

func (*Component_) ConfigureStringList added in v0.2.0

func (c *Component_) ConfigureStringList(propName string, prop *[]string, check func(value []string) error, defaultValue []string)

func (*Component_) Find added in v0.2.0

func (c *Component_) Find(propName string) (propValue Value, ok bool)

func (*Component_) LoopRun added in v0.2.0

func (c *Component_) LoopRun(interval time.Duration, callback func(now time.Time))

func (*Component_) MakeComp added in v0.2.0

func (c *Component_) MakeComp(compName string)

func (*Component_) Prop added in v0.2.0

func (c *Component_) Prop(propName string) (propValue Value, ok bool)
type Cookie struct {
	// contains filtered or unexported fields
}

Cookie is a "set-cookie" header that is sent to http client by http server.

func (*Cookie) Set added in v0.2.0

func (c *Cookie) Set(name string, value string) bool

func (*Cookie) SetDomain added in v0.2.0

func (c *Cookie) SetDomain(domain string) bool

func (*Cookie) SetExpires added in v0.2.0

func (c *Cookie) SetExpires(expires time.Time) bool

func (*Cookie) SetHttpOnly added in v0.2.0

func (c *Cookie) SetHttpOnly()

func (*Cookie) SetMaxAge added in v0.2.0

func (c *Cookie) SetMaxAge(maxAge int32)

func (*Cookie) SetPath added in v0.2.0

func (c *Cookie) SetPath(path string) bool

func (*Cookie) SetSameSite added in v0.2.0

func (c *Cookie) SetSameSite(mode string)

func (*Cookie) SetSameSiteLax added in v0.2.0

func (c *Cookie) SetSameSiteLax()

func (*Cookie) SetSameSiteNone added in v0.2.0

func (c *Cookie) SetSameSiteNone()

func (*Cookie) SetSameSiteStrict added in v0.2.0

func (c *Cookie) SetSameSiteStrict()

func (*Cookie) SetSecure added in v0.2.0

func (c *Cookie) SetSecure()

type Cronjob

type Cronjob interface {
	// Imports
	Component
	// Methods
	Schedule() // runner
}

Cronjob component

type Cronjob_

type Cronjob_ struct {
	// Parent
	Component_
	// contains filtered or unexported fields
}

Cronjob_ is a parent.

func (*Cronjob_) OnCreate added in v0.2.1

func (j *Cronjob_) OnCreate(compName string, stage *Stage)

func (*Cronjob_) Stage added in v0.2.1

func (j *Cronjob_) Stage() *Stage

type FCGIBackend added in v0.2.2

type FCGIBackend struct {
	// Parent
	Backend_[*fcgiNode]
}

FCGIBackend is an FCGI backend.

func (*FCGIBackend) CreateNode added in v0.2.2

func (b *FCGIBackend) CreateNode(compName string) Node

func (*FCGIBackend) FetchExchan added in v0.2.2

func (b *FCGIBackend) FetchExchan(httpReq ServerRequest) (*fcgiExchan, error)

func (*FCGIBackend) OnConfigure added in v0.2.2

func (b *FCGIBackend) OnConfigure()

func (*FCGIBackend) OnPrepare added in v0.2.2

func (b *FCGIBackend) OnPrepare()

func (*FCGIBackend) StoreExchan added in v0.2.2

func (b *FCGIBackend) StoreExchan(exchan *fcgiExchan)

type FCGIProxyConfig added in v0.2.4

type FCGIProxyConfig struct {
	HTTPProxyConfig        // embeded
	ScriptFilename  []byte // for SCRIPT_FILENAME
	IndexFile       []byte // the file that will be used as index
}

FCGIProxyConfig

type Gate added in v0.2.0

type Gate interface {

	// Methods
	Shut() error
	IsShut() bool
	// contains filtered or unexported methods
}

Gate is the interface for all gates. Gates are not components.

type Gate_

type Gate_[S Server] struct {
	// contains filtered or unexported fields
}

Gate_ is a parent.

func (*Gate_) Address added in v0.2.1

func (h *Gate_) Address() string

func (*Gate_[S]) DecConn added in v0.2.0

func (g *Gate_[S]) DecConn()

func (*Gate_[S]) ID added in v0.2.0

func (g *Gate_[S]) ID() int32

func (*Gate_[S]) IncConn added in v0.2.0

func (g *Gate_[S]) IncConn()

func (*Gate_[S]) IsShut added in v0.2.0

func (g *Gate_[S]) IsShut() bool

func (*Gate_[S]) MarkShut added in v0.2.0

func (g *Gate_[S]) MarkShut()

func (*Gate_[S]) OnNew added in v0.2.1

func (g *Gate_[S]) OnNew(server S, id int32)

func (*Gate_) ReadTimeout added in v0.2.1

func (h *Gate_) ReadTimeout() time.Duration

func (*Gate_[S]) Server added in v0.2.1

func (g *Gate_[S]) Server() S

func (*Gate_) Stage added in v0.2.1

func (h *Gate_) Stage() *Stage

func (*Gate_) TLSConfig added in v0.2.1

func (h *Gate_) TLSConfig() *tls.Config

func (*Gate_) TLSMode added in v0.2.1

func (h *Gate_) TLSMode() bool

func (*Gate_) UDSMode added in v0.2.1

func (h *Gate_) UDSMode() bool

func (*Gate_[S]) WaitConns added in v0.2.0

func (g *Gate_[S]) WaitConns()

func (*Gate_) WriteTimeout added in v0.2.1

func (h *Gate_) WriteTimeout() time.Duration

type HTTP1Backend

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

HTTP1Backend

func (*HTTP1Backend) AcquireStream added in v0.2.4

func (b *HTTP1Backend) AcquireStream(servReq ServerRequest) (BackendStream, error)

func (*HTTP1Backend) CreateNode added in v0.2.0

func (b *HTTP1Backend) CreateNode(compName string) Node

func (*HTTP1Backend) OnConfigure added in v0.2.0

func (b *HTTP1Backend) OnConfigure()

func (*HTTP1Backend) OnPrepare added in v0.2.0

func (b *HTTP1Backend) OnPrepare()

func (*HTTP1Backend) ReleaseStream added in v0.2.4

func (b *HTTP1Backend) ReleaseStream(backStream BackendStream)

type HTTP2Backend

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

HTTP2Backend

func (*HTTP2Backend) AcquireStream added in v0.2.4

func (b *HTTP2Backend) AcquireStream(servReq ServerRequest) (BackendStream, error)

func (*HTTP2Backend) CreateNode added in v0.2.0

func (b *HTTP2Backend) CreateNode(compName string) Node

func (*HTTP2Backend) OnConfigure added in v0.2.0

func (b *HTTP2Backend) OnConfigure()

func (*HTTP2Backend) OnPrepare added in v0.2.0

func (b *HTTP2Backend) OnPrepare()

func (*HTTP2Backend) ReleaseStream added in v0.2.4

func (b *HTTP2Backend) ReleaseStream(backStream BackendStream)

type HTTP3Backend

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

HTTP3Backend

func (*HTTP3Backend) AcquireStream added in v0.2.4

func (b *HTTP3Backend) AcquireStream(servReq ServerRequest) (BackendStream, error)

func (*HTTP3Backend) CreateNode added in v0.2.0

func (b *HTTP3Backend) CreateNode(compName string) Node

func (*HTTP3Backend) OnConfigure added in v0.2.0

func (b *HTTP3Backend) OnConfigure()

func (*HTTP3Backend) OnPrepare added in v0.2.0

func (b *HTTP3Backend) OnPrepare()

func (*HTTP3Backend) ReleaseStream added in v0.2.4

func (b *HTTP3Backend) ReleaseStream(backStream BackendStream)

type HTTPBackend added in v0.2.1

type HTTPBackend interface {
	// Imports
	Backend
	// Methods
	AcquireStream(servReq ServerRequest) (BackendStream, error)
	ReleaseStream(backStream BackendStream)
}

HTTPBackend is the http backend.

type HTTPNode added in v0.2.1

type HTTPNode interface {
	// Imports
	Node
	// contains filtered or unexported methods
}

HTTPNode is the http node.

type HTTPProxyConfig added in v0.2.4

type HTTPProxyConfig struct {
	// Inbound, to origin servers
	BufferClientContent bool
	Hostname            []byte // overrides client provided hostname
	Colonport           []byte // overrides client provided colonport
	InboundViaName      []byte
	AppendPathPrefix    []byte
	AddRequestHeaders   map[string]Value
	DelRequestHeaders   [][]byte
	// Outbound, to user agents
	BufferServerContent bool
	OutboundViaName     []byte
	AddResponseHeaders  map[string]Value
	DelResponseHeaders  [][]byte
}

HTTPProxyConfig

type HTTPServer added in v0.2.1

type HTTPServer interface {
	// Imports
	Server
	// Methods
	MaxConcurrentConnsPerGate() int32
	// contains filtered or unexported methods
}

HTTPServer is the http server.

type Handle

type Handle func(req ServerRequest, resp ServerResponse)

Handle is a function which handles an http request and gives an http response.

type Handlet

type Handlet interface {
	// Imports
	Component
	// Methods
	IsProxy() bool // reverse proxies and origins are different, we must differentiate them
	IsCache() bool // proxy caches and reverse proxies are different, we must differentiate them
	Handle(req ServerRequest, resp ServerResponse) (handled bool)
}

Handlet component handles the incoming request and gives an outgoing response if the request is handled.

type Handlet_

type Handlet_ struct {
	// Parent
	Component_
	// contains filtered or unexported fields
}

Handlet_ is a parent.

func (*Handlet_) Dispatch added in v0.2.0

func (h *Handlet_) Dispatch(req ServerRequest, resp ServerResponse, notFound Handle)

func (*Handlet_) IsCache added in v0.2.0

func (h *Handlet_) IsCache() bool

func (*Handlet_) IsProxy added in v0.2.0

func (h *Handlet_) IsProxy() bool

func (*Handlet_) OnCreate added in v0.2.1

func (h *Handlet_) OnCreate(compName string, stage *Stage, webapp *Webapp)

func (*Handlet_) Stage added in v0.2.1

func (h *Handlet_) Stage() *Stage

func (*Handlet_) UseMapper added in v0.2.0

func (h *Handlet_) UseMapper(handlet Handlet, mapper Mapper)

func (*Handlet_) Webapp added in v0.2.1

func (h *Handlet_) Webapp() *Webapp

type Hcache added in v0.2.1

type Hcache interface {
	// Imports
	Component
	// Methods
	Maintain() // runner
	// TODO: design good apis
	Set(key []byte, hobject *Hobject)
	Get(key []byte) (hobject *Hobject)
	Del(key []byte) bool
}

Hcache component is the interface to storages of HTTP caching.

type Hcache_ added in v0.2.1

type Hcache_ struct {
	// Parent
	Component_
	// contains filtered or unexported fields
}

Hcache_ is a parent.

func (*Hcache_) OnCreate added in v0.2.1

func (c *Hcache_) OnCreate(compName string, stage *Stage)

func (*Hcache_) Stage added in v0.2.1

func (c *Hcache_) Stage() *Stage

type Hobject

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

Hobject represents an HTTP object in Hcache.

type Hstate added in v0.2.1

type Hstate interface {
	// Imports
	Component
	// Methods
	Maintain() // runner
	Set(sid []byte, sess *Session) error
	Get(sid []byte) (sess *Session, err error)
	Del(sid []byte) error
}

Hstate is the component interface to storages of HTTP states.

type Hstate_ added in v0.2.1

type Hstate_ struct {
	// Parent
	Component_
	// contains filtered or unexported fields
}

Hstate_ is a parent.

func (*Hstate_) OnCreate added in v0.2.1

func (s *Hstate_) OnCreate(compName string, stage *Stage)

func (*Hstate_) Stage added in v0.2.1

func (s *Hstate_) Stage() *Stage

type LogConfig added in v0.2.0

type LogConfig struct {
	Target  string   // "/path/to/file.log", "1.2.3.4:5678", ...
	Rotate  string   // "day", "hour", ...
	Fields  []string // ("uri", "status"), ...
	BufSize int32    // size of log buffer
}

LogConfig

type Logger added in v0.2.0

type Logger interface {
	Logf(f string, v ...any)
	Close()
}

Logger

type Mapper added in v0.1.3

type Mapper interface {
	FindHandle(req ServerRequest) Handle // called firstly
	HandleName(req ServerRequest) string // called secondly
}

Mapper performs request mapping in handlets. Mappers are not components.

type Node added in v0.2.0

type Node interface {
	// Imports
	Component

	// Methods
	Maintain() // runner
	// contains filtered or unexported methods
}

Node is a member of backend.

type Node_ added in v0.2.0

type Node_[B Backend] struct {
	// Parent
	Component_
	// contains filtered or unexported fields
}

Node_ is a parent.

func (*Node_) Address added in v0.2.1

func (h *Node_) Address() string

func (*Node_[B]) Backend added in v0.2.1

func (n *Node_[B]) Backend() B

func (*Node_[B]) DecConn added in v0.2.4

func (n *Node_[B]) DecConn()

func (*Node_[B]) DecConns added in v0.2.4

func (n *Node_[B]) DecConns(size int)

func (*Node_[B]) DialTimeout added in v0.2.1

func (n *Node_[B]) DialTimeout() time.Duration

func (*Node_[B]) IncConn added in v0.2.4

func (n *Node_[B]) IncConn()

func (*Node_[B]) OnConfigure added in v0.2.0

func (n *Node_[B]) OnConfigure()

func (*Node_[B]) OnCreate added in v0.2.0

func (n *Node_[B]) OnCreate(compName string, stage *Stage, backend B)

func (*Node_[B]) OnPrepare added in v0.2.0

func (n *Node_[B]) OnPrepare()

func (*Node_[B]) OnShutdown added in v0.2.0

func (n *Node_[B]) OnShutdown()

func (*Node_) ReadTimeout added in v0.2.1

func (h *Node_) ReadTimeout() time.Duration

func (*Node_) Stage added in v0.2.1

func (h *Node_) Stage() *Stage

func (*Node_) TLSConfig added in v0.2.0

func (h *Node_) TLSConfig() *tls.Config

func (*Node_) TLSMode added in v0.2.1

func (h *Node_) TLSMode() bool

func (*Node_) UDSMode added in v0.2.1

func (h *Node_) UDSMode() bool

func (*Node_[B]) WaitConns added in v0.2.4

func (n *Node_[B]) WaitConns()

func (*Node_) WriteTimeout added in v0.2.1

func (h *Node_) WriteTimeout() time.Duration

type Piece

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

Piece is a member of content chain.

func GetPiece added in v0.2.0

func GetPiece() *Piece

func (*Piece) File added in v0.2.0

func (p *Piece) File() *os.File

func (*Piece) IsFile added in v0.2.0

func (p *Piece) IsFile() bool

func (*Piece) IsText added in v0.2.0

func (p *Piece) IsText() bool

func (*Piece) Next added in v0.2.0

func (p *Piece) Next() *Piece

func (*Piece) SetFile added in v0.2.0

func (p *Piece) SetFile(file *os.File, info os.FileInfo, shut bool)

func (*Piece) SetText added in v0.2.0

func (p *Piece) SetText(text []byte)

func (*Piece) Text added in v0.2.0

func (p *Piece) Text() []byte

type QConn

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

QConn is a backend-side quix connection to quixNode.

func (*QConn) Close added in v0.2.0

func (c *QConn) Close() error

func (*QConn) DialStream added in v0.2.2

func (c *QConn) DialStream() (*QStream, error)

func (*QConn) MakeTempName added in v0.2.0

func (c *QConn) MakeTempName(dst []byte, unixTime int64) int

func (*QConn) TLSMode added in v0.2.1

func (c *QConn) TLSMode() bool

func (*QConn) UDSMode added in v0.2.1

func (c *QConn) UDSMode() bool

type QStream added in v0.1.4

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

QStream is a bidirectional stream of QConn.

func (*QStream) Close added in v0.2.0

func (s *QStream) Close() error

func (*QStream) Read added in v0.2.0

func (s *QStream) Read(dst []byte) (n int, err error)

func (*QStream) Write added in v0.2.0

func (s *QStream) Write(src []byte) (n int, err error)

type QUIXBackend added in v0.2.0

type QUIXBackend struct {
	// Parent
	Backend_[*quixNode]
}

QUIXBackend component.

func (*QUIXBackend) CreateNode added in v0.2.0

func (b *QUIXBackend) CreateNode(compName string) Node

func (*QUIXBackend) DialStream added in v0.2.2

func (b *QUIXBackend) DialStream() (*QStream, error)

func (*QUIXBackend) OnConfigure added in v0.2.0

func (b *QUIXBackend) OnConfigure()

func (*QUIXBackend) OnPrepare added in v0.2.0

func (b *QUIXBackend) OnPrepare()

type QUIXConn added in v0.2.0

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

QUIXConn is a QUIX connection coming from QUIXRouter.

func (*QUIXConn) MakeTempName added in v0.2.0

func (c *QUIXConn) MakeTempName(dst []byte, unixTime int64) int

func (*QUIXConn) TLSMode added in v0.2.1

func (c *QUIXConn) TLSMode() bool

func (*QUIXConn) UDSMode added in v0.2.1

func (c *QUIXConn) UDSMode() bool

type QUIXDealet added in v0.2.0

type QUIXDealet interface {
	// Imports
	Component
	// Methods
	DealWith(conn *QUIXConn, stream *QUIXStream) (dealt bool)
}

QUIXDealet

type QUIXDealet_ added in v0.2.0

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

QUIXDealet_ is a parent.

func (*QUIXDealet_) OnCreate added in v0.2.1

func (d *QUIXDealet_) OnCreate(compName string, stage *Stage)

func (*QUIXDealet_) Stage added in v0.2.1

func (d *QUIXDealet_) Stage() *Stage

type QUIXProxyConfig added in v0.2.0

type QUIXProxyConfig struct {
}

QUIXProxyConfig

type QUIXRouter added in v0.2.0

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

QUIXRouter

func (*QUIXRouter) DecCase added in v0.2.4

func (r *QUIXRouter) DecCase()

func (*QUIXRouter) DecDealet added in v0.2.4

func (r *QUIXRouter) DecDealet()

func (*QUIXRouter) MaxConcurrentConnsPerGate added in v0.2.1

func (r *QUIXRouter) MaxConcurrentConnsPerGate() int32

func (*QUIXRouter) MaxConcurrentStreamsPerConn added in v0.2.1

func (h *QUIXRouter) MaxConcurrentStreamsPerConn() int32

func (*QUIXRouter) MaxCumulativeStreamsPerConn added in v0.2.1

func (h *QUIXRouter) MaxCumulativeStreamsPerConn() int32

func (*QUIXRouter) OnConfigure added in v0.2.0

func (r *QUIXRouter) OnConfigure()

func (*QUIXRouter) OnPrepare added in v0.2.0

func (r *QUIXRouter) OnPrepare()

func (*QUIXRouter) Serve added in v0.2.0

func (r *QUIXRouter) Serve()

type QUIXStream added in v0.2.0

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

QUIXStream

func (*QUIXStream) Read added in v0.2.0

func (s *QUIXStream) Read(dst []byte) (n int, err error)

func (*QUIXStream) Write added in v0.2.0

func (s *QUIXStream) Write(src []byte) (n int, err error)

type RPCServer added in v0.2.0

type RPCServer interface {
	// Imports
	Server
	// Methods
	BindServices()
}

RPCServer

type Range added in v0.2.0

type Range struct {
	From, Last int64 // [From:Last], inclusive
}

Range defines a range.

type Region added in v0.2.0

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

Region

func (*Region) Free added in v0.2.0

func (r *Region) Free()

func (*Region) Init added in v0.2.0

func (r *Region) Init()

func (*Region) Make added in v0.2.0

func (r *Region) Make(size int) []byte

type Reviser

type Reviser interface {
	// Imports
	Component
	// Methods
	ID() uint8

	Rank() int8 // 0-31 (with 0-15 as tunable, 16-31 as fixed)

	// For incoming requests, either sized or vague
	BeforeRecv(req ServerRequest, resp ServerResponse)                 // for sized content
	BeforeDraw(req ServerRequest, resp ServerResponse)                 // for vague content
	OnInput(req ServerRequest, resp ServerResponse, input *Chain) bool // for both sized and vague
	FinishDraw(req ServerRequest, resp ServerResponse)                 // for vague content

	// For outgoing responses, either sized or vague
	BeforeSend(req ServerRequest, resp ServerResponse)              // for sized content
	BeforeEcho(req ServerRequest, resp ServerResponse)              // for vague content
	OnOutput(req ServerRequest, resp ServerResponse, output *Chain) // for both sized and vague
	FinishEcho(req ServerRequest, resp ServerResponse)              // for vague content
	// contains filtered or unexported methods
}

Reviser component revises incoming requests and outgoing responses.

type Reviser_

type Reviser_ struct {
	// Parent
	Component_
	// contains filtered or unexported fields
}

Reviser_ is a parent.

func (*Reviser_) ID added in v0.2.0

func (r *Reviser_) ID() uint8

func (*Reviser_) OnCreate added in v0.2.1

func (r *Reviser_) OnCreate(compName string, stage *Stage, webapp *Webapp)

func (*Reviser_) Stage added in v0.2.1

func (r *Reviser_) Stage() *Stage

func (*Reviser_) Webapp added in v0.2.1

func (r *Reviser_) Webapp() *Webapp

type Rule

type Rule struct {
	// Parent
	Component_
	// contains filtered or unexported fields
}

Rule component defines a rule for matching requests and handlets.

func (*Rule) OnConfigure added in v0.2.0

func (r *Rule) OnConfigure()

func (*Rule) OnPrepare added in v0.2.0

func (r *Rule) OnPrepare()

func (*Rule) OnShutdown added in v0.2.0

func (r *Rule) OnShutdown()

type SCGIBackend added in v0.2.2

type SCGIBackend struct {
	// Parent
	Backend_[*scgiNode]
}

SCGIBackend

func (*SCGIBackend) CreateNode added in v0.2.2

func (b *SCGIBackend) CreateNode(compName string) Node

func (*SCGIBackend) Dial added in v0.2.4

func (b *SCGIBackend) Dial(httpReq ServerRequest) (*scgiExchan, error)

func (*SCGIBackend) OnConfigure added in v0.2.2

func (b *SCGIBackend) OnConfigure()

func (*SCGIBackend) OnPrepare added in v0.2.2

func (b *SCGIBackend) OnPrepare()

type SCGIProxyConfig added in v0.2.4

type SCGIProxyConfig struct {
	HTTPProxyConfig // embeded
}

SCGIProxyConfig

type SOCKProxyConfig added in v0.2.4

type SOCKProxyConfig struct {
}

SOCKProxyConfig

type Server

type Server interface {
	// Imports
	Component
	// Methods
	Serve() // runner
	// contains filtered or unexported methods
}

Server component. A Server has a group of Gates.

type ServerRequest added in v0.2.2

type ServerRequest interface {
	RemoteAddr() net.Addr
	Webapp() *Webapp

	IsAsteriskOptions() bool // OPTIONS *

	VersionCode() uint8
	IsHTTP1() bool
	IsHTTP1_0() bool
	IsHTTP1_1() bool
	IsHTTP2() bool
	IsHTTP3() bool
	Version() string // HTTP/1.0, HTTP/1.1, HTTP/2, HTTP/3
	RiskyVersion() []byte

	SchemeCode() uint8 // SchemeHTTP, SchemeHTTPS
	IsHTTP() bool
	IsHTTPS() bool
	Scheme() string // http, https
	RiskyScheme() []byte

	IsGET() bool
	IsHEAD() bool
	IsPOST() bool
	IsPUT() bool
	IsDELETE() bool
	IsCONNECT() bool
	IsOPTIONS() bool
	IsTRACE() bool
	Method() string // GET, POST, ...
	RiskyMethod() []byte

	Authority() string      // hostname[:port]
	RiskyAuthority() []byte // hostname[:port]
	Hostname() string       // hostname
	RiskyHostname() []byte  // hostname
	Colonport() string      // :port
	RiskyColonport() []byte // :port

	URI() string              // /encodedPath?queryString
	RiskyURI() []byte         // /encodedPath?queryString
	Path() string             // /decodedPath
	RiskyPath() []byte        // /decodedPath
	EncodedPath() string      // /encodedPath
	RiskyEncodedPath() []byte // /encodedPath
	QueryString() string      // including '?' if query string exists, otherwise empty
	RiskyQueryString() []byte // including '?' if query string exists, otherwise empty

	HasQueries() bool
	AllQueries() (queries [][2]string)
	Q(name string) string
	Qstr(name string, defaultValue string) string
	Qint(name string, defaultValue int) int
	Query(name string) (value string, ok bool)
	RiskyQuery(name string) (value []byte, ok bool)
	Queries(name string) (values []string, ok bool)
	HasQuery(name string) bool
	DelQuery(name string) (deleted bool)
	AddQuery(name string, value string) bool

	HasHeaders() bool
	AllHeaderLines() (headerLines [][2]string)
	H(name string) string
	Hstr(name string, defaultValue string) string
	Hint(name string, defaultValue int) int
	Header(name string) (value string, ok bool)
	RiskyHeader(name string) (value []byte, ok bool)
	Headers(name string) (values []string, ok bool)
	HasHeader(name string) bool
	DelHeader(name string) (deleted bool)
	AddHeader(name string, value string) bool

	UserAgent() string
	RiskyUserAgent() []byte

	ContentType() string
	RiskyContentType() []byte

	ContentIsEncoded() bool

	ContentSize() int64
	RiskyContentLength() []byte

	AcceptTrailers() bool

	EvalPreconditions(date int64, etag []byte, asOrigin bool) (status int16, normal bool)

	HasIfRange() bool
	EvalIfRange(date int64, etag []byte, asOrigin bool) (canRange bool)

	HasRanges() bool
	EvalRanges(size int64) []Range

	HasCookies() bool
	AllCookies() (cookies [][2]string)
	C(name string) string
	Cstr(name string, defaultValue string) string
	Cint(name string, defaultValue int) int
	Cookie(name string) (value string, ok bool)
	RiskyCookie(name string) (value []byte, ok bool)
	Cookies(name string) (values []string, ok bool)
	HasCookie(name string) bool
	DelCookie(name string) (deleted bool)
	AddCookie(name string, value string) bool

	SetRecvTimeout(timeout time.Duration) // to defend against slowloris attack
	HasContent() bool                     // true if content exists
	IsVague() bool                        // true if content exists and is not sized
	Content() string
	RiskyContent() []byte

	HasForms() bool
	AllForms() (forms [][2]string)
	F(name string) string
	Fstr(name string, defaultValue string) string
	Fint(name string, defaultValue int) int
	Form(name string) (value string, ok bool)
	RiskyForm(name string) (value []byte, ok bool)
	Forms(name string) (values []string, ok bool)
	HasForm(name string) bool
	AddForm(name string, value string) bool

	HasUpfiles() bool
	AllUpfiles() (upfiles []*Upfile)
	U(name string) *Upfile
	Upfile(name string) (upfile *Upfile, ok bool)
	Upfiles(name string) (upfiles []*Upfile, ok bool)
	HasUpfile(name string) bool

	HasTrailers() bool
	AllTrailerLines() (trailerLines [][2]string)
	T(name string) string
	Tstr(name string, defaultValue string) string
	Tint(name string, defaultValue int) int
	Trailer(name string) (value string, ok bool)
	RiskyTrailer(name string) (value []byte, ok bool)
	Trailers(name string) (values []string, ok bool)
	HasTrailer(name string) bool
	DelTrailer(name string) (deleted bool)
	AddTrailer(name string, value string) bool

	RiskyMake(size int) []byte
	// contains filtered or unexported methods
}

ServerRequest is the server-side http request.

type ServerResponse added in v0.2.2

type ServerResponse interface {
	Request() ServerRequest

	SetStatus(status int16) error
	Status() int16

	MakeETagFrom(date int64, size int64) ([]byte, bool) // with `""`
	SetExpires(expires int64) bool
	SetLastModified(lastModified int64) bool
	AddContentType(contentType string) bool
	AddContentTypeBytes(contentType []byte) bool
	AddHTTPSRedirection(authority string) bool
	AddHostnameRedirection(hostname string) bool
	AddDirectoryRedirection() bool

	AddCookie(cookie *Cookie) bool

	AddHeader(name string, value string) bool
	AddHeaderBytes(name []byte, value []byte) bool
	Header(name string) (value string, ok bool)
	HasHeader(name string) bool
	DelHeader(name string) bool
	DelHeaderBytes(name []byte) bool

	IsSent() bool
	SetSendTimeout(timeout time.Duration) // to defend against slowloris attack

	Send(content string) error
	SendBytes(content []byte) error
	SendFile(contentPath string) error
	SendJSON(content any) error
	SendBadRequest(content []byte) error                                                 // 400
	SendForbidden(content []byte) error                                                  // 403
	SendNotFound(content []byte) error                                                   // 404
	SendMethodNotAllowed(allow string, content []byte) error                             // 405
	SendNotAcceptable(content []byte) error                                              // 406
	SendUnsupportedMediaType(acceptEncoding string, accept string, content []byte) error // 415
	SendRangeNotSatisfiable(contentSize int64, content []byte) error                     // 416
	SendInternalServerError(content []byte) error                                        // 500
	SendNotImplemented(content []byte) error                                             // 501
	SendBadGateway(content []byte) error                                                 // 502
	SendGatewayTimeout(content []byte) error                                             // 504

	Echo(chunk string) error
	EchoBytes(chunk []byte) error
	EchoFile(chunkPath string) error
	AddTrailer(name string, value string) bool
	AddTrailerBytes(name []byte, value []byte) bool
	// contains filtered or unexported methods
}

ServerResponse is the server-side http response.

type ServerSocket added in v0.2.2

type ServerSocket interface {
	// TODO
	Read(dst []byte) (int, error)
	Write(src []byte) (int, error)
	Close() error
}

ServerSocket is the server-side webSocket.

type Server_

type Server_[G Gate] struct {
	// Parent
	Component_
	// contains filtered or unexported fields
}

Server_ is a parent.

func (*Server_[G]) AddGate added in v0.2.0

func (s *Server_[G]) AddGate(gate G)

func (*Server_) Address added in v0.2.0

func (h *Server_) Address() string

func (*Server_[G]) Colonport added in v0.2.1

func (s *Server_[G]) Colonport() string

func (*Server_[G]) ColonportBytes added in v0.2.1

func (s *Server_[G]) ColonportBytes() []byte

func (*Server_[G]) DecGate added in v0.2.4

func (s *Server_[G]) DecGate()

func (*Server_[G]) NumGates added in v0.2.0

func (s *Server_[G]) NumGates() int32

func (*Server_[G]) OnConfigure added in v0.2.0

func (s *Server_[G]) OnConfigure()

func (*Server_[G]) OnCreate added in v0.2.0

func (s *Server_[G]) OnCreate(compName string, stage *Stage)

func (*Server_[G]) OnPrepare added in v0.2.0

func (s *Server_[G]) OnPrepare()

func (*Server_[G]) OnShutdown added in v0.2.0

func (s *Server_[G]) OnShutdown()

func (*Server_) ReadTimeout added in v0.2.0

func (h *Server_) ReadTimeout() time.Duration

func (*Server_) Stage added in v0.2.0

func (h *Server_) Stage() *Stage

func (*Server_) TLSConfig added in v0.2.0

func (h *Server_) TLSConfig() *tls.Config

func (*Server_) TLSMode added in v0.2.1

func (h *Server_) TLSMode() bool

func (*Server_) UDSMode added in v0.2.1

func (h *Server_) UDSMode() bool

func (*Server_[G]) WaitGates added in v0.2.4

func (s *Server_[G]) WaitGates()

func (*Server_) WriteTimeout added in v0.2.0

func (h *Server_) WriteTimeout() time.Duration

type Service added in v0.2.0

type Service struct {
	// Parent
	Component_
	// contains filtered or unexported fields
}

Service is the RPC service.

func (*Service) BindServer added in v0.2.0

func (s *Service) BindServer(server RPCServer)

func (*Service) CloseLog added in v0.2.4

func (l *Service) CloseLog()

func (*Service) Logf added in v0.2.0

func (l *Service) Logf(f string, v ...any)

func (*Service) OnConfigure added in v0.2.0

func (s *Service) OnConfigure()

func (*Service) OnPrepare added in v0.2.0

func (s *Service) OnPrepare()

func (*Service) OnShutdown added in v0.2.0

func (s *Service) OnShutdown()

func (*Service) Servers added in v0.2.0

func (s *Service) Servers() []RPCServer

type Session

type Session struct {
	// TODO
	ID      [40]byte // session id
	Secret  [40]byte // secret key
	Created int64    // unix time
	Expires int64    // unix time
	Role    int8     // 0: default, >0: user defined values
	Device  int8     // terminal device type
	// contains filtered or unexported fields
}

Session is an HTTP session in hstate.

func (*Session) Del added in v0.2.0

func (s *Session) Del(name string)

func (*Session) Get added in v0.2.0

func (s *Session) Get(name string) string

func (*Session) Set added in v0.2.0

func (s *Session) Set(name string, value string)

type Socklet

type Socklet interface {
	// Imports
	Component
	// Methods
	IsProxy() bool // reverse proxies and origin servers are different, we must differentiate them
	Serve(req ServerRequest, sock ServerSocket)
}

Socklet component handles the webSocket.

type Socklet_

type Socklet_ struct {
	// Parent
	Component_
	// contains filtered or unexported fields
}

Socklet_ is a parent.

func (*Socklet_) IsProxy added in v0.2.0

func (s *Socklet_) IsProxy() bool

func (*Socklet_) OnCreate added in v0.2.1

func (s *Socklet_) OnCreate(compName string, stage *Stage, webapp *Webapp)

func (*Socklet_) Stage added in v0.2.1

func (s *Socklet_) Stage() *Stage

func (*Socklet_) Webapp added in v0.2.1

func (s *Socklet_) Webapp() *Webapp

type Stage

type Stage struct {
	// Parent
	Component_
	// contains filtered or unexported fields
}

Stage represents a running stage in the worker process.

A worker process may have many stages in its lifetime, especially when new configuration is applied, a new stage is created, or the old one is told to quit.

func StageFromFile added in v0.2.0

func StageFromFile(configBase string, configFile string) (*Stage, error)

func StageFromText added in v0.2.0

func StageFromText(configText string) (*Stage, error)

func (*Stage) Backend added in v0.2.0

func (s *Stage) Backend(compName string) Backend

func (*Stage) Clock added in v0.2.0

func (s *Stage) Clock() *clockFixture

func (*Stage) Cronjob added in v0.2.0

func (s *Stage) Cronjob(compName string) Cronjob

func (*Stage) DecBackend added in v0.2.4

func (s *Stage) DecBackend()

func (*Stage) DecCronjob added in v0.2.4

func (s *Stage) DecCronjob()

func (*Stage) DecHcache added in v0.2.4

func (s *Stage) DecHcache()

func (*Stage) DecHstate added in v0.2.4

func (s *Stage) DecHstate()

func (*Stage) DecRouter added in v0.2.4

func (s *Stage) DecRouter()

func (*Stage) DecServer added in v0.2.4

func (s *Stage) DecServer()

func (*Stage) DecService added in v0.2.4

func (s *Stage) DecService()

func (*Stage) DecWebapp added in v0.2.4

func (s *Stage) DecWebapp()

func (*Stage) Fcache added in v0.2.0

func (s *Stage) Fcache() *fcacheFixture

func (*Stage) Fixture added in v0.2.0

func (s *Stage) Fixture(compSign string) fixture

func (*Stage) Hcache added in v0.2.1

func (s *Stage) Hcache(compName string) Hcache

func (*Stage) Hstate added in v0.2.1

func (s *Stage) Hstate(compName string) Hstate

func (*Stage) ID added in v0.2.0

func (s *Stage) ID() int32

func (*Stage) NumCPU added in v0.2.0

func (s *Stage) NumCPU() int32

func (*Stage) OnConfigure added in v0.2.0

func (s *Stage) OnConfigure()

func (*Stage) OnPrepare added in v0.2.0

func (s *Stage) OnPrepare()

func (*Stage) OnShutdown added in v0.2.0

func (s *Stage) OnShutdown()

func (*Stage) ProfBlock added in v0.2.0

func (s *Stage) ProfBlock()

func (*Stage) ProfCPU added in v0.2.0

func (s *Stage) ProfCPU()

func (*Stage) ProfGoroutine added in v0.2.0

func (s *Stage) ProfGoroutine()

func (*Stage) ProfHeap added in v0.2.0

func (s *Stage) ProfHeap()

func (*Stage) ProfThread added in v0.2.0

func (s *Stage) ProfThread()

func (*Stage) QUIXRouter added in v0.2.0

func (s *Stage) QUIXRouter(compName string) *QUIXRouter

func (*Stage) Quit added in v0.2.0

func (s *Stage) Quit()

func (*Stage) Resolv added in v0.2.0

func (s *Stage) Resolv() *resolvFixture

func (*Stage) Server added in v0.2.0

func (s *Stage) Server(compName string) Server

func (*Stage) Service added in v0.2.0

func (s *Stage) Service(compName string) *Service

func (*Stage) Start added in v0.2.0

func (s *Stage) Start(id int32)

func (*Stage) TCPXRouter added in v0.2.0

func (s *Stage) TCPXRouter(compName string) *TCPXRouter

func (*Stage) UDPXRouter added in v0.2.0

func (s *Stage) UDPXRouter(compName string) *UDPXRouter

func (*Stage) Webapp added in v0.2.0

func (s *Stage) Webapp(compName string) *Webapp

type TCPXBackend added in v0.2.0

type TCPXBackend struct {
	// Parent
	Backend_[*tcpxNode]
}

TCPXBackend component.

func (*TCPXBackend) CreateNode added in v0.2.0

func (b *TCPXBackend) CreateNode(compName string) Node

func (*TCPXBackend) Dial added in v0.2.0

func (b *TCPXBackend) Dial() (*TConn, error)

func (*TCPXBackend) OnConfigure added in v0.2.0

func (b *TCPXBackend) OnConfigure()

func (*TCPXBackend) OnPrepare added in v0.2.0

func (b *TCPXBackend) OnPrepare()

type TCPXConn added in v0.2.0

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

TCPXConn is a TCPX connection coming from TCPXRouter.

func (*TCPXConn) Close added in v0.2.0

func (c *TCPXConn) Close()

func (*TCPXConn) CloseRead added in v0.2.0

func (c *TCPXConn) CloseRead()

func (*TCPXConn) CloseWrite added in v0.2.0

func (c *TCPXConn) CloseWrite()

func (*TCPXConn) MakeTempName added in v0.2.0

func (c *TCPXConn) MakeTempName(dst []byte, unixTime int64) int

func (*TCPXConn) Recv added in v0.2.0

func (c *TCPXConn) Recv() (data []byte, err error)

func (*TCPXConn) Send added in v0.2.0

func (c *TCPXConn) Send(data []byte) (err error)

func (*TCPXConn) Sendv added in v0.2.1

func (c *TCPXConn) Sendv() (err error)

func (*TCPXConn) SetReadDeadline added in v0.2.0

func (c *TCPXConn) SetReadDeadline() error

func (*TCPXConn) SetWriteDeadline added in v0.2.0

func (c *TCPXConn) SetWriteDeadline() error

func (*TCPXConn) TLSMode added in v0.2.1

func (c *TCPXConn) TLSMode() bool

func (*TCPXConn) UDSMode added in v0.2.1

func (c *TCPXConn) UDSMode() bool

type TCPXDealet added in v0.2.0

type TCPXDealet interface {
	// Imports
	Component
	// Methods
	DealWith(conn *TCPXConn) (dealt bool)
}

TCPXDealet

type TCPXDealet_ added in v0.2.0

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

TCPXDealet_ is a parent.

func (*TCPXDealet_) OnCreate added in v0.2.1

func (d *TCPXDealet_) OnCreate(compName string, stage *Stage)

func (*TCPXDealet_) Stage added in v0.2.1

func (d *TCPXDealet_) Stage() *Stage

type TCPXProxyConfig added in v0.2.0

type TCPXProxyConfig struct {
}

TCPXProxyConfig

type TCPXRouter added in v0.2.0

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

TCPXRouter

func (*TCPXRouter) DecCase added in v0.2.4

func (r *TCPXRouter) DecCase()

func (*TCPXRouter) DecDealet added in v0.2.4

func (r *TCPXRouter) DecDealet()

func (*TCPXRouter) MaxConcurrentConnsPerGate added in v0.2.1

func (r *TCPXRouter) MaxConcurrentConnsPerGate() int32

func (*TCPXRouter) OnConfigure added in v0.2.0

func (r *TCPXRouter) OnConfigure()

func (*TCPXRouter) OnPrepare added in v0.2.0

func (r *TCPXRouter) OnPrepare()

func (*TCPXRouter) Serve added in v0.2.0

func (r *TCPXRouter) Serve()

type TConn

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

TConn is a backend-side connection to tcpxNode.

func (*TConn) Close added in v0.2.0

func (c *TConn) Close() error

func (*TConn) CloseRead added in v0.2.1

func (c *TConn) CloseRead()

func (*TConn) CloseWrite added in v0.2.1

func (c *TConn) CloseWrite()

func (*TConn) MakeTempName added in v0.2.0

func (c *TConn) MakeTempName(dst []byte, unixTime int64) int

func (*TConn) Recv added in v0.2.1

func (c *TConn) Recv() (data []byte, err error)

func (*TConn) Send added in v0.2.1

func (c *TConn) Send(data []byte) (err error)

func (*TConn) Sendv added in v0.2.1

func (c *TConn) Sendv() (err error)

func (*TConn) SetReadDeadline added in v0.2.1

func (c *TConn) SetReadDeadline() error

func (*TConn) SetWriteDeadline added in v0.2.1

func (c *TConn) SetWriteDeadline() error

func (*TConn) TLSMode added in v0.2.1

func (c *TConn) TLSMode() bool

func (*TConn) UDSMode added in v0.2.1

func (c *TConn) UDSMode() bool

type UConn

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

UConn

func (*UConn) Close added in v0.2.0

func (c *UConn) Close() error

func (*UConn) MakeTempName added in v0.2.0

func (c *UConn) MakeTempName(dst []byte, unixTime int64) int

func (*UConn) ReadFrom added in v0.2.0

func (c *UConn) ReadFrom(dst []byte) (n int, addr net.Addr, err error)

func (*UConn) UDSMode added in v0.2.1

func (c *UConn) UDSMode() bool

func (*UConn) WriteTo added in v0.2.0

func (c *UConn) WriteTo(src []byte, addr net.Addr) (n int, err error)

type UDPXBackend added in v0.2.0

type UDPXBackend struct {
	// Parent
	Backend_[*udpxNode]
}

UDPXBackend component.

func (*UDPXBackend) CreateNode added in v0.2.0

func (b *UDPXBackend) CreateNode(compName string) Node

func (*UDPXBackend) Dial added in v0.2.0

func (b *UDPXBackend) Dial() (*UConn, error)

func (*UDPXBackend) OnConfigure added in v0.2.0

func (b *UDPXBackend) OnConfigure()

func (*UDPXBackend) OnPrepare added in v0.2.0

func (b *UDPXBackend) OnPrepare()

type UDPXConn added in v0.2.0

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

UDPXConn

func (*UDPXConn) Close added in v0.2.0

func (c *UDPXConn) Close() error

func (*UDPXConn) MakeTempName added in v0.2.0

func (c *UDPXConn) MakeTempName(dst []byte, unixTime int64) int

func (*UDPXConn) ReadFrom added in v0.2.1

func (c *UDPXConn) ReadFrom(dst []byte) (n int, addr net.Addr, err error)

func (*UDPXConn) UDSMode added in v0.2.1

func (c *UDPXConn) UDSMode() bool

func (*UDPXConn) WriteTo added in v0.2.1

func (c *UDPXConn) WriteTo(src []byte, addr net.Addr) (n int, err error)

type UDPXDealet added in v0.2.0

type UDPXDealet interface {
	// Imports
	Component
	// Methods
	DealWith(conn *UDPXConn) (dealt bool)
}

UDPXDealet

type UDPXDealet_ added in v0.2.0

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

UDPXDealet_ is a parent.

func (*UDPXDealet_) OnCreate added in v0.2.1

func (d *UDPXDealet_) OnCreate(compName string, stage *Stage)

func (*UDPXDealet_) Stage added in v0.2.1

func (d *UDPXDealet_) Stage() *Stage

type UDPXProxyConfig added in v0.2.0

type UDPXProxyConfig struct {
}

UDPXProxyConfig

type UDPXRouter added in v0.2.0

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

UDPXRouter

func (*UDPXRouter) DecCase added in v0.2.4

func (r *UDPXRouter) DecCase()

func (*UDPXRouter) DecDealet added in v0.2.4

func (r *UDPXRouter) DecDealet()

func (*UDPXRouter) OnConfigure added in v0.2.0

func (r *UDPXRouter) OnConfigure()

func (*UDPXRouter) OnPrepare added in v0.2.0

func (r *UDPXRouter) OnPrepare()

func (*UDPXRouter) Serve added in v0.2.0

func (r *UDPXRouter) Serve()

type Upfile added in v0.2.0

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

Upfile is a file uploaded by http client and used by http server.

func (*Upfile) Base added in v0.2.0

func (u *Upfile) Base() string

func (*Upfile) Error added in v0.2.0

func (u *Upfile) Error() error

func (*Upfile) IsOK added in v0.2.0

func (u *Upfile) IsOK() bool

func (*Upfile) MoveTo added in v0.2.0

func (u *Upfile) MoveTo(path string) error

func (*Upfile) Name added in v0.2.0

func (u *Upfile) Name() string

func (*Upfile) Path added in v0.2.0

func (u *Upfile) Path() string

func (*Upfile) Size added in v0.2.0

func (u *Upfile) Size() int64

func (*Upfile) Type added in v0.2.0

func (u *Upfile) Type() string

type Value added in v0.2.0

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

Value is a value in config file.

func (*Value) Bool added in v0.2.0

func (v *Value) Bool() (b bool, ok bool)

func (*Value) Bytes added in v0.2.0

func (v *Value) Bytes() (p []byte, ok bool)

func (*Value) BytesList added in v0.2.0

func (v *Value) BytesList() (list [][]byte, ok bool)

func (*Value) BytesVar added in v0.2.0

func (v *Value) BytesVar(keeper varKeeper) []byte

func (*Value) Dict added in v0.2.0

func (v *Value) Dict() (dict map[string]Value, ok bool)

func (*Value) Duration added in v0.2.0

func (v *Value) Duration() (d time.Duration, ok bool)

func (*Value) Int added in v0.2.0

func (v *Value) Int() (i int, ok bool)

func (*Value) Int8 added in v0.2.0

func (v *Value) Int8() (i8 int8, ok bool)

func (*Value) Int16 added in v0.2.0

func (v *Value) Int16() (i16 int16, ok bool)

func (*Value) Int32 added in v0.2.0

func (v *Value) Int32() (i32 int32, ok bool)

func (*Value) Int64 added in v0.2.0

func (v *Value) Int64() (i64 int64, ok bool)

func (*Value) IsBool added in v0.2.0

func (v *Value) IsBool() bool

func (*Value) IsDict added in v0.2.0

func (v *Value) IsDict() bool

func (*Value) IsDuration added in v0.2.0

func (v *Value) IsDuration() bool

func (*Value) IsInteger added in v0.2.0

func (v *Value) IsInteger() bool

func (*Value) IsList added in v0.2.0

func (v *Value) IsList() bool

func (*Value) IsString added in v0.2.0

func (v *Value) IsString() bool

func (*Value) IsVariable added in v0.2.0

func (v *Value) IsVariable() bool

func (*Value) List added in v0.2.0

func (v *Value) List() (list []Value, ok bool)

func (*Value) ListN added in v0.2.0

func (v *Value) ListN(n int) (list []Value, ok bool)

func (*Value) String added in v0.2.0

func (v *Value) String() (s string, ok bool)

func (*Value) StringDict added in v0.2.0

func (v *Value) StringDict() (dict map[string]string, ok bool)

func (*Value) StringList added in v0.2.0

func (v *Value) StringList() (list []string, ok bool)

func (*Value) StringListN added in v0.2.0

func (v *Value) StringListN(n int) (list []string, ok bool)

func (*Value) StringVar added in v0.2.0

func (v *Value) StringVar(keeper varKeeper) string

func (*Value) Uint32 added in v0.2.0

func (v *Value) Uint32() (u32 uint32, ok bool)

type Webapp added in v0.2.0

type Webapp struct {
	// Parent
	Component_
	// contains filtered or unexported fields
}

Webapp is the Web application.

func (*Webapp) AddSetting added in v0.2.0

func (a *Webapp) AddSetting(name string, value string)

func (*Webapp) CloseLog added in v0.2.4

func (l *Webapp) CloseLog()

func (*Webapp) DecHandlet added in v0.2.4

func (a *Webapp) DecHandlet()

func (*Webapp) DecReviser added in v0.2.4

func (a *Webapp) DecReviser()

func (*Webapp) DecRule added in v0.2.4

func (a *Webapp) DecRule()

func (*Webapp) DecSocklet added in v0.2.4

func (a *Webapp) DecSocklet()

func (*Webapp) Handlet added in v0.2.0

func (a *Webapp) Handlet(compName string) Handlet

func (*Webapp) Logf added in v0.2.0

func (l *Webapp) Logf(f string, v ...any)

func (*Webapp) OnConfigure added in v0.2.0

func (a *Webapp) OnConfigure()

func (*Webapp) OnPrepare added in v0.2.0

func (a *Webapp) OnPrepare()

func (*Webapp) OnShutdown added in v0.2.0

func (a *Webapp) OnShutdown()

func (*Webapp) Reviser added in v0.2.0

func (a *Webapp) Reviser(compName string) Reviser

func (*Webapp) Rule added in v0.2.0

func (a *Webapp) Rule(compName string) *Rule

func (*Webapp) Setting added in v0.2.0

func (a *Webapp) Setting(name string) (value string, ok bool)

func (*Webapp) Socklet added in v0.2.0

func (a *Webapp) Socklet(compName string) Socklet

Jump to

Keyboard shortcuts

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