utils

package
v0.0.0-...-9ea7be0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: Apache-2.0 Imports: 13 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 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) ([]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