-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure.go
66 lines (50 loc) · 1.05 KB
/
configure.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"bufio"
"fmt"
"github.com/JorgenEvens/ddns-client/arguments"
"os"
"strings"
)
func prompt(prompt string) string {
reader := bufio.NewReader(os.Stdin)
fmt.Print(prompt + ": ")
username, _ := reader.ReadString('\n')
return strings.TrimRight(username, "\n")
}
func configure() {
read, endpoint := arguments.Value("endpoint")
if !read {
endpoint = prompt("API Location")
}
read, username := arguments.Value("username")
if !read {
username = prompt("Username")
}
read, config := arguments.Value("config")
if !read {
config = "./config.json"
}
password := prompt("Password")
var api Api
api.Endpoint = endpoint
acquireToken(&api, username, password)
err := api.SaveConfiguration(config)
if err != nil {
fmt.Println(err)
}
}
func acquireToken(api *Api, username string, password string) {
var user User
user.Username = username
user.Password = password
if user.Client == nil {
user.Client = new(Client)
}
user.Client = NewClient()
err := user.Login(api)
if err != nil {
fmt.Println(err)
return
}
}