Przeglądaj źródła

added envelop for all request, so that CRUD objects can use the top level Json

master
sp 4 lat temu
rodzic
commit
e4660d60a9
2 zmienionych plików z 6 dodań i 7 usunięć
  1. +5
    -6
      apiv1.go
  2. +1
    -1
      main.go

+ 5
- 6
apiv1.go Wyświetl plik

@@ -26,13 +26,13 @@ type apiV1Envelop struct {
}

type apiV1Response struct {
apiV1Envelop
Env apiV1Envelop
Body interface{}
}

var apiV1Handler = []apiV1HandlerMap{
{"POST", "login", apiV1Login},
{"GET", "login", dummyHandler},
{"GET", "login", apiV1DumpRequest},
}

//apiV1Main version 1 main entry for all REST API
@@ -56,8 +56,7 @@ func apiV1Login(w http.ResponseWriter, r *http.Request) {
p := loan.User{}
p.FakeNew()

res := apiV1Response{}
res.apiV1Envelop = apiV1EnvelopBlank()
res := apiV1ResponseBlank()
res.Body = p
apiSendJson(res, w)

@@ -79,7 +78,7 @@ func apiV1DumpRequest(w http.ResponseWriter, r *http.Request) {
msg := fmt.Sprintf("Unhandled Protocol = %s path= %s", r.Method, r.URL.Path)
dumpLines := strings.Split(dump, "\r\n")
ar := apiV1ResponseBlank()
ar.Msg = msg
ar.Env.Msg = msg
ar.Body = dumpLines
b, _ := json.Marshal(ar)
fmt.Fprintf(w, "%s\n", b)
@@ -97,6 +96,6 @@ func apiV1EnvelopBlank() (ret apiV1Envelop) {
}

func apiV1ResponseBlank() (ret apiV1Response) {
ret.apiV1Envelop = apiV1EnvelopBlank()
ret.Env = apiV1EnvelopBlank()
return
}

+ 1
- 1
main.go Wyświetl plik

@@ -32,7 +32,7 @@ func main() {
func setupRootFileServer() {
//root of doc
for idx, node := range config.Static {
log.Printf("setting up %d static with %+v\n", idx, node)
log.Printf("setting up static %d with %+v\n", idx, node)
fs := http.FileServer(http.Dir(node.Dir))
http.Handle(node.StaticUrl, http.StripPrefix(node.StripPrefix, fs))
}

Ładowanie…
Anuluj
Zapisz