Esempio n. 1
0
func (ss *StaticServer) Keys(rw http.ResponseWriter, req *http.Request) {
	result, err := ss.mkv.FindAll()
	if err != nil {
		util.WriteError(rw, "STAT-241", err)
		return
	}

	filter := req.URL.Query().Get("filter")
	if filter != "" {
		pat, err := regexp.Compile(filter)
		if err != nil {
			util.WriteError(rw, "STAT-242", err)
			return
		}
		filtered := make([]KeyStoreEntry, 0)
		for _, i := range result {
			if pat.MatchString(i.K) {
				filtered = append(filtered, i)
			}
		}
		result = filtered
	}

	util.WriteJSON(rw, result)
}
Esempio n. 2
0
func (ss *StaticServer) RemoveKey(rw http.ResponseWriter, req *http.Request) {
	key := bone.GetValue(req, "key")

	err := ss.mkv.Remove(key)

	if err != nil {
		util.WriteError(rw, "STAT-231", err)
	}
}
Esempio n. 3
0
func (ss *StaticServer) GenID(rw http.ResponseWriter, req *http.Request) {
	name := bone.GetValue(req, "idname")

	id, err := ss.mkv.GetNextID(name)

	if err != nil {
		util.WriteError(rw, "STAT-261", err)
	}
	util.WriteJSON(rw, id)
}
Esempio n. 4
0
func (ss *StaticServer) PutKey(rw http.ResponseWriter, req *http.Request) {
	key := bone.GetValue(req, "key")
	value := bone.GetValue(req, "value")
	ss.setS3RootIfPresent(key, value)

	if err := ss.mkv.Upsert(key, value); err != nil {
		util.WriteError(rw, "STAT-201", err)
		return
	}
	util.WriteJSON(rw, value)
}
Esempio n. 5
0
func (ss *StaticServer) GetIDForHash(rw http.ResponseWriter, req *http.Request) {
	name := bone.GetValue(req, "idname")
	hash := bone.GetValue(req, "hash")

	id, err := ss.mkv.GetIDFor(name, hash)

	if err != nil {
		util.WriteError(rw, "STAT-251", err)
		return
	}
	util.WriteJSON(rw, id)
}
Esempio n. 6
0
func (ss *StaticServer) PostKey(rw http.ResponseWriter, req *http.Request) {
	key := bone.GetValue(req, "key")

	body, err := ioutil.ReadAll(req.Body)
	if err != nil {
		util.WriteWebError(rw, util.NewWebError(http.StatusBadRequest, "STAT-211", err.Error()))
	}
	b := string(body)
	value := getJSON(b)
	ss.setS3RootIfPresent(key, value)

	if err := ss.mkv.Upsert(key, value); err != nil {
		util.WriteError(rw, "STAT-212", err)
		return
	}
	util.WriteJSON(rw, value)
}