util

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseBool

func ParseBool(b string) *bool

ParseBool parses a string into a boolean pointer.

func ParseHexUint64s added in v0.10.0

func ParseHexUint64s(ss []string) ([]*uint64, error)

Parses a uint64 from given hex in string.

func ParsePInt64s added in v0.0.4

func ParsePInt64s(ss []string) ([]*int64, error)

ParsePInt64s parses a slice of strings into a slice of int64 pointers.

func ParseUint32s

func ParseUint32s(ss []string) ([]uint32, error)

ParseUint32s parses a slice of strings into a slice of uint32s.

func ParseUint64s

func ParseUint64s(ss []string) ([]uint64, error)

ParseUint64s parses a slice of strings into a slice of uint64s.

func ReadFileNoStat added in v0.0.6

func ReadFileNoStat(filename string) ([]byte, error)

ReadFileNoStat uses io.ReadAll to read contents of entire file. This is similar to os.ReadFile but without the call to os.Stat, because many files in /proc and /sys report incorrect file sizes (either 0 or 4096). Reads a max file size of 1024kB. For files larger than this, a scanner should be used.

func ReadIntFromFile added in v0.1.0

func ReadIntFromFile(path string) (int64, error)

ReadIntFromFile reads a file and attempts to parse a int64 from it.

func ReadUintFromFile

func ReadUintFromFile(path string) (uint64, error)

ReadUintFromFile reads a file and attempts to parse a uint64 from it.

func SysReadFile

func SysReadFile(file string) (string, error)

SysReadFile is a simplified os.ReadFile that invokes syscall.Read directly. https://github.com/prometheus/node_exporter/pull/728/files

Note that this function will not read files larger than 128 bytes.

Types

type ValueParser added in v0.0.3

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

A ValueParser enables parsing a single string into a variety of data types in a concise and safe way. The Err method must be invoked after invoking any other methods to ensure a value was successfully parsed.

func NewValueParser added in v0.0.3

func NewValueParser(v string) *ValueParser

NewValueParser creates a ValueParser using the input string.

func (*ValueParser) Err added in v0.0.3

func (vp *ValueParser) Err() error

Err returns the last error, if any, encountered by the ValueParser.

func (*ValueParser) Int added in v0.0.8

func (vp *ValueParser) Int() int

Int interprets the underlying value as an int and returns that value.

func (*ValueParser) PInt64 added in v0.0.3

func (vp *ValueParser) PInt64() *int64

PInt64 interprets the underlying value as an int64 and returns a pointer to that value.

func (*ValueParser) PUInt64 added in v0.0.3

func (vp *ValueParser) PUInt64() *uint64

PUInt64 interprets the underlying value as an uint64 and returns a pointer to that value.

Jump to

Keyboard shortcuts

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