parseutil

package
v0.0.0-...-52b58a3 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: Apache-2.0, MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAUrl = errors.New("not a url")

Functions

func ParseAbsoluteTime

func ParseAbsoluteTime(in interface{}) (time.Time, error)

func ParseAddrs

func ParseAddrs(addrs interface{}) ([]*sockaddr.SockAddrMarshaler, error)

func ParseBool

func ParseBool(in interface{}) (bool, error)

func ParseCapacityString

func ParseCapacityString(in interface{}) (uint64, error)

ParseCapacityString parses a capacity string and returns the number of bytes it represents. Capacity strings are things like 5gib or 10MB. Supported prefixes are kb, kib, mb, mib, gb, gib, tb, tib, which are not case sensitive. If no prefix is present, the number is assumed to be in bytes already.

func ParseCommaStringSlice

func ParseCommaStringSlice(in interface{}) ([]string, error)

func ParseDurationSecond

func ParseDurationSecond(in interface{}) (time.Duration, error)

func ParseInt

func ParseInt(in interface{}) (int64, error)

func ParsePath

func ParsePath(path string) (string, error)

ParsePath parses a URL with schemes file://, env://, or any other. Depending on the scheme it will return specific types of data:

* file:// will return a string with the file's contents

* env:// will return a string with the env var's contents

* Anything else will return the string as it was

On error, we return the original string along with the error. The caller can switch on errors.Is(err, ErrNotAUrl) to understand whether it was the parsing step that errored or something else (such as a file not found). This is useful to attempt to read a non-URL string from some resource, but where the original input may simply be a valid string of that type.

func ParseString

func ParseString(in interface{}) (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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