one more update
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-09 16:56:00 +11:00
parent 43e0ecd1ce
commit d8b68f2815
3 changed files with 36 additions and 34 deletions

View File

@@ -6,11 +6,14 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"log"
"math/big"
"net"
"os"
"path/filepath"
"reflect"
"strings"
"time"
)
@@ -183,3 +186,33 @@ func GenerateCerts(tlsCert string, tlsKey string) {
}
log.Printf("wrote %s\n", tlsKey)
}
func PrintStructContents(s interface{}, indentLevel int) string {
var result strings.Builder
val := reflect.ValueOf(s)
if val.Kind() == reflect.Ptr {
val = val.Elem()
}
typ := val.Type()
for i := 0; i < val.NumField(); i++ {
field := val.Field(i)
fieldType := typ.Field(i)
indent := strings.Repeat("\t", indentLevel)
result.WriteString(fmt.Sprintf("%s%s: ", indent, fieldType.Name))
switch field.Kind() {
case reflect.Struct:
result.WriteString("\n")
result.WriteString(PrintStructContents(field.Interface(), indentLevel+1))
default:
result.WriteString(fmt.Sprintf("%v\n", field.Interface()))
}
}
return result.String()
}