示例#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)
}