utils

package
v2.1.7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Example (GenObjectID)

Checking that our IDs are pretty random...

rand.Seed(time.Now().UnixNano())

ids := map[string]bool{}

var g IDGen

for c := 0; c < 1000000; c++ {
	id := g.GenObjectID()
	_, exists := ids[id]
	if exists {
		fmt.Printf("match: %v\n", c)
		break
	}
	ids[id] = true
}

fmt.Println("done")
Output:

done
Example (MakeSaveableFileName)
fmt.Println(MakeSaveableFileName("my roi"))
fmt.Println(MakeSaveableFileName("Dust/Alteration"))
fmt.Println(MakeSaveableFileName("I bet $100 this is cheese"))
fmt.Println(MakeSaveableFileName("10% Ca/Fe & Coffee matrix?"))
Output:

my roi
Dust Alteration
I bet  100 this is cheese
10% Ca Fe   Coffee matrix

Index

Examples

Constants

View Source
const PrettyPrintIndentForJSON = "    "

PrettyPrintIndentForJSON Pretty-print indenting of JSON

View Source
const SharedItemIDPrefix = "shared-"

Any item that we share will have its ID prefixed with shared-. Not necessarily as stored in S3 because it may sit in a known shared directory, but when the API sends out a shared object, it must be prefixed this way

Variables

This section is empty.

Functions

func AbsI64

func AbsI64(x int64) int64

func AddFilesToZip

func AddFilesToZip(w *zip.Writer, basePath, baseInZip string)

func FilesEqual

func FilesEqual(aPath, bPath string) error

func GetStringMapKeys

func GetStringMapKeys(theMap map[string]bool) []string

REFACTOR: TODO: Make this more generic... and/or make an int version FAIL... this seems to not be compatible with ANYTHING??? func GetStringMapKeys(theMap map[string]interface{}) []string {

func ImagesEqual

func ImagesEqual(aPath, bPath string) error

func MakeSaveableFileName

func MakeSaveableFileName(name string) string

MakeSaveableFileName - Given a name which may not be acceptable as a file name, generate a string for a file name that won't have issues. This replaces bad characters like slashes with spaces, etc

func RandStringBytesMaskImpr

func RandStringBytesMaskImpr(n int) string

func ReadFileLines added in v2.0.8

func ReadFileLines(filePath string) ([]string, error)

ReadFileLines - Reads all lines in a file into a string array

func ReadImageFile

func ReadImageFile(path string) (image.Image, error)

func ReplaceStringsInSlice

func ReplaceStringsInSlice(vals []string, replacements map[string]string)

func SetStringsInMap

func SetStringsInMap(vals []string, theMap map[string]bool)

See comments about making this generic... search for REFACTOR, TODO or utils.SetStringsInMap()

func StringInSlice

func StringInSlice(a string, list []string) bool

func StringSlicesEqual

func StringSlicesEqual(test []string, ans []string) bool

func StripSharedItemIDPrefix

func StripSharedItemIDPrefix(ID string) (string, bool)

StripSharedItemIDPrefix - Strips shared prefix and returns true if object was shared

func UnzipDirectory

func UnzipDirectory(src string, dest string, flattenPaths bool) ([]string, error)

func WritePNGImageFile

func WritePNGImageFile(pathPrefix string, img image.Image) error

func ZipDirectory

func ZipDirectory(dirPath string) ([]byte, error)

ZipDirectory - zips a whole directory and its contents (NOT recursive!) See: https://golang.org/pkg/archive/zip/#example_Writer

Types

type IDGen

type IDGen struct {
}

IDGen - Implementation of ID generator interface

func (*IDGen) GenObjectID

func (i *IDGen) GenObjectID() string

GenObjectID - Implementation of ID generator interface

Jump to

Keyboard shortcuts

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