devserver

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: MIT Imports: 29 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPortFree added in v0.13.0

func CheckPortFree(host string, port int) error

Asserts that the given TCP port is available to listen on, for the given (local) host; return an error if it is not.

func GetFreePort added in v0.13.0

func GetFreePort(host string) (int, error)

Returns a TCP port that is available to listen on, for the given (local) host.

This works by binding a new TCP socket on port 0, which requests the OS to allocate a free port. There is no strict guarantee that the port will remain available after this function returns, but it should be safe to assume that a given port will not be allocated again to any process on this machine within a few seconds.

On Unix-based systems, binding to the port returned by this function requires setting the `SO_REUSEADDR` socket option (Go already does that by default, but other languages may not); otherwise, the OS may fail with a message such as "address already in use". Windows default behavior is already appropriate in this regard; on that platform, `SO_REUSEADDR` has a different meaning and should not be set (setting it may have unpredictable consequences).

func MaybeEscapeIPv6 added in v0.13.2

func MaybeEscapeIPv6(host string) string

Escapes an IPv6 address with square brackets, if it is an IPv6 address.

func MustGetFreePort

func MustGetFreePort(host string) int

Returns a TCP port that is available to listen on, for the given (local) host; panics if no port is available.

This works by binding a new TCP socket on port 0, which requests the OS to allocate a free port. There is no strict guarantee that the port will remain available after this function returns, but it should be safe to assume that a given port will not be allocated again to any process on this machine within a few seconds.

On Unix-based systems, binding to the port returned by this function requires setting the `SO_REUSEADDR` socket option (Go already does that by default, but other languages may not); otherwise, the OS may fail with a message such as "address already in use". Windows default behavior is already appropriate in this regard; on that platform, `SO_REUSEADDR` has a different meaning and should not be set (setting it may have unpredictable consequences).

Types

type Server

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

func Start

func Start(options StartOptions) (*Server, error)

func (*Server) Stop

func (s *Server) Stop()

type StartOptions

type StartOptions struct {
	// Required fields
	FrontendIP             string
	FrontendPort           int
	Namespaces             []string
	ClusterID              string
	MasterClusterName      string
	CurrentClusterName     string
	InitialFailoverVersion int
	Logger                 *slog.Logger
	LogLevel               slog.Level

	// Optional fields
	UIIP                  string // Empty means no UI
	UIPort                int    // Required if UIIP is non-empty
	UIAssetPath           string
	UICodecEndpoint       string
	PublicPath            string
	DatabaseFile          string
	MetricsPort           int
	PProfPort             int
	SqlitePragmas         map[string]string
	FrontendHTTPPort      int
	EnableGlobalNamespace bool
	DynamicConfigValues   map[string]any
	LogConfig             func([]byte)
	GRPCInterceptors      []grpc.UnaryServerInterceptor
}

Jump to

Keyboard shortcuts

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