Fix NoValue field, Fix MaxLen when header name is > value

This commit is contained in:
yo 2021-12-18 15:37:05 +01:00
parent 26166489fd
commit 3fdca54cc4

View File

@ -47,13 +47,13 @@ func displayStructFields(jails []Jail, valsToDisplay []string) {
line := make([]Field, len(valsToDisplay)) line := make([]Field, len(valsToDisplay))
for i, f := range valsToDisplay { for i, f := range valsToDisplay {
a := reflect.ValueOf(&tj).Elem() a := reflect.ValueOf(&tj).Elem()
//fmt.Printf("Struct : %s, Champ : %s\n", a.String(), f)
//fmt.Printf("%v", a.Elem().FieldByName(f).Interface())
field := Field { field := Field {
Name: f, Name: f,
}
if a.Elem().FieldByName(f).IsValid() {
// For now this just contains this item length, will adjust later // For now this just contains this item length, will adjust later
MaxLen: len(fmt.Sprintf("%v", a.Elem().FieldByName(f).Interface())), field.MaxLen = len(fmt.Sprintf("%v", a.Elem().FieldByName(f).Interface()))
Value: fmt.Sprintf("%v", a.Elem().FieldByName(f).Interface()), field.Value = fmt.Sprintf("%v", a.Elem().FieldByName(f).Interface())
} }
line[i] = field line[i] = field
@ -64,7 +64,7 @@ func displayStructFields(jails []Jail, valsToDisplay []string) {
// Get real maximum length // Get real maximum length
maxlen := make([]int, len(valsToDisplay)) maxlen := make([]int, len(valsToDisplay))
for i := 0; i< len(valsToDisplay); i++ { for i := 0; i< len(valsToDisplay); i++ {
maxlen[i] = 0 maxlen[i] = len(valsToDisplay[i])
} }
for _, l := range out { for _, l := range out {
for i, f := range l { for i, f := range l {
@ -83,7 +83,7 @@ func displayStructFields(jails []Jail, valsToDisplay []string) {
} }
totalLen := 0 totalLen := 0
// Add separator and 2 blank spaces // For each field, add separator and 2 blank spaces
for _, f := range out[0] { for _, f := range out[0] {
totalLen += f.MaxLen + 3 totalLen += f.MaxLen + 3
} }
@ -145,16 +145,7 @@ func listJails(args []string) {
listJailsFromDatastore(d) listJailsFromDatastore(d)
} }
displayStructFields(gJails, []string{"JID", "Name", "RootPath"}) displayStructFields(gJails, []string{"JID", "Name", "Release", "RootPath"})
/* for _, j := range (gJails) {
if j.Running {
fmt.Printf("%d ; %s ; %s ; %s\n", j.JID, j.Name, j.Config.Ip4_addr, j.Config.Release)
} else {
fmt.Printf(" ; %s ; %s ; %s\n", j.Name, j.Config.Ip4_addr, j.Config.Release)
}
}
*/
} }
@ -196,9 +187,6 @@ func listJailsFromDirectory(dir string) ([]Jail) {
} }
// 3. Add current running informations // 3. Add current running informations
// FIXME : use rj.host.hostname
//j.Internal_name = fmt.Sprintf("ioc-%s", j.Name)
rjails, err := jail.GetJails() rjails, err := jail.GetJails()
if err != nil { log.Fatalln("Unable to list running jails") } if err != nil { log.Fatalln("Unable to list running jails") }
for _, rj := range rjails { for _, rj := range rjails {
@ -225,7 +213,5 @@ func getJailConfig(jailConfigPath string) (JailConfig, error) {
err = json.Unmarshal([]byte(content), &jc) err = json.Unmarshal([]byte(content), &jc)
if err != nil { log.Fatalln(fmt.Sprintf("Error occured during unmarshaling %s: %s", jailConfigPath, err.Error())) } if err != nil { log.Fatalln(fmt.Sprintf("Error occured during unmarshaling %s: %s", jailConfigPath, err.Error())) }
//fmt.Printf("Jail Config: %#v\n", jc)
return jc, err return jc, err
} }