Documentation ¶
Overview ¶
Package util stores useful helper code.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildFullURL ¶
BuildFullURL builds a complete URL string in the format host/path?query, where query's keys and values will be formatted as k=v. Returns an util.MalformedURLError if the given URL can't be parsed. This function is a (very simplified version of url.URL.String().
func CleanSlashes ¶
CleanSlashes removes extraneous slashes (like nexus.com///something), which Nexus' API doesn't recognize as valid. Returns an util.MalformedURLError if the given URL can't be parsed.
func MapDiff ¶
func MapDiff(expected map[string]string, actual map[string]string) (diff []string, onlyExpected []string, onlyActual []string)
MapDiff calculates the difference between two maps. It returns three values:
* diff: a slice of strings, holding the keys in both with different values;
* onlyExpected: a slice of keys only in expected;
* onlyActual: a slice of keys only in actual.
When the maps are equal, all three slices will be empty.
Example ¶
package main import ( "fmt" "sbrubbles.org/go/nexus/util" ) func main() { expected := map[string]string{"a": "a", "b": "b"} actual := map[string]string{"a": "aaaa", "c": "c"} diff, onlyExpected, onlyActual := util.MapDiff(expected, actual) fmt.Println(diff) // ["a"] fmt.Println(onlyExpected) // ["b"] fmt.Println(onlyActual) // ["c"] diff, onlyExpected, onlyActual = util.MapDiff(expected, expected) fmt.Println(diff) // [] fmt.Println(onlyExpected) // [] fmt.Println(onlyActual) // [] }
Output:
Types ¶
type ByteSize ¶
type ByteSize float64
ByteSize represents an amount of bytes. float64 is needed since division is required. Implements the fmt.Stringer interface.
Some pre-constructed file size units.
type MalformedURLError ¶
type MalformedURLError struct {
URL string // e.g. http:/:malformed.url.com
}
MalformedURLError is returned when the given URL could not be parsed.
func (MalformedURLError) Error ¶
func (err MalformedURLError) Error() string
Error implements the error interface.