util

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcPadding

func CalcPadding(length, blkSize int) int

CalcPadding returns the number of padding bytes needed to round length bytes to a multiple of blkSize.

func Checksum

func Checksum(srcs ...[]byte) uint16

Calculate RFC1071 checksum of supplied data chunks. If a chunk has an odd length, it is padded with a 0 during checksum computation.

func CreateParentDirs added in v0.4.0

func CreateParentDirs(file string) error

CreateParentDir creates the necessary parent directories for file.

func FillPadding

func FillPadding(b []byte, length, blkSize int) int

func FmtDuration

func FmtDuration(dur time.Duration) string

func LowerKeys added in v0.4.0

func LowerKeys(m map[string]string)

LowerKeys lowers all keys in the map and deletes the previous keys.

func PaddedLen added in v0.4.0

func PaddedLen(length, blkSize int) int

func ParseDuration

func ParseDuration(durationStr string) (time.Duration, error)

ParseDuration parses a string into a time.Duration, assuming that a year always has 365d, a week always has 7d, and a day always has 24h.

It is similar to time.ParseDuration, but differs in the following ways: - It adds support for the following units: "y", "w", "d" - It requires a unit suffix - It does not support mixed unit durations (e.g. `1h10m10s` is not supported). - It does not support negative durations.

func RunsInDocker added in v0.4.0

func RunsInDocker() (bool, error)

RunsInDocker returns whether the current binary is run in a docker container.

func SecsToCompact added in v0.4.0

func SecsToCompact(t uint32) string

SecsToCompact creates a compact string representation from the seconds.

func SecsToTime

func SecsToTime(t uint32) time.Time

SecsToTime takes seconds stored in a uint32.

func TimeToCompact added in v0.4.0

func TimeToCompact(t time.Time) string

TimeToCompact formats the time as a compat string, e.g. it discards the milliseconds parts if the time only has second resolution.

func TimeToSecs added in v0.2.0

func TimeToSecs(t time.Time) uint32

TimeToSecs returns seconds stored as uint32.

func TimeToString

func TimeToString(t time.Time) string

TimeToString formats the time as a string.

func WriteFile added in v0.4.0

func WriteFile(filename string, data []byte, perm os.FileMode) error

WriteFile writes data to the file. It first writes to a temporary file in the same directory and the renames that file to filename.

Types

type ASList

type ASList struct {
	Core    []addr.IA `yaml:"Core"`
	NonCore []addr.IA `yaml:"Non-core"`
}

ASList is a list of ISD-AS identifiers grouped by core and non-core.

func LoadASList

func LoadASList(fileName string) (*ASList, error)

LoadASList parses the yaml file fileName and returns a structure with non-core and core ASes.

func (*ASList) AllASes added in v0.1.1

func (al *ASList) AllASes() []addr.IA

AllASes returns all ASes in the ASList as a slice.

type B64Bytes

type B64Bytes []byte

func (B64Bytes) MarshalYAML

func (b B64Bytes) MarshalYAML() (interface{}, error)

func (B64Bytes) String

func (b B64Bytes) String() string

func (*B64Bytes) UnmarshalYAML

func (b *B64Bytes) UnmarshalYAML(unmarshal func(interface{}) error) error

type ChannelLock

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

ChannelLock implements a sync.Mutex-like API that uses a 1-value channel behind the scenes. This makes it usable in selects that also need to meet context deadlines.

func NewChannelLock

func NewChannelLock() *ChannelLock

func (*ChannelLock) Lock

func (l *ChannelLock) Lock() <-chan struct{}

Lock returns a channel that can be drained to acquire the lock.

func (*ChannelLock) Unlock

func (l *ChannelLock) Unlock()

type DurWrap added in v0.4.0

type DurWrap struct {
	time.Duration
}

DurWrap is a wrapper to enable marshalling and unmarshalling of durations with the custom format.

func (DurWrap) MarshalText added in v0.4.0

func (d DurWrap) MarshalText() (text []byte, err error)

func (*DurWrap) Set added in v0.4.0

func (d *DurWrap) Set(text string) error

func (DurWrap) String added in v0.4.0

func (d DurWrap) String() string

func (*DurWrap) UnmarshalText added in v0.4.0

func (d *DurWrap) UnmarshalText(text []byte) error

type FileMode added in v0.4.0

type FileMode os.FileMode

func (*FileMode) UnmarshalText added in v0.4.0

func (f *FileMode) UnmarshalText(text []byte) error

type Raw

type Raw struct {
	B      []byte
	Offset int
}

func (*Raw) Peek

func (r *Raw) Peek(p []byte) (int, error)

func (*Raw) Read

func (r *Raw) Read(p []byte) (int, error)

func (*Raw) Write

func (r *Raw) Write(p []byte) (int, error)

type Trigger

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

Trigger represents a timer with delayed arming. Once Arm is called, the channel return by Done() will be closed after d time. If d is 0, the channel is never closed.

func NewTrigger

func NewTrigger(d time.Duration) *Trigger

func (*Trigger) Arm

func (t *Trigger) Arm() *time.Timer

Arm starts the trigger's preset timer, and returns the corresponding timer object. If the trigger is not configured with a timer, nil is returned.

Calling Arm multiple times on the same object is a no-op. Every successive call will return nil.

func (*Trigger) Done

func (t *Trigger) Done() <-chan struct{}

func (*Trigger) Triggered

func (t *Trigger) Triggered() bool

type UnixTime added in v0.4.0

type UnixTime struct {
	time.Time
}

UnixTime allows parsing and packing timestamps in seconds since epoch.

func (UnixTime) MarshalJSON added in v0.4.0

func (t UnixTime) MarshalJSON() ([]byte, error)

MarshalJSON marshals the time as seconds since unix epoch. This must be a value receiver.

func (*UnixTime) String added in v0.4.0

func (t *UnixTime) String() string

func (*UnixTime) UnmarshalJSON added in v0.4.0

func (t *UnixTime) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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