common

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: MPL-2.0 Imports: 8 Imported by: 564

Documentation

Overview

Package common contains common utilities that are shared among other packages. See each sub-package for detail.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoClue = errors.New("not enough information for making a decision")

ErrNoClue is for the situation that existing information is not enough to make a decision. For example, Router may return this error when there is no suitable route.

Functions

func Close

func Close(obj interface{}) error

Close closes the obj if it is a Closable.

xray:api:beta

func CreateObject

func CreateObject(ctx context.Context, config interface{}) (interface{}, error)

CreateObject creates an object by its config. The config type must be registered through RegisterConfig().

func Error2

func Error2(v interface{}, err error) error

Error2 returns the err from the 2nd parameter.

func GetGOBIN

func GetGOBIN() string

GetGOBIN returns GOBIN environment variable as a string. It will NOT be empty.

func GetGOPATH

func GetGOPATH() string

GetGOPATH returns GOPATH environment variable as a string. It will NOT be empty.

func GetModuleName

func GetModuleName(pathToProjectRoot string) (string, error)

GetModuleName returns the value of module in `go.mod` file.

func GetRuntimeEnv

func GetRuntimeEnv(key string) (string, error)

GetRuntimeEnv returns the value of runtime environment variable, that is set by running following command: `go env -w key=value`.

func Interrupt

func Interrupt(obj interface{}) error

Interrupt calls Interrupt() if object implements Interruptible interface, or Close() if the object implements Closable interface.

xray:api:beta

func Must

func Must(err error)

Must panics if err is not nil.

func Must2

func Must2(v interface{}, err error) interface{}

Must2 panics if the second parameter is not nil, otherwise returns the first parameter.

func RegisterConfig

func RegisterConfig(config interface{}, configCreator ConfigCreator) error

RegisterConfig registers a global config creator. The config can be nil but must have a type.

Types

type ChainedClosable

type ChainedClosable []Closable

ChainedClosable is a Closable that consists of multiple Closable objects.

func (ChainedClosable) Close

func (cc ChainedClosable) Close() error

Close implements Closable.

type Closable

type Closable interface {
	// Close release all resources used by this object, including goroutines.
	Close() error
}

Closable is the interface for objects that can release its resources.

xray:api:beta

type ConfigCreator

type ConfigCreator func(ctx context.Context, config interface{}) (interface{}, error)

ConfigCreator is a function to create an object by a config.

type HasType

type HasType interface {
	// Type returns the type of the object.
	// Usually it returns (*Type)(nil) of the object.
	Type() interface{}
}

HasType is the interface for objects that knows its type.

type Interruptible

type Interruptible interface {
	Interrupt()
}

Interruptible is an interface for objects that can be stopped before its completion.

xray:api:beta

type Runnable

type Runnable interface {
	// Start starts the runnable object. Upon the method returning nil, the object begins to function properly.
	Start() error

	Closable
}

Runnable is the interface for objects that can start to work and stop on demand.

Directories

Path Synopsis
Package buf provides a light-weight memory allocation mechanism.
Package buf provides a light-weight memory allocation mechanism.
Package crypto provides common crypto libraries for Xray.
Package crypto provides common crypto libraries for Xray.
Package dice contains common functions to generate random number.
Package dice contains common functions to generate random number.
Package errors is a drop-in replacement for Golang lib 'errors'.
Package errors is a drop-in replacement for Golang lib 'errors'.
net
Package net is a drop-in replacement to Golang's net package, with some more functionalities.
Package net is a drop-in replacement to Golang's net package, with some more functionalities.
cnc
dns
tls
udp
Package session provides functions for sessions of incoming requests.
Package session provides functions for sessions of incoming requests.

Jump to

Keyboard shortcuts

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