~stephen-stewart/snapweb/client-side-filtering-and-ordering

« back to all changes in this revision

Viewing changes to oem/handlers.go

  • Committer: Snappy Tarmac
  • Author(s): Sergio Schvezov
  • Date: 2015-05-03 22:01:52 UTC
  • mfrom: (109.1.5 webdm)
  • Revision ID: snappy_tarmac-20150503220152-3t1ydw42t9yikms9
Enabling golint and fixing the issues it found to be able to enable it by sergiusens approved by chipaca

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
package oem
19
19
 
20
20
import (
21
 
        "encoding/json"
22
 
        "fmt"
23
 
        "net/http"
24
21
        "os"
25
22
        "path/filepath"
26
 
 
27
 
        "github.com/gorilla/mux"
28
23
)
29
24
 
30
 
type handler struct{}
31
 
 
32
 
func NewHandler() *handler {
33
 
        return &handler{}
34
 
}
35
 
 
36
 
func (h *handler) get(w http.ResponseWriter, r *http.Request) {
37
 
        data, err := Oem()
38
 
        if err != nil {
39
 
                if err == ErrNotFound {
40
 
                        w.WriteHeader(http.StatusNotFound)
41
 
                        fmt.Fprint(w, "No OEM package installed")
42
 
                } else if err == ErrTooMany {
43
 
                        w.WriteHeader(http.StatusInternalServerError)
44
 
                        fmt.Fprint(w, fmt.Sprintf("Error: %s", err))
45
 
                } else if err == ErrDecode {
46
 
                        w.WriteHeader(http.StatusInternalServerError)
47
 
                        fmt.Fprint(w, fmt.Sprintf("Error: %s", err))
48
 
                }
49
 
        }
50
 
 
51
 
        enc := json.NewEncoder(w)
52
 
        if err := enc.Encode(data); err != nil {
53
 
                w.WriteHeader(http.StatusInternalServerError)
54
 
                fmt.Fprint(w, fmt.Sprintf("Error: %s", err))
55
 
                return
56
 
        }
57
 
}
58
 
 
59
 
func (h *handler) MakeMuxer(prefix string) http.Handler {
60
 
        var m *mux.Router
61
 
 
62
 
        if prefix == "" {
63
 
                m = mux.NewRouter()
64
 
        } else {
65
 
                m = mux.NewRouter().PathPrefix(prefix).Subrouter()
66
 
        }
67
 
 
68
 
        // Get oem branding.
69
 
        m.HandleFunc("/", h.get).Methods("GET")
70
 
 
71
 
        return m
72
 
}
73
 
 
74
25
func glob(dir string, filename string) (pkgs []string, err error) {
75
26
        err = filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
76
27
                if filepath.Base(path) == filename {