util

package
v0.11.10 Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: Apache-2.0 Imports: 17 Imported by: 166

Documentation

Overview

Package util contains various utility functions that are useful across all of goiardi.

Index

Constants

This section is empty.

Variables

View Source
var NoDBConfigured = gerror.StatusError("no db configured, but you tried to use one", http.StatusInternalServerError)

NoDBConfigured is an error for when no database has been configured for use, yet an SQL function is being called.

Functions

func CheckForObject added in v0.11.0

func CheckForObject(orgname string, checksum string) (bool, error)

func CustomObjURL

func CustomObjURL(obj GoiardiObj, path string) string

CustomObjURL crafts a URL for a Goiardi object with additional path elements.

func CustomURL

func CustomURL(path string) string

CustomURL crafts a URL from the provided path, without providing an object.

func DeepMerge

func DeepMerge(key string, source interface{}) map[string]interface{}

DeepMerge merges disparate data structures into a flat hash.

func DelSliceElement added in v0.11.3

func DelSliceElement(pos int, strs []string) []string

DelSliceElement removes an element from a slice of strings.

func FlattenObj

func FlattenObj(obj interface{}) map[string]interface{}

FlattenObj flattens an object and expand its keys into a map[string]string so it's suitable for indexing, either with solr (eventually) or with the whipped up replacement for local mode. Objects fed into this function *must* have the "json" tag set for their struct members.

func IndexEscapeStr added in v0.10.0

func IndexEscapeStr(s string) string

IndexEscapeStr escapes values to index in the database, so characters that need to be escaped for Solr are properly found when using the trie or postgres based searches.

func Indexify

func Indexify(flattened map[string]interface{}) []string

Indexify prepares a flattened object for indexing by turning it into a sorted slice of strings formatted like "key:value".

func InitS3 added in v0.11.0

func InitS3(conf *config.Conf) error

InitS3 sets up the session and whatnot for using goiardi with S3.

func MapifyObject

func MapifyObject(obj interface{}) map[string]interface{}

MapifyObject turns an object into a map[string]interface{}. Useful for when you have a slice of objects that you need to trim, mutilate, fold, etc. before returning them as JSON.

func ObjURL

func ObjURL(obj GoiardiObj) string

ObjURL crafts a URL for an object.

func PgSearchKey added in v0.10.0

func PgSearchKey(key string) string

PgSearchKey removes characters from search term fields that make the ltree data type unhappy. This leads to the postgres-based search being, perhaps, somewhat less precise than the solr (or ersatz solr) based search, but at the same time one that's less resource demanding and covers almost all known use cases. Potential bug: Postgres considers some, but not all, unicode letters as being alphanumeric; i.e. golang and postgres both consider 'ü' to be a letter, but golang accepts 'ሀ' as a letter while postgres does not. This is reasonably unlikely to be an issue, but if you're using lots of non-European characters in your attributes this could be a problem. We're accepting more than raw ASCII alnum however because it's better behavior and because Postgres does accept at least some other alphabets as being alphanumeric.

func PgSearchQueryKey added in v0.10.0

func PgSearchQueryKey(key string) string

PgSearchQueryKey is very similar to PgSearchKey, except that it preserves the Solr wildcard charactes '*' and '?' in the queries.

func RemoveDupStrings added in v0.11.3

func RemoveDupStrings(strs []string) []string

RemoveDupStrings removes duplicates from a slice of strings. The slice of strings must be sorted before it's used with this function.

func S3CheckFile added in v0.11.0

func S3CheckFile(orgname, checksum string) bool

func S3DeleteHashes added in v0.11.0

func S3DeleteHashes(fileHashes []string)

func S3GetURL added in v0.11.0

func S3GetURL(orgname string, checksum string) (string, error)

func S3PutURL added in v0.11.0

func S3PutURL(orgname string, checksum string) (string, error)

func TrimStringMax added in v0.11.3

func TrimStringMax(s string, strLength int) string

TrimStringMax trims a string down if its length is over a certain amount

func ValidateDBagName

func ValidateDBagName(name string) bool

func ValidateEnvName

func ValidateEnvName(name string) bool

func ValidateName

func ValidateName(name string) bool

func ValidateUserName added in v0.4.0

func ValidateUserName(name string) bool

Types

type Gerror

type Gerror interface {
	gerror.Error
}

Gerror is an error type that wraps around the goiardi Error type.

func CastErr added in v0.5.0

func CastErr(err error) Gerror

CastErr will easily cast a different kind of error to a Gerror. A convenience wrapper around error.CastErr.

func CheckAdminPlusValidator added in v0.4.0

func CheckAdminPlusValidator(jsonActor map[string]interface{}) Gerror

CheckAdminPlusValidator checks that client/user json is not trying to set admin and validator at the same time. This has to be checked separately to make chef-pedent happy.

func Errorf

func Errorf(format string, a ...interface{}) Gerror

Errorf creates a new Gerror, with a formatted error string. A convenience wrapper around error.Errorf.

func ValidateAsBool

func ValidateAsBool(b interface{}) (bool, Gerror)

func ValidateAsConstraint

func ValidateAsConstraint(t interface{}) (bool, Gerror)

func ValidateAsFieldString

func ValidateAsFieldString(str interface{}) (string, Gerror)

func ValidateAsString

func ValidateAsString(str interface{}) (string, Gerror)

func ValidateAsVersion

func ValidateAsVersion(ver interface{}) (string, Gerror)

func ValidateAttributes

func ValidateAttributes(key string, attrs interface{}) (map[string]interface{}, Gerror)

func ValidateCookbookDivision

func ValidateCookbookDivision(dname string, div interface{}) ([]map[string]interface{}, Gerror)

func ValidateCookbookMetadata

func ValidateCookbookMetadata(mdata interface{}) (map[string]interface{}, Gerror)

func ValidateNumVersions

func ValidateNumVersions(nr string) Gerror

func ValidateRunList

func ValidateRunList(rl interface{}) ([]string, Gerror)

type GoiardiObj

type GoiardiObj interface {
	GetName() string
	URLType() string
}

GoiardiObj is an interface for helping goiardi/chef objects, like cookbooks, roles, etc., be able to easily make URLs and be identified by name.

type StringSlice added in v0.8.0

type StringSlice []string

StringSlice makes it possible to scan Posgres arrays directly into a golang slice. Borrowed from https://gist.github.com/adharris/4163702.

func (*StringSlice) Scan added in v0.8.0

func (s *StringSlice) Scan(src interface{}) error

Scan implements sql.Scanner for the StringSlice type.

Jump to

Keyboard shortcuts

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