Error logging and support no namespace

master
Bel LaPointe 2019-06-19 12:02:01 -06:00
parent b1466a3e48
commit c70508b3fb
2 changed files with 12 additions and 3 deletions

View File

@ -2,7 +2,7 @@ package serve
import ( import (
"local/dynamodb/server/config" "local/dynamodb/server/config"
"local/s2sa/s2sa/server/router" "local/router"
"strings" "strings"
) )

View File

@ -3,8 +3,9 @@ package serve
import ( import (
"io/ioutil" "io/ioutil"
"local/dynamodb/server/config" "local/dynamodb/server/config"
"local/s2sa/s2sa/server/router" "local/router"
"local/storage" "local/storage"
"log"
"net/http" "net/http"
"path" "path"
"strings" "strings"
@ -41,11 +42,18 @@ func (s *Server) NSCatchAll(w http.ResponseWriter, r *http.Request) {
func (s *Server) get(w http.ResponseWriter, r *http.Request) { func (s *Server) get(w http.ResponseWriter, r *http.Request) {
db := config.Values().DB db := config.Values().DB
ns := strings.Split(r.URL.Path, "/")[1] ns := strings.Split(r.URL.Path, "/")[1]
key := strings.Split(r.URL.Path, "/")[2] var key string
if len(strings.Split(r.URL.Path, "/")) < 3 {
key = ns
ns = ""
} else {
key = strings.Split(r.URL.Path, "/")[2]
}
if value, err := db.Get(key, ns); err == storage.ErrNotFound { if value, err := db.Get(key, ns); err == storage.ErrNotFound {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return return
} else if err != nil { } else if err != nil {
log.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} else { } else {
@ -67,6 +75,7 @@ func (s *Server) put(w http.ResponseWriter, r *http.Request) {
return return
} }
if err := db.Set(key, value, ns); err != nil { if err := db.Set(key, value, ns); err != nil {
log.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }