-
Notifications
You must be signed in to change notification settings - Fork 2
/
goprowifi.go
73 lines (51 loc) · 1.1 KB
/
goprowifi.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package goprowifi
import (
"fmt"
"io/ioutil"
"net/http"
)
// Client ...
type Client struct {
// Use this switch to see all network communication.
Debug bool
// http interface can be used when testing
myDoer Doer
service
}
type service struct {
client *Client
}
// Doer to make testing easer !
type Doer interface {
Do(*http.Request) (*http.Response, error)
}
// NewClient ...
func NewClient(debug bool) *Client {
g := &Client{}
const API = "http://10.5.5.9/gp/gpControl/"
g.Debug = debug
// set default http interface to use
g.myDoer = http.DefaultClient
return g
}
func (g *Client) request(url string) (bodyBytes []byte, statusCode int, err error) {
fmt.Printf("[Debug] URL : %s\n", url)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return
}
resp, err := g.myDoer.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
bodyBytes, err = ioutil.ReadAll(resp.Body)
if err != nil {
return
}
fmt.Printf("[Debug] body : %s\n", string(bodyBytes))
statusCode = resp.StatusCode
fmt.Printf("[Debug] status : %d\n", statusCode)
return
}