-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcancel.go
49 lines (42 loc) · 1.04 KB
/
cancel.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 (
"flag"
"fmt"
"log"
"net/http"
"net/http/cookiejar"
"net/url"
)
type Cancel struct {
VisitID *string
}
func (cmd *Cancel) Name() string { return "cancel" }
func (cmd *Cancel) Synopsis() string { return "Cancel a visit" }
func (cmd *Cancel) DefineFlags(fs *flag.FlagSet) {
cmd.VisitID = fs.String("visitid", "", "Visit ID to cancel.")
}
func (cmd *Cancel) Run() {
log.SetOutput(LogOutput())
if *cmd.VisitID == "" {
fmt.Println("Must specify visitid.")
return
}
// Load session
mboSession, err := LoadMBOSession()
if err != nil {
fmt.Println(err)
return
}
cookieJar, _ := cookiejar.New(nil)
client := &http.Client{Jar: cookieJar}
mbo_url, _ := url.Parse(MBO_URL)
client.Jar.SetCookies(mbo_url, mboSession.Cookies)
resp, err := client.Get(fmt.Sprintf("%s/ASP/adm/adm_res_canc.asp?visitID=%s&cType=1", MBO_URL, *cmd.VisitID))
if err != nil || resp.StatusCode != 200 {
log.Println(err)
log.Println(resp)
fmt.Println("Error performing cancel.")
}
defer resp.Body.Close()
fmt.Println("Cancelled visit.")
}