refactoring. remove global state, use new logging, config functions

This commit is contained in:
2018-06-17 16:15:58 +02:00
parent d091398f05
commit 75197310bf
24 changed files with 295 additions and 476 deletions

View File

@@ -4,20 +4,18 @@ import (
"fmt"
"net/http"
"fornaxian.com/pixeldrain-web/log"
"fornaxian.com/pixeldrain-web/pixelapi"
"fornaxian.com/pixeldrain-web/webcontroller/templates"
"github.com/Fornaxian/log"
"github.com/julienschmidt/httprouter"
)
// ServeListViewer controller for GET /l/:id
func ServeListViewer(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
var list = pixelapi.GetList(p.ByName("id"))
func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
var list = wc.api.GetList(p.ByName("id"))
if list.Error != nil {
if list.Error.ReqError {
log.Error("API request error occurred: %s", list.Error.Value)
}
ServeNotFound(w, r)
wc.serveNotFound(w, r)
return
}
@@ -30,7 +28,7 @@ func ServeListViewer(w http.ResponseWriter, r *http.Request, p httprouter.Params
"title": list.Title,
"views": 0,
}
err = templates.Get().ExecuteTemplate(w, "file_viewer", map[string]interface{}{
err = wc.templates.Get().ExecuteTemplate(w, "file_viewer", map[string]interface{}{
"Title": fmt.Sprintf("%s ~ Pixeldrain list", list.Title),
"APIResponse": listdata,
"Type": "list",