Skip to content

Instantly share code, notes, and snippets.

@psav
Created May 27, 2021 17:33
Show Gist options
  • Save psav/7f78e4eafba9923de918c24848dee73d to your computer and use it in GitHub Desktop.
Save psav/7f78e4eafba9923de918c24848dee73d to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"reflect"
"strconv"
"strings"
clowder "github.com/redhatinsights/app-common-go/pkg/api/v1"
)
func main() {
if os.Getenv("ACG_CONFIG") == "" {
println("ACG_CONFIFG is not set. Exiting.")
return
}
v := reflect.ValueOf(clowder.LoadedConfig)
req_print("CLOWDER", v)
}
func req_print(prefix string, ob reflect.Value) {
ob = reflect.Indirect(ob)
if !ob.IsValid() {
return
}
if ob.Type().String() == "bool" {
fmt.Printf(strings.ToUpper(prefix) + ": " + strconv.FormatBool(reflect.Value(ob).Bool()) + "\n")
return
}
if ob.Type().String() == "string" {
fmt.Printf(strings.ToUpper(prefix) + ": " + reflect.Value(ob).String() + "\n")
return
}
if ob.Type().String() == "int" {
fmt.Printf(strings.ToUpper(prefix) + ": " + strconv.FormatInt(reflect.Value(ob).Int(), 10) + "\n")
return
}
if ob.Kind() == reflect.Slice {
for i := 0; i < ob.Len(); i++ {
req_print(prefix+"_"+strconv.Itoa(i), ob.Index(i))
}
return
}
for i := 0; i < ob.NumField(); i++ {
newObj := reflect.ValueOf(ob.Field(i).Interface())
req_print(prefix+"_"+ob.Type().Field(i).Name, newObj)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment