portainer/api/http/settings_handler.go

41 lines
899 B
Go
Raw Normal View History

2016-12-18 05:21:29 +00:00
package http
import (
"github.com/portainer/portainer"
"log"
"net/http"
"os"
"github.com/gorilla/mux"
2016-12-18 05:21:29 +00:00
)
// SettingsHandler represents an HTTP API handler for managing settings.
type SettingsHandler struct {
*mux.Router
Logger *log.Logger
settings *portainer.Settings
2016-12-18 05:21:29 +00:00
}
// NewSettingsHandler returns a new instance of SettingsHandler.
func NewSettingsHandler(mw *middleWareService) *SettingsHandler {
2016-12-18 05:21:29 +00:00
h := &SettingsHandler{
Router: mux.NewRouter(),
Logger: log.New(os.Stderr, "", log.LstdFlags),
2016-12-18 05:21:29 +00:00
}
h.Handle("/settings",
mw.public(http.HandlerFunc(h.handleGetSettings)))
2016-12-18 05:21:29 +00:00
return h
}
// handleGetSettings handles GET requests on /settings
func (handler *SettingsHandler) handleGetSettings(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
handleNotAllowed(w, []string{http.MethodGet})
2016-12-18 05:21:29 +00:00
return
}
encodeJSON(w, handler.settings, handler.Logger)
}