Exemplo 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)
}
Exemplo n.º 2
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)
}
Exemplo n.º 3
0
func (ss *StaticServer) FindKey(rw http.ResponseWriter, req *http.Request) {
	key := bone.GetValue(req, "key")

	s, err := ss.mkv.FindOne(key)

	if err != nil {
		util.WriteNewWebError(rw, http.StatusNotFound, "STAT-221", "Couldn't find key "+key+": "+err.Error())
		return
	}
	util.WriteJSON(rw, s)
}
Exemplo 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)
}
Exemplo 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)
}
Exemplo 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)
}
Exemplo n.º 7
0
func (ss *StaticServer) Status(rw http.ResponseWriter, req *http.Request) {
	stat := ss.vc.GetStatus()
	util.WriteJSON(rw, stat)
}