-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.go
More file actions
42 lines (35 loc) · 787 Bytes
/
client.go
File metadata and controls
42 lines (35 loc) · 787 Bytes
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
package main
import (
"net/http"
"os"
"os/user"
"path/filepath"
cookiejar "github.com/Komosa/persistent-cookiejar"
"golang.org/x/net/publicsuffix"
)
const CFURL = "https://codeforces.com"
func (cf *cf) initClient() error {
sysuser, err := user.Current()
if err != nil {
return err
}
fp := filepath.Clean(sysuser.HomeDir + "/.config/cf/")
if err = os.MkdirAll(fp, 0700); err != nil {
return err
}
jar, err := cookiejar.New(&cookiejar.Options{
PublicSuffixList: publicsuffix.List,
Filename: filepath.Clean(fp + "/" + cf.config["user"] + ".cookie"),
})
cf.client = &http.Client{Jar: jar}
return err
}
func (cf *cf) saveCookie() error {
if c := cf.client; c != nil {
j, ok := c.Jar.(*cookiejar.Jar)
if ok {
return j.Save()
}
}
return nil
}