utils

package
v0.0.0-...-87c9453 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreSliceEqual

func AreSliceEqual(first []interface{}, second []interface{}) bool

Checks to see if slices are equal to each other, returning false or true

func AreStringSliceEqual

func AreStringSliceEqual(first []string, second []string) bool

Checks to see if the string slices are equal to each other, returning false or true

func ConvertToStringSlice

func ConvertToStringSlice(slice []interface{}, ignoreNil bool) []string

Converts a given interface{} slice into a []string

func ExtractFieldFromMapList

func ExtractFieldFromMapList(data []map[string]interface{}, field string) []interface{}

Extracts a given field from n list of maps, returning a list f the values for that field, where the field does not exist, a nil is added

func PrettyPrintJSON

func PrettyPrintJSON(data []byte) error

Pretty prints JSON data

Example

The PrettyPrintJSON function prints out JSON in a pretty format

type dataType struct {
	Foo   string `json:"foo"`
	Jesus string `json:"Jesus"`
	Woo   string `json:"Woo"`
}

data := dataType{
	Foo:   "bar",
	Jesus: "the LORD",
	Woo:   "hoo",
}

dataAsJson, err := json.Marshal(data)
if err != nil {
	log.Fatal("error marshalling the data: ", err)
}

PrettyPrintJSON(dataAsJson)
Output:

{
	"foo": "bar",
	"Jesus": "the LORD",
	"Woo": "hoo"
}

func SortStringSlice

func SortStringSlice(slice []string, order SortOrder) []string

Sorts a given string slice in a given order

Types

type SortOrder

type SortOrder int
const (
	ASC SortOrder = iota
	DESC
)

Jump to

Keyboard shortcuts

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