Skip to content

Commit

Permalink
Added space in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpye committed Nov 6, 2023
1 parent c914287 commit afd56ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,30 @@ func createGlobalFakerFunctionMap() template.FuncMap {

//Build the function map from the globalFaker
v := reflect.ValueOf(globalFaker)
//loop through the methods
// loop through the methods
for i := 0; i < v.NumMethod(); i++ {
method := v.Method(i)
//get the method name lowercase
// get the method name lowercase
method_name := v.Type().Method(i).Name
//get the arguments for the method
// get the arguments for the method
methodArgs := make([]reflect.Value, method.Type().NumIn())
//Check to see if the method has any arguments that are not supported by templates
// Check to see if the method has any arguments that are not supported by templates
has_invalid_arg := false
for m := range methodArgs {
if method.Type().In(m).Kind() == reflect.Array || method.Type().In(m).Kind() == reflect.Slice || method.Type().In(m).Kind() == reflect.Interface {
has_invalid_arg = true
break
}
}
//if the method has no invalid arguments add it to the funcMap
// if the method has no invalid arguments add it to the funcMap
if !has_invalid_arg {
funcMap[method_name] = method.Interface()
}
}

//add the custom functions
// add the custom functions

//function to generate a range of integers
// function to generate a range of integers
funcMap["IntRange"] = func(start, end int) []int { // function to generate a range of integers
n := end - start + 1
result := make([]int, n)
Expand All @@ -131,24 +131,24 @@ func createGlobalFakerFunctionMap() template.FuncMap {
return result
}

//function to generate a base64 encode string useful for images
// function to generate a base64 encode string useful for images
funcMap["Base64Enc"] = base64EncString

//function to replace all values in string
// function to replace all values in string
funcMap["replace"] = strings.ReplaceAll

//function to make string lower case
// function to make string lower case
funcMap["lc"] = strings.ToLower

//function to make string upper case
// function to make string upper case
funcMap["uc"] = strings.ToUpper

//function wrapper for SVG this is because template engine cant handle passing structs
// function wrapper for SVG this is because template engine cant handle passing structs
funcMap["SVG"] = func(width int, height int) string {
return globalFaker.Svg(&SVGOptions{Width: width, Height: height, Type: "svg", Colors: []string{"#000000", "#FFFFFF"}})
}

//function wrapper for SQL this is because template engine cant handle passing structs
// function wrapper for SQL this is because template engine cant handle passing structs
funcMap["Sql"] = func() (string, error) {
return globalFaker.SQL(&SQLOptions{
Table: "people",
Expand Down
2 changes: 1 addition & 1 deletion template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ func TestTemplateHtmlContent(t *testing.T) {
func TestTemplateAll(t *testing.T) {
f := New(11)
globalFaker.Rand.Seed(11)
//combine all templates
// combine all templates

build_str := ""
for k := range data.Template {
Expand Down

0 comments on commit afd56ef

Please sign in to comment.