forked from S1mpleTheBest/hilink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (49 loc) · 1.11 KB
/
main.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
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"os"
"github.com/S1mpleTheBest/hilink"
)
var (
flagEndpoint = flag.String("endpoint", "http://192.168.8.1/", "api endpoint")
flagDebug = flag.Bool("v", false, "enable verbose")
flagLogin = flag.String("l", "", "login")
flagPassword = flag.String("p", "", "password")
)
func main() {
var err error
flag.Parse()
// options
opts := []hilink.Option{
hilink.URL(*flagEndpoint),
hilink.Host(*flagEndpoint),
}
if *flagLogin != "" && *flagPassword != "" {
opts = append(opts, hilink.Auth(*flagLogin, *flagPassword))
}
if *flagDebug {
opts = append(opts, hilink.Log(log.Printf, log.Printf))
}
// create client
client, err := hilink.NewClient(opts...)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
// get device info
d, err := client.DeviceInfo()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
// change to json
v, err := json.MarshalIndent(d, "", " ")
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
fmt.Fprintf(os.Stdout, "%s\n", string(v))
}