this never works
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
bbf96ee7fa
commit
1f07cc2d79
54
args.go
54
args.go
|
@ -7,8 +7,6 @@ package main
|
|||
import (
|
||||
"log"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
arg "github.com/alexflint/go-arg"
|
||||
"git.wit.org/wit/gui"
|
||||
// log "git.wit.org/wit/gui/log"
|
||||
|
@ -40,57 +38,9 @@ func init() {
|
|||
}
|
||||
log.Println(true, "INIT() args.GuiArg.Gui =", gui.GuiArg.Gui)
|
||||
|
||||
Set(&me, "default")
|
||||
me.artificialSleep = 2.3
|
||||
me.artificialS = "blah"
|
||||
log.Println("init() me.artificialSleep =", me.artificialSleep)
|
||||
log.Println("init() me.artificialS =", me.artificialS)
|
||||
me.artificialSleep = 2.3
|
||||
log.Println("init() me.artificialSleep =", me.artificialSleep)
|
||||
sleep(me.artificialSleep)
|
||||
}
|
||||
|
||||
func Set(ptr interface{}, tag string) error {
|
||||
if reflect.TypeOf(ptr).Kind() != reflect.Ptr {
|
||||
log.Println(logError, "Set() Not a pointer", ptr, "with tag =", tag)
|
||||
return fmt.Errorf("Not a pointer")
|
||||
}
|
||||
|
||||
v := reflect.ValueOf(ptr).Elem()
|
||||
t := v.Type()
|
||||
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
defaultVal := t.Field(i).Tag.Get(tag)
|
||||
name := t.Field(i).Name
|
||||
// log("Set() try name =", name, "defaultVal =", defaultVal)
|
||||
setField(v.Field(i), defaultVal, name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setField(field reflect.Value, defaultVal string, name string) error {
|
||||
|
||||
if !field.CanSet() {
|
||||
// log("setField() Can't set value", field, defaultVal)
|
||||
return fmt.Errorf("Can't set value\n")
|
||||
} else {
|
||||
log.Println("setField() Can set value", name, defaultVal)
|
||||
}
|
||||
|
||||
switch field.Kind() {
|
||||
case reflect.Int:
|
||||
val, _ := strconv.Atoi(defaultVal)
|
||||
field.Set(reflect.ValueOf(int(val)).Convert(field.Type()))
|
||||
case reflect.Float64:
|
||||
val, _ := strconv.ParseFloat(defaultVal, 64)
|
||||
field.Set(reflect.ValueOf(float64(val)).Convert(field.Type()))
|
||||
case reflect.String:
|
||||
field.Set(reflect.ValueOf(defaultVal).Convert(field.Type()))
|
||||
case reflect.Bool:
|
||||
if defaultVal == "true" {
|
||||
field.Set(reflect.ValueOf(true))
|
||||
} else {
|
||||
field.Set(reflect.ValueOf(false))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ type Host struct {
|
|||
domainname string // kernel.org
|
||||
// fqdn string // mirrors.kernel.org
|
||||
|
||||
dnsTTL int `default:3` // Recheck DNS is working every TTL (in seconds)
|
||||
dnsTTL int `default:"3"` // Recheck DNS is working every TTL (in seconds)
|
||||
dnsTTLsleep float64 // sleep between loops
|
||||
artificialSleep float64 `default:0.7` // artificial sleep on startup
|
||||
artificialS string `default:0.7` // artificial sleep on startup
|
||||
artificialSleep float64 `default:"0.7"` // artificial sleep on startup
|
||||
artificialS string `default:"abc"` // artificial sleep on startup
|
||||
|
||||
changed bool // set to true if things changed
|
||||
user string // name of the user
|
||||
|
|
Loading…
Reference in New Issue