forked from alloy-d/goauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersist.go
38 lines (32 loc) · 813 Bytes
/
persist.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
package oauth
import (
"fmt"
"os"
)
// Stores access token information to the given filename.
//
// Format is the same as the return from the server.
func (o *OAuth) Save(fileName string) (err error) {
file, err := os.OpenFile(fileName, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0600)
defer file.Close()
if err != nil {
return
}
fmt.Fprintf(file, "oauth_token=%s&oauth_token_secret=%s", o.AccessToken, o.AccessSecret)
if o.userId != 0 {
fmt.Fprintf(file, "&user_id=%d", o.userId)
}
if o.userName != "" {
fmt.Fprintf(file, "&screen_name=%s", o.userName)
}
return nil
}
// Loads access token information from a file.
func (o *OAuth) Load(fileName string) (err error) {
file, err := os.Open(fileName)
defer file.Close()
if err != nil {
return
}
return o.parseResponse(200, file, TokenReq)
}