Error logging and support no namespace
parent
b1466a3e48
commit
c70508b3fb
|
|
@ -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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue