Documentation
¶
Index ¶
- Variables
- func Bytes2Str(data []byte) string
- func GraceRun(f func() error) error
- func GraceStart(f func(ch GraceSignalChan) error) error
- func HomeDir() (string, error)
- func IsInContainer(pid int) (bool, error)
- func LineWriter(fn func(line []byte) error, ignoreEmpty bool) io.Writer
- func Reset()
- func Str2Bytes(str string) []byte
- func WithHomeDir(path string) (string, error)
- type Duration
- type Errors
- type GraceSignalChan
- type UUID
- type Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DisableCache bool
DisableCache will disable caching of the home directory. Caching is enabled by default.
Functions ¶
func Bytes2Str ¶
Bytes2Str converts byte slice to a string without memory allocation. See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
Note it may break if string and/or slice header will change in the future go versions.
Example ¶
Output:
func GraceStart ¶ added in v0.2.6
func GraceStart(f func(ch GraceSignalChan) error) error
GraceStart start a grace function
func HomeDir ¶ added in v0.0.7
HomeDir returns the home directory for the executing user.
This uses an OS-specific method for discovering the home directory. An error is returned if a home directory cannot be detected.
func IsInContainer ¶ added in v0.1.2
IsInContainer checks if the service is being executed in docker or lxc container.
func LineWriter ¶ added in v0.3.17
LineWriter return a writer with a line callback
func Reset ¶ added in v0.0.7
func Reset()
Reset clears the cache, forcing the next call to Dir to re-detect the home directory. This generally never has to be called, but can be useful in tests if you're modifying the home directory via the HOME env var or something.
func Str2Bytes ¶
Str2Bytes converts string to a byte slice without memory allocation.
Note it may break if string and/or slice header will change in the future go versions.
Example ¶
Output:
func WithHomeDir ¶ added in v0.0.7
WithHomeDir expands the path to include the home directory if the path is prefixed with `~`. If it isn't prefixed with `~`, the path is returned as-is.
Types ¶
type Duration ¶ added in v0.3.19
Duration implement JSON marshall for time.Duration
func (Duration) MarshalJSON ¶ added in v0.3.19
MarshalJSON implement MarshalJSON
func (*Duration) UnmarshalJSON ¶ added in v0.3.19
UnmarshalJSON implement UnmarshalJSON
type Errors ¶ added in v0.2.1
type Errors []error
Errors contains multi error
type GraceSignalChan ¶ added in v0.2.6
type GraceSignalChan chan struct{}
GraceSignalChan grace signal chan
type UUID ¶ added in v0.0.2
type UUID [16]byte
A UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC 4122.
var (
Nil UUID // empty UUID, all zeros
)
Well known namespace IDs and UUIDs
func NewRandomUUID ¶ added in v0.0.2
NewRandomUUID returns a Random (Version 4) UUID.
The strength of the UUIDs is based on the strength of the crypto/rand package.
A note about uniqueness derived from the UUID Wikipedia entry:
Randomly generated UUIDs have 122 random bits. One's annual risk of being hit by a meteorite is estimated to be one chance in 17 billion, that means the probability is about 0.00000000006 (6 × 10−11), equivalent to the odds of creating a few tens of trillions of UUIDs in a year and having one duplicate.
Example ¶
Output:
func NewRandomUUIDFromReader ¶ added in v0.0.2
NewRandomUUIDFromReader returns a Random (Version 4) UUID.
func NewUUID ¶ added in v0.0.2
func NewUUID() UUID
NewUUID creates a new random UUID or panics. New is equivalent to the expression
uuid.Must(uuid.NewRandom())
Example ¶
Output:
func ParseUUID ¶ added in v0.0.2
ParseUUID decodes s into a UUID or returns an error. Both the standard UUID forms of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded as well as the Microsoft encoding {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} and the raw hex encoding: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
type Value ¶ added in v0.3.13
type Value[T comparable] struct { // contains filtered or unexported fields }
func NewValue ¶ added in v0.3.13
func NewValue[T comparable](v T) *Value[T]
NewValue create the value for expression
func Unwrap ¶ added in v0.5.0
func Unwrap[T comparable](mv T, err error) *Value[T]
Unwrap the value from (value, error) if err != nil, return v
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
config
Package config provider load configuration from file
|
Package config provider load configuration from file |
examples
|
|
Package httputil contains lots of helper functions
|
Package httputil contains lots of helper functions |
Package sh to run command programing
|
Package sh to run command programing |