forked from mfrister/syno-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (43 loc) · 957 Bytes
/
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
package main
import (
"log"
"os"
"gopkg.in/alecthomas/kingpin.v1"
"jluccisano/go/syno-cli/synoapi"
)
var (
enable = kingpin.Command("enable", "Enable camera")
disable = kingpin.Command("disable", "Disable camera")
)
func main() {
// something like https://myds.example.net:5001
api_base := os.Getenv("SYNO_BASE_URL")
user := os.Getenv("SYNO_USER")
password := os.Getenv("SYNO_PASSWORD")
command := kingpin.Parse()
client := synoapi.NewClient(api_base)
err := client.Login(user, password)
if err != nil {
log.Fatal(err)
}
switch command {
default:
kingpin.Usage()
case "enable":
enableCamera(client)
case "disable":
disableCamera(client)
}
}
func enableCamera(client *synoapi.Client) {
err := client.Enable()
if err != nil {
log.Fatalf("Locking failed: %v", err)
}
}
func disableCamera(client *synoapi.Client) {
err := client.Disable()
if err != nil {
log.Fatalf("Locking failed: %v", err)
}
}