Beispiel #1
0
func (csvr ClientAPISVR) replaceAll(resp http.ResponseWriter, req *http.Request) {
	reqlist, err := csvr.parseReqList(req)
	if err != nil {
		log.Println(err)
		resp.WriteHeader(http.StatusBadRequest)
		return
	}
	var rlist []passsql.PassRecord
	var r passsql.PassRecord
	for _, x := range reqlist {
		r.Meta = x["meta"].(string)
		r.Meta_id = x["meta_id"].(string)
		r.Uname = x["uname"].(string)
		r.Pass = x["pass"].(string)
		r.Pass_rev = int(x["pass_rev"].(float64))
		r.Kgroup = x["kgroup"].(string)
		r.Remark = x["remark"].(string)
		rlist = append(rlist, r)
	}
	err = csvr.PDB.ReplaceAll(csvr.Tablename, rlist)
	if err != nil {
		resp.WriteHeader(http.StatusInternalServerError)
		log.Println(err)
		return
	}
	resp.WriteHeader(http.StatusOK)
	return
}
Beispiel #2
0
func (csvr ClientAPISVR) addRecord(resp http.ResponseWriter, req *http.Request) {
	x, err := csvr.parseReq(req)
	if err != nil {
		resp.WriteHeader(http.StatusBadRequest)
		return
	}
	var r passsql.PassRecord
	r.Meta = x["meta"].(string)
	r.Meta_id = x["meta_id"].(string)
	r.Uname = x["uname"].(string)
	r.Pass = x["pass"].(string)
	r.Remark = x["remark"].(string)
	r.Kgroup = x["kgroup"].(string)
	err = csvr.PDB.Insert(csvr.Tablename, r)
	if err != nil {
		resp.WriteHeader(http.StatusInternalServerError)
		return
	}
	resp.WriteHeader(http.StatusCreated)
	return

}