-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.go
49 lines (41 loc) · 948 Bytes
/
web.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
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func accountinfo(url, user, pass, info string) string {
var out string
response, err := http.Get(url + "api/send_sms.cfm?uname=" + user + "&pword=" + pass + "&sacc=" + user + "&action=balance")
if err != nil {
log.Println("Error while downloading", url, ":", err)
}
// Verify if the response was ok
if response.StatusCode != http.StatusOK {
log.Printf("Server return non-200 status: %v\n", response.Status)
}
defer response.Body.Close()
message, _ := ioutil.ReadAll(response.Body)
parsed := parseAccountInfo(string(message))
if len(parsed) > 0 {
switch info {
case "credit":
out = parsed[0]
case "tax":
out = parsed[2]
default:
for i, aObj := range parsed {
if i == len(parsed)-1 {
out += aObj
} else {
out += aObj + ","
}
}
}
} else {
fmt.Println("Improper Result")
fmt.Println(string(message))
}
return out
}