Documentation ¶
Overview ¶
Package util contains various utility functions that are useful across all of goiardi.
Index ¶
- Variables
- func CustomObjURL(obj GoiardiObj, path string) string
- func CustomURL(path string) string
- func DeepMerge(key string, source interface{}) map[string]interface{}
- func FlattenObj(obj interface{}) map[string]interface{}
- func IndexEscapeStr(s string) string
- func Indexify(flattened map[string]interface{}) []string
- func MapifyObject(obj interface{}) map[string]interface{}
- func ObjURL(obj GoiardiObj) string
- func PgSearchKey(key string) string
- func ValidateDBagName(name string) bool
- func ValidateEnvName(name string) bool
- func ValidateName(name string) bool
- func ValidateUserName(name string) bool
- type Gerror
- func CastErr(err error) Gerror
- func CheckAdminPlusValidator(jsonActor map[string]interface{}) Gerror
- func Errorf(format string, a ...interface{}) Gerror
- func New(text string) Gerror
- func ValidateAsBool(b interface{}) (bool, Gerror)
- func ValidateAsConstraint(t interface{}) (bool, Gerror)
- func ValidateAsFieldString(str interface{}) (string, Gerror)
- func ValidateAsString(str interface{}) (string, Gerror)
- func ValidateAsVersion(ver interface{}) (string, Gerror)
- func ValidateAttributes(key string, attrs interface{}) (map[string]interface{}, Gerror)
- func ValidateCookbookDivision(dname string, div interface{}) ([]map[string]interface{}, Gerror)
- func ValidateCookbookMetadata(mdata interface{}) (map[string]interface{}, Gerror)
- func ValidateNumVersions(nr string) Gerror
- func ValidateRunList(rl interface{}) ([]string, Gerror)
- type GoiardiObj
- type StringSlice
Constants ¶
This section is empty.
Variables ¶
var NoDBConfigured = &gerror{msg: "no db configured, but you tried to use one", status: http.StatusInternalServerError}
NoDBConfigured is an error for when no database has been configured for use, yet an SQL function is being called.
Functions ¶
func CustomObjURL ¶
func CustomObjURL(obj GoiardiObj, path string) string
CustomObjURL crafts a URL for a Goiardi object with additional path elements.
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
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 ¶
Indexify prepares a flattened object for indexing by turning it into a sorted slice of strings formatted like "key:value".
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 PgSearchKey ¶ added in v0.10.0
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 ValidateDBagName ¶
func ValidateEnvName ¶
func ValidateName ¶
func ValidateUserName ¶ added in v0.4.0
Types ¶
type Gerror ¶
Gerror is an error type that includes an http status code (defaults to http.BadRequest).
func CheckAdminPlusValidator ¶ added in v0.4.0
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 ValidateAsBool ¶
func ValidateAsConstraint ¶
func ValidateAsFieldString ¶
func ValidateAsString ¶
func ValidateAsVersion ¶
func ValidateAttributes ¶
func ValidateNumVersions ¶
func ValidateRunList ¶
type GoiardiObj ¶
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.