mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 14:59:41 +02:00
* feat(api): introduce new datastore interface * refactor(api): refactor http and main layers * refactor(api): refactor http and bolt layers
30 lines
879 B
Go
30 lines
879 B
Go
package templates
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
|
|
httperror "github.com/portainer/libhttp/error"
|
|
)
|
|
|
|
// GET request on /api/templates
|
|
func (handler *Handler) templateList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
|
settings, err := handler.DataStore.Settings().Settings()
|
|
if err != nil {
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve settings from the database", err}
|
|
}
|
|
|
|
resp, err := http.Get(settings.TemplatesURL)
|
|
if err != nil {
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve templates via the network", err}
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_, err = io.Copy(w, resp.Body)
|
|
if err != nil {
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to write templates from templates URL", err}
|
|
}
|
|
|
|
return nil
|
|
}
|