Error logging and support no namespace
parent
b1466a3e48
commit
c70508b3fb
|
|
@ -2,7 +2,7 @@ package serve
|
|||
|
||||
import (
|
||||
"local/dynamodb/server/config"
|
||||
"local/s2sa/s2sa/server/router"
|
||||
"local/router"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@ package serve
|
|||
import (
|
||||
"io/ioutil"
|
||||
"local/dynamodb/server/config"
|
||||
"local/s2sa/s2sa/server/router"
|
||||
"local/router"
|
||||
"local/storage"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
"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) {
|
||||
db := config.Values().DB
|
||||
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 {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
} else if err != nil {
|
||||
log.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
|
|
@ -67,6 +75,7 @@ func (s *Server) put(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
if err := db.Set(key, value, ns); err != nil {
|
||||
log.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue