Files
coder/codersdk/servicebanner.go
2022-12-06 18:38:38 +00:00

39 lines
913 B
Go

package codersdk
import (
"context"
"encoding/json"
"net/http"
)
type ServiceBanner struct {
Enabled bool `json:"enabled"`
Message string `json:"message,omitempty"`
BackgroundColor string `json:"background_color,omitempty"`
}
func (c *Client) ServiceBanner(ctx context.Context) (*ServiceBanner, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/service-banner", nil)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, readBodyAsError(res)
}
var b ServiceBanner
return &b, json.NewDecoder(res.Body).Decode(&b)
}
func (c *Client) SetServiceBanner(ctx context.Context, s *ServiceBanner) error {
res, err := c.Request(ctx, http.MethodPut, "/api/v2/service-banner", s)
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return readBodyAsError(res)
}
return nil
}