Ejemplo n.º 1
0
func getConfig(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	json := gabs.New()
	json.Set(readonly == "true", "readonly")

	w.Write([]byte(json.String()))
}
Ejemplo n.º 2
0
func saveDoc(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	json := gabs.New()
	if readonly == "false" {
		r.ParseForm()
		path := r.Form["path"][0]
		markdown := r.Form["doc"][0]
		err := ioutil.WriteFile(path, []byte(markdown), 0644)
		if err != nil {
			json.Set(false, "success")
			json.Set(err.Error(), "error")
		} else {
			json.Set(true, "success")
		}
	} else {
		json.Set(false, "success")
		json.Set("moc is in readonly mode", "error")
	}

	w.Write([]byte(json.String()))
}
Ejemplo n.º 3
0
func persistenCounter() {
	if len(counter) > 0 {
		json := gabs.New()
		counterlock.Lock()
		for k, v := range counter {
			json.Set(v, k)
		}
		counterlock.Unlock()
		err := ioutil.WriteFile(countFile, json.Bytes(), 0x644)
		if err != nil {
			log.Error("persisten counter failed: ", err)
		}
	}
}