goutils

package module
v0.0.0-...-caeabf1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2019 License: MIT Imports: 19 Imported by: 0

README

goutils

Build Status GitHub last commit Coverage Status Codacy Badge GoDoc GitHub stars

Documentation

Index

Constants

View Source
const (
	// MaxIterations Prevents infinite loops
	MaxIterations = 100
)

Variables

View Source
var (
	// DelayShutdown ...
	DelayShutdown sync.WaitGroup
	// DelayReason ...
	DelayReason string
)
View Source
var BoltDB *bolt.DB

BoltDB global access to BoltDB resource

Functions

func Assert

func Assert(tb testing.TB, condition bool, msg string, v ...interface{})

Assert fails the test if the condition is false.

func CatchShutdown

func CatchShutdown()

CatchShutdown is a helper function called via goroutine when you start your app the only parameter required is the function you want to call to cleanup your app example: go goutils.CatchShutdown(app.Shutdown())

func ConnectBolt

func ConnectBolt(file string) (err error)

ConnectBolt given a filename (usually from the config) will open boltDB

func EnsureNoQueryParameters

func EnsureNoQueryParameters(r *http.Request) (bool, error)

EnsureNoQueryParameters is a help function for endpoints that require no query parameters

func Equals

func Equals(tb testing.TB, exp, act interface{})

Equals fails the test if exp is not equal to act.

func GetBuildInfo

func GetBuildInfo() (str string, err error)

GetBuildInfo will return git build information as a string. No GOVVV required.

func GetQueryParameter

func GetQueryParameter(r *http.Request, name string, required bool, defaultOk bool, def string) (string, error)

GetQueryParameter is a helper function to get query parameters by name and return error ONLY if they are required and not present and DO NOT have a defined default value.

Example: ``` qpApple,ok := GetQueryParameter(r,"apple",false,true,"Granny Smith")

if err != nil {
		HandleError(w, http.StatusInternalServerError.RequestURI, err)
		return
}

```

func HTML5FormLogin

func HTML5FormLogin() string

HTML5FormLogin returns string content representing a basic login form centered on the page

func HTML5Page

func HTML5Page(title, content string) string

HTML5Page returns string content representing a valid HTML5 page with the given title set and the content provided placed in a DIV an ID of content

func HTML5PageLogin

func HTML5PageLogin() string

HTML5PageLogin returns a complete basic Login page

func HTML5PageNotImplemented

func HTML5PageNotImplemented(name string) string

HTML5PageNotImplemented returns a complete basic

func InitializeBolt

func InitializeBolt(file string) (err error)

InitializeBolt creates a new BoltDB resource

func Ok

func Ok(tb testing.TB, err error)

Ok fails the test if an err is not nil.

func ReadConfigFile

func ReadConfigFile(data interface{}, filename string) (err error)

ReadConfigFile Read a single config file, return a struct, where 'data' is a pointer to that struct

func StringArrayContains

func StringArrayContains(arr []string, str string) bool

StringArrayContains helper function to return true or false is a given string exists in the provided string array

func StringToAlphaNumeric

func StringToAlphaNumeric(s string) (str string, err error)

StringToAlphaNumeric given a string will strip all characters except AlphaNumeric and return the result

func ValidateDir

func ValidateDir(filename string) (fullpath string, dirInfo os.FileInfo, err error)

ValidateDir Validate if exists, and is type directory

func ValidateEmailAddress

func ValidateEmailAddress(email string) (err error)

ValidateEmailAddress tests given email for valid email format

func ValidateFile

func ValidateFile(filename string) (fullpath string, fileInfo os.FileInfo, err error)

ValidateFile Validate if exists, and is type file

func ValidateFileOrParentDir

func ValidateFileOrParentDir(filename string) (fullpath string, err error)

ValidateFileOrParentDir Validate if exists, and is type file Or parent directory valid, because file is to be created

Types

type ElementMap

type ElementMap map[string]interface{}

ElementMap is the JSON element parsed into a key-value map

type ErrList

type ErrList []string

ErrList Struct to accumulate a list of errors

func (*ErrList) Add

func (errList *ErrList) Add(v ...interface{})

Add Append error to list

func (*ErrList) Addf

func (errList *ErrList) Addf(text string, v ...interface{})

Addf Append formatted error to list

func (ErrList) Get

func (errList ErrList) Get() (err error)

Get to Compile list of error strings into an error message

type FileDetail

type FileDetail struct {
	Name           string
	DistinctName   string
	FullPath       string
	PathComponents []string
}

FileDetail ...

func DistinctFilenames

func DistinctFilenames(filenames []string, errList *ErrList) (fileDetails []FileDetail)

DistinctFilenames Create Parsed{} struct for each filename, validating and formatting names

type Parsed

type Parsed struct {
	FileName     string
	DistinctName string
	Position     int
	ElementMap   ElementMap
}

Parsed contains each JSON element, remembering where it was found - DistinctName is shortest unique name across all filenames - Position is element # within the file: 0 if single element, 1...N if array of N elements

type ParsedMap

type ParsedMap map[string][]Parsed

ParsedMap When mutiple files are parsed, a field in each element is specified as the Id - This element Id is used as the ParsedMap key (so becomes a required field)

type ResultMap

type ResultMap map[string]interface{}

ResultMap The Parsed map form is then collapsed into a single data object result per Id

func ReadConfigFiles

func ReadConfigFiles(data interface{}, idName string, filenames ...string) (resultMap ResultMap, err error)

ReadConfigFiles Read a list of config files into a map of structs, where 'data' points to struct and idName is field for map key - Can configure an application using one or more JSON files - For example, put general settings in one file, credentials in a second file.

Jump to

Keyboard shortcuts

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