-
Notifications
You must be signed in to change notification settings - Fork 70
/
news.go
34 lines (29 loc) · 743 Bytes
/
news.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package client
import (
"fmt"
"net/url"
"strings"
charm "github.com/charmbracelet/charm/proto"
)
// NewsList lists the server news.
func (cc *Client) NewsList(tags []string, page int) ([]*charm.News, error) {
var nl []*charm.News
if tags == nil {
tags = []string{"server"}
}
tq := url.QueryEscape(strings.Join(tags, ","))
err := cc.AuthedJSONRequest("GET", fmt.Sprintf("/v1/news?page=%d&tags=%s", page, tq), nil, &nl)
if err != nil {
return nil, err
}
return nl, nil
}
// News shows a given news.
func (cc *Client) News(id string) (*charm.News, error) {
var n *charm.News
err := cc.AuthedJSONRequest("GET", fmt.Sprintf("/v1/news/%s", url.QueryEscape(id)), nil, &n)
if err != nil {
return nil, err
}
return n, nil
}