diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-01-10 12:18:00 -0800 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2017-01-10 12:18:00 -0800 |
commit | 97613eafb4979ff3356097e0d18ba9e92c790d64 (patch) | |
tree | 2640e236de0dca50f92e5556c2fe27dd607cc691 | |
parent | a9d3645302c8129c3300959f024fa28972208e50 (diff) |
adding returns to exit req/res, testing values -> struct conv via schema
-rw-r--r-- | system/addon/manager.go | 15 | ||||
-rw-r--r-- | system/admin/handlers.go | 25 |
2 files changed, 30 insertions, 10 deletions
diff --git a/system/addon/manager.go b/system/addon/manager.go index 1be09c0..753ddd7 100644 --- a/system/addon/manager.go +++ b/system/addon/manager.go @@ -6,8 +6,7 @@ import ( "html/template" "net/url" - "encoding/json" - + "github.com/gorilla/schema" "github.com/ponzu-cms/ponzu/management/editor" ) @@ -18,6 +17,7 @@ const managerHTML = ` <form method="post" action="/admin/addon" enctype="multipart/form-data"> {{ .DefaultInputs }} {{ .Editor }} + <button type="submit" class="btn green waves-effect waves-light">Save</button> </form> </div> ` @@ -36,13 +36,10 @@ func Manage(data url.Values, reverseDNS string) ([]byte, error) { at := a() - // convert data => json => at{} - j, err := json.Marshal(data) - if err != nil { - return nil, err - } - - err = json.Unmarshal(j, &at) + dec := schema.NewDecoder() + dec.IgnoreUnknownKeys(true) + dec.SetAliasTag("json") + err := dec.Decode(&at, data) if err != nil { return nil, err } diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 1edbb4d..2dcbddf 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -1946,6 +1946,7 @@ func addonsHandler(res http.ResponseWriter, req *http.Request) { } res.Write(errView) + return } } @@ -1968,6 +1969,7 @@ func addonsHandler(res http.ResponseWriter, req *http.Request) { } res.Write(errView) + return } _, err = html.Write(list.Bytes()) @@ -1981,6 +1983,7 @@ func addonsHandler(res http.ResponseWriter, req *http.Request) { } res.Write(errView) + return } _, err = html.WriteString(`</ul></div></div>`) @@ -1994,6 +1997,23 @@ func addonsHandler(res http.ResponseWriter, req *http.Request) { } res.Write(errView) + return + } + + if html.Len() == 0 { + _, err := html.WriteString(`<p>No addons available.</p>`) + if err != nil { + log.Println("Error writing default addon html to admin view:", err) + res.WriteHeader(http.StatusInternalServerError) + errView, err := Error500() + if err != nil { + log.Println(err) + return + } + + res.Write(errView) + return + } } view, err := Admin(html.Bytes()) @@ -2007,6 +2027,7 @@ func addonsHandler(res http.ResponseWriter, req *http.Request) { } res.Write(errView) + return } res.Write(view) @@ -2099,6 +2120,7 @@ func addonsHandler(res http.ResponseWriter, req *http.Request) { } res.Write(errView) + return } } @@ -2120,7 +2142,7 @@ func addonHandler(res http.ResponseWriter, req *http.Request) { return } - _, ok := addon.Types[id] + at, ok := addon.Types[id] if !ok { log.Println("Addon: ", id, "is not found in addon.Types map") res.WriteHeader(http.StatusNotFound) @@ -2166,6 +2188,7 @@ func addonHandler(res http.ResponseWriter, req *http.Request) { } res.Write(errView) + return } } |