server

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 19 Imported by: 809

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithALPN

func WithALPN(enable bool) config.Option

WithALPN sets whether enable ALPN.

func WithAltTransport added in v0.5.0

func WithAltTransport(transporter func(options *config.Options) network.Transporter) config.Option

WithAltTransport sets which network library to use as an alternative transporter(need to be implemented by specific transporter).

func WithAutoReloadRender added in v0.3.1

func WithAutoReloadRender(b bool, interval time.Duration) config.Option

WithAutoReloadRender sets the config of auto reload render. If auto reload render is enabled: 1. interval = 0 means reload render according to file watch mechanism.(recommended) 2. interval > 0 means reload render every interval.

func WithBasePath added in v0.5.0

func WithBasePath(basePath string) config.Option

WithBasePath sets basePath.Must be "/" prefix and suffix,If not the default concatenate "/"

func WithBindConfig added in v0.7.0

func WithBindConfig(bc *binding.BindConfig) config.Option

WithBindConfig sets bind config.

func WithCustomBinder added in v0.7.0

func WithCustomBinder(b binding.Binder) config.Option

WithCustomBinder sets customized Binder.

func WithCustomValidator added in v0.7.0

func WithCustomValidator(b binding.StructValidator) config.Option

WithCustomValidator sets customized Binder.

func WithDisableDefaultContentType added in v0.7.2

func WithDisableDefaultContentType(disable bool) config.Option

func WithDisableDefaultDate added in v0.7.2

func WithDisableDefaultDate(disable bool) config.Option

func WithDisableHeaderNamesNormalizing added in v0.7.0

func WithDisableHeaderNamesNormalizing(disable bool) config.Option

WithDisableHeaderNamesNormalizing is used to set whether disable header names normalizing.

func WithDisablePreParseMultipartForm

func WithDisablePreParseMultipartForm(b bool) config.Option

WithDisablePreParseMultipartForm sets disablePreParseMultipartForm.

This option is useful for servers that desire to treat multipart form data as a binary blob, or choose when to parse the data. Server pre parses multipart form data by default.

func WithDisablePrintRoute added in v0.4.0

func WithDisablePrintRoute(b bool) config.Option

WithDisablePrintRoute sets whether disable debugPrintRoute If we don't set it, it will default to false

func WithExitWaitTime

func WithExitWaitTime(timeout time.Duration) config.Option

WithExitWaitTime sets timeout for graceful shutdown.

The server may exit ahead after all connections closed. All responses after shutdown will be added 'Connection: close' header.

func WithGetOnly

func WithGetOnly(isOnly bool) config.Option

WithGetOnly sets whether accept GET request only. Default: false

func WithH2C

func WithH2C(enable bool) config.Option

WithH2C sets whether enable H2C.

func WithHandleMethodNotAllowed

func WithHandleMethodNotAllowed(b bool) config.Option

WithHandleMethodNotAllowed sets handleMethodNotAllowed.

If enabled, the router checks if another method is allowed for the current route, if the current request can not be routed. If this is the case, the request is answered with 'Method Not Allowed' and HTTP status code 405. If no other Method is allowed, the request is delegated to the NotFound handler.

func WithHostPorts

func WithHostPorts(hp string) config.Option

WithHostPorts sets listening address.

func WithIdleTimeout

func WithIdleTimeout(t time.Duration) config.Option

WithIdleTimeout sets idle timeout.

Close the connection when the successive request timeout (in keepalive mode). Set this to protect server from misbehavior clients.

func WithKeepAlive

func WithKeepAlive(b bool) config.Option

WithKeepAlive sets Whether use long connection. Default: true

func WithKeepAliveTimeout

func WithKeepAliveTimeout(t time.Duration) config.Option

WithKeepAliveTimeout sets keep-alive timeout.

In most cases, there is no need to care about this option.

func WithListenConfig

func WithListenConfig(l *net.ListenConfig) config.Option

WithListenConfig sets listener config.

func WithMaxKeepBodySize

func WithMaxKeepBodySize(bs int) config.Option

WithMaxKeepBodySize sets max size of request/response body to keep when recycled. Unit: byte

Body buffer which larger than this size will be put back into buffer poll.

func WithMaxRequestBodySize

func WithMaxRequestBodySize(bs int) config.Option

WithMaxRequestBodySize sets the limitation of request body size. Unit: byte

Body buffer which larger than this size will be put back into buffer poll.

func WithNetwork

func WithNetwork(nw string) config.Option

WithNetwork sets network. Support "tcp", "udp", "unix"(unix domain socket).

func WithOnAccept added in v0.5.0

func WithOnAccept(fn func(conn net.Conn) context.Context) config.Option

WithOnAccept sets the callback function when a new connection is accepted but cannot receive data in netpoll. In go net, it will be called before converting tls connection

func WithOnConnect added in v0.5.0

func WithOnConnect(fn func(ctx context.Context, conn network.Conn) context.Context) config.Option

WithOnConnect sets the onConnect function. It can received data from connection in netpoll. In go net, it will be called after converting tls connection.

func WithReadBufferSize

func WithReadBufferSize(size int) config.Option

WithReadBufferSize sets the read buffer size which also limit the header size.

func WithReadTimeout

func WithReadTimeout(t time.Duration) config.Option

WithReadTimeout sets read timeout.

Close the connection when read request timeout.

func WithRedirectFixedPath

func WithRedirectFixedPath(b bool) config.Option

WithRedirectFixedPath sets redirectFixedPath.

If enabled, the router tries to fix the current request path, if no handle is registered for it. First superfluous path elements like ../ or // are removed. Afterwards the router does a case-insensitive lookup of the cleaned path. If a handle can be found for this route, the router makes a redirection to the corrected path with status code 301 for GET requests and 308 for all other request methods. For example /FOO and /..//Foo could be redirected to /foo. RedirectTrailingSlash is independent of this option.

func WithRedirectTrailingSlash

func WithRedirectTrailingSlash(b bool) config.Option

WithRedirectTrailingSlash sets redirectTrailingSlash.

Enables automatic redirection if the current route can't be matched but a handler for the path with (without) the trailing slash exists. For example if /foo/ is requested but a route only exists for /foo, the client is redirected to /foo with http status code 301 for GET requests and 307 for all other request methods.

func WithRegistry added in v0.3.0

func WithRegistry(r registry.Registry, info *registry.Info) config.Option

WithRegistry sets the registry and registry's info

func WithRemoveExtraSlash

func WithRemoveExtraSlash(b bool) config.Option

WithRemoveExtraSlash sets removeExtraSlash.

RemoveExtraSlash a parameter can be parsed from the URL even with extra slashes. If UseRawPath is false (by default), the RemoveExtraSlash effectively is true, as url.Path gonna be used, which is already cleaned.

func WithStreamBody

func WithStreamBody(b bool) config.Option

WithStreamBody determines whether read body in stream or not.

StreamRequestBody enables streaming request body, and calls the handler sooner when given body is larger than the current limit.

func WithTLS

func WithTLS(cfg *tls.Config) config.Option

WithTLS sets TLS config to start a tls server.

NOTE: If a tls server is started, it won't accept non-tls request.

func WithTraceLevel

func WithTraceLevel(level stats.Level) config.Option

WithTraceLevel sets the level trace.

func WithTracer

func WithTracer(t tracer.Tracer) config.Option

WithTracer adds tracer to server.

func WithTransport

func WithTransport(transporter func(options *config.Options) network.Transporter) config.Option

WithTransport sets which network library to use.

func WithUnescapePathValues

func WithUnescapePathValues(b bool) config.Option

WithUnescapePathValues sets unescapePathValues.

If true, the path value will be unescaped. If UseRawPath is false (by default), the UnescapePathValues effectively is true, as url.Path gonna be used, which is already unescaped.

func WithUseRawPath

func WithUseRawPath(b bool) config.Option

WithUseRawPath sets useRawPath.

If enabled, the url.RawPath will be used to find parameters.

func WithValidateConfig added in v0.7.0

func WithValidateConfig(vc *binding.ValidateConfig) config.Option

WithValidateConfig sets validate config.

func WithWriteTimeout added in v0.4.1

func WithWriteTimeout(t time.Duration) config.Option

WithWriteTimeout sets write timeout.

Connection will be closed when write request timeout.

Types

type Hertz

type Hertz struct {
	*route.Engine
	// contains filtered or unexported fields
}

Hertz is the core struct of hertz.

func Default

func Default(opts ...config.Option) *Hertz

Default creates a hertz instance with default middlewares.

func New

func New(opts ...config.Option) *Hertz

New creates a hertz instance without any default config.

func (*Hertz) SetCustomSignalWaiter added in v0.2.0

func (h *Hertz) SetCustomSignalWaiter(f func(err chan error) error)

SetCustomSignalWaiter sets the signal waiter function. If Default one is not met the requirement, set this function to customize. Hertz will exit immediately if f returns an error, otherwise it will exit gracefully.

func (*Hertz) Spin

func (h *Hertz) Spin()

Spin runs the server until catching os.Signal or error returned by h.Run().

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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