-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
59 lines (50 loc) · 877 Bytes
/
client.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cli
import (
"bytes"
"encoding/json"
"fmt"
"github.com/mradile/rssfeeder/pkg/client/configuration"
"github.com/urfave/cli"
"io"
"net/http"
"os"
"time"
)
type client struct {
http *http.Client
cfg *configuration.Configuration
debug bool
}
var Client = &client{
http: &http.Client{
Timeout: time.Duration(time.Second * 60),
},
}
func toJSONReader(data interface{}) (io.Reader, error) {
byts, err := json.Marshal(data)
if err != nil {
return nil, err
}
return bytes.NewReader(byts), nil
}
func setLogLevel(c *cli.Context) {
if c.GlobalBool("debug") {
Client.debug = true
}
}
func LogDebug(msg string) {
if !Client.debug {
return
}
fmt.Println(msg)
}
func LogInfo(msg string) {
fmt.Println(msg)
}
func LogError(msg string) {
fmt.Fprintln(os.Stderr, msg)
}
func LogFatal(msg string) {
fmt.Fprintln(os.Stderr, msg)
os.Exit(1)
}