Пример #1
0
func Run() {
	serverInternal := http.NewServeMux()
	serverInternal.HandleFunc("/", handler)
	serverInternal.HandleFunc("/key/", handleGetKey)
	serverInternal.HandleFunc("/json", handleGetJson)
	serverInternal.HandleFunc("/JSON", handleGetJson)
	log.Fatal("webInternal.Run(): ", http.ListenAndServe(data.Get("config.portInternal"), serverInternal))
}
Пример #2
0
func handleGetJson(w http.ResponseWriter, r *http.Request) {
	dat, err := json.Marshal(data.GetData())
	if data.Get("config.readableJson") == "yes" {
		dat, err = json.MarshalIndent(data.GetData(), "", "  ")
	}
	if err != nil {
		log.Print(err)
	}
	fmt.Fprintf(w, "%s", dat)
}
Пример #3
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))
		}
	}
}
Пример #4
0
func handleGetKey(w http.ResponseWriter, r *http.Request) {
	var i = strings.LastIndex(r.URL.Path, "/key/") + len("/key/")
	if i > 0 {
		fmt.Fprintf(w, "%s\n", data.Get(r.URL.Path[i:]))
	}
}
Пример #5
0
func Get(k string) string {
	return data.Get(k)
}