-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth.go
51 lines (44 loc) · 897 Bytes
/
auth.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
package main
import (
"fmt"
"log"
"net/url"
"github.com/writeas/go-writeas/v2"
)
var Client *writeas.Client
func SignIn(u string, p string, i string) error {
if i == "" {
fmt.Println("Logging in...")
// Client = writeas.NewDevClient() // Use in development
Client = writeas.NewClient()
_, err := Client.LogIn(u, p)
if err != nil {
return err
}
fmt.Println("Logged in!")
return nil
}
instance, err := url.Parse(i)
if err != nil {
return err
}
instance.Scheme = "https"
instance.Path += "/api"
fmt.Println("Logging in to", i)
config := writeas.Config{URL: instance.String()}
Client = writeas.NewClientWith(config)
_, err = Client.LogIn(u, p)
if err != nil {
return err
}
fmt.Println("Logged in!")
return nil
}
func SignOut() {
fmt.Println("Logging out...")
err := Client.LogOut()
if err != nil {
log.Fatal(err)
}
fmt.Println("Logged out!")
}