Files
grafana/vendor/github.com/brianvoe/gofakeit/generate.go
T
Oleg Gaidarenko 35f227de11 Feature: LDAP refactoring (#16950)
* incapsulates multipleldap logic under one module

* abstracts users upsert and get logic

* changes some of the text error messages and import sort sequence

* heavily refactors the LDAP module – LDAP module now only deals with LDAP related behaviour

* integrates affected auth_proxy module and their tests

* refactoring of the auth_proxy logic
2019-05-17 14:57:26 +03:00

42 lines
1.1 KiB
Go

package gofakeit
import (
"strings"
)
// Generate fake information from given string. String should contain {category.subcategory}
//
// Ex: {person.first} - random firstname
//
// Ex: {person.first}###{person.last}@{person.last}.{internet.domain_suffix} - billy834smith@smith.com
//
// Ex: ### - 481 - random numbers
//
// Ex: ??? - fda - random letters
//
// For a complete list possible categories use the Categories() function.
func Generate(dataVal string) string {
// Identify items between brackets: {person.first}
for strings.Count(dataVal, "{") > 0 && strings.Count(dataVal, "}") > 0 {
catValue := ""
startIndex := strings.Index(dataVal, "{")
endIndex := strings.Index(dataVal, "}")
replace := dataVal[(startIndex + 1):endIndex]
categories := strings.Split(replace, ".")
if len(categories) >= 2 && dataCheck([]string{categories[0], categories[1]}) {
catValue = getRandValue([]string{categories[0], categories[1]})
}
dataVal = strings.Replace(dataVal, "{"+replace+"}", catValue, 1)
}
// Replace # with numbers
dataVal = replaceWithNumbers(dataVal)
// Replace ? with letters
dataVal = replaceWithLetters(dataVal)
return dataVal
}