Ejemplo n.º 1
0
func ParseArgs(inOpts [][]string) error {

	PushArgs(inOpts)
	mu.Lock()
	defer mu.Unlock()
	for _, v := range indexed {
		elem := v
		elem.Value = flag.String(elem.Name, elem.Default, elem.Description)
	}
	// nothing is actally done until parse is called
	if Get("config.enableFlagParse") == "yes" {
		flag.Parse()
	}
	for _, elem := range indexed {
		data.Set(elem.Name, *elem.Value)
	}

	// Start the internal admin web interface
	if Get("config.portInternal") != "" {
		if Get("config.silentWebPrompt") == "no" {
			fmt.Println("configuration on", Get("config.portInternal"))
		}
		go webInternal.Run()
	}
	return nil
}
Ejemplo n.º 2
0
func handleGet(w http.ResponseWriter, r *http.Request) {
	if err := r.ParseForm(); err != nil {
		log.Print(err)
	}
	if len(r.Form) > 0 {
		for k, v := range r.Form {
			data.Set(k, strings.Join(v, " "))
		}
	} else {
		configKeys := data.Keys()
		for _, k := range configKeys {
			fmt.Fprintf(w, "Config[%q] = %q\n", k, data.Get(k))
		}
	}
}
Ejemplo n.º 3
0
func PushArgs(inOpts [][]string) error {
	mu.Lock()
	defer mu.Unlock()
	for i, _ := range inOpts {
		var o Option
		if v, ok := indexed[inOpts[i][NameIdx]]; ok == true {
			o = *v
		}
		o.Name, o.Default = inOpts[i][NameIdx], inOpts[i][DefaultIdx]
		if len(inOpts[i]) > 2 {
			o.Description = inOpts[i][DescriptionIdx]
		}
		data.Set(o.Name, o.Default)
		indexed[o.Name] = &o
	}
	return nil
}
Ejemplo n.º 4
0
func Set(k, v string) {
	data.Set(k, v)
}