common

package
v0.0.0-...-6a5da2a Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Marshal = func(v interface{}) (io.Reader, error) {
	b, err := json.MarshalIndent(v, "", "\t")
	if err != nil {
		return nil, err
	}
	return bytes.NewReader(b), nil
}

Marshal is a function that marshals the object into an io.Reader. By default, it uses the JSON marshaller.

View Source
var Unmarshal = func(r io.Reader, v interface{}) error {
	return json.NewDecoder(r).Decode(v)
}

Unmarshal is a function that unmarshals the data from the reader into the specified value. By default, it uses the JSON unmarshaller.

Functions

func Contains

func Contains(a []string, x string) bool

Contains works out if a string slice contains a given string element

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func Load

func Load(path string, v interface{}) error

Load loads the file at path into v. Use os.IsNotExist() to see if the returned error is due to the file being missing.

func Save

func Save(path string, v interface{}) error

Save saves a representation of v to the file at path.

Types

type FallBackWrapper

type FallBackWrapper struct {
	Assets http.FileSystem
}

FallBackWrapper serves a file if found and else default to index.html

func (*FallBackWrapper) Open

func (i *FallBackWrapper) Open(name string) (http.File, error)

Open serves a file if found and else default to index.html

Jump to

Keyboard shortcuts

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