portainer/api/http/handler/settings.go

44 lines
1.1 KiB
Go
Raw Normal View History

package handler
2016-12-18 05:21:29 +00:00
import (
"github.com/portainer/portainer"
httperror "github.com/portainer/portainer/http/error"
"github.com/portainer/portainer/http/security"
2016-12-18 05:21:29 +00:00
"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(bouncer *security.RequestBouncer, settings *portainer.Settings) *SettingsHandler {
2016-12-18 05:21:29 +00:00
h := &SettingsHandler{
Router: mux.NewRouter(),
Logger: log.New(os.Stderr, "", log.LstdFlags),
settings: settings,
2016-12-18 05:21:29 +00:00
}
h.Handle("/settings",
bouncer.PublicAccess(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 {
httperror.WriteMethodNotAllowedResponse(w, []string{http.MethodGet})
2016-12-18 05:21:29 +00:00
return
}
encodeJSON(w, handler.settings, handler.Logger)
}