mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 15:29:42 +02:00
* feat(api): add support for an externally fetched title for motd * refactor(api): gofmt motd.go * refactor(api): update go comment
34 lines
801 B
Go
34 lines
801 B
Go
package motd
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/portainer/libhttp/response"
|
|
"github.com/portainer/portainer"
|
|
"github.com/portainer/portainer/crypto"
|
|
"github.com/portainer/portainer/http/client"
|
|
)
|
|
|
|
type motdResponse struct {
|
|
Title string `json:"Title"`
|
|
Message string `json:"Message"`
|
|
Hash []byte `json:"Hash"`
|
|
}
|
|
|
|
func (handler *Handler) motd(w http.ResponseWriter, r *http.Request) {
|
|
|
|
motd, err := client.Get(portainer.MessageOfTheDayURL, 0)
|
|
if err != nil {
|
|
response.JSON(w, &motdResponse{Message: ""})
|
|
return
|
|
}
|
|
|
|
title, err := client.Get(portainer.MessageOfTheDayTitleURL, 0)
|
|
if err != nil {
|
|
response.JSON(w, &motdResponse{Message: ""})
|
|
return
|
|
}
|
|
|
|
hash := crypto.HashFromBytes(motd)
|
|
response.JSON(w, &motdResponse{Title: string(title), Message: string(motd), Hash: hash})
|
|
}
|