ソースを参照

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

master
sp 4年前
コミット
e4660d60a9
2個のファイルの変更6行の追加7行の削除
  1. +5
    -6
      apiv1.go
  2. +1
    -1
      main.go

+ 5
- 6
apiv1.go ファイルの表示

} }


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


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


//apiV1Main version 1 main entry for all REST API //apiV1Main version 1 main entry for all REST API
p := loan.User{} p := loan.User{}
p.FakeNew() p.FakeNew()


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


msg := fmt.Sprintf("Unhandled Protocol = %s path= %s", r.Method, r.URL.Path) msg := fmt.Sprintf("Unhandled Protocol = %s path= %s", r.Method, r.URL.Path)
dumpLines := strings.Split(dump, "\r\n") dumpLines := strings.Split(dump, "\r\n")
ar := apiV1ResponseBlank() ar := apiV1ResponseBlank()
ar.Msg = msg
ar.Env.Msg = msg
ar.Body = dumpLines ar.Body = dumpLines
b, _ := json.Marshal(ar) b, _ := json.Marshal(ar)
fmt.Fprintf(w, "%s\n", b) fmt.Fprintf(w, "%s\n", b)
} }


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

+ 1
- 1
main.go ファイルの表示

func setupRootFileServer() { func setupRootFileServer() {
//root of doc //root of doc
for idx, node := range config.Static { 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)) fs := http.FileServer(http.Dir(node.Dir))
http.Handle(node.StaticUrl, http.StripPrefix(node.StripPrefix, fs)) http.Handle(node.StaticUrl, http.StripPrefix(node.StripPrefix, fs))
} }

読み込み中…
キャンセル
保存