-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (43 loc) · 1001 Bytes
/
main.go
File metadata and controls
54 lines (43 loc) · 1001 Bytes
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
package main
import (
"bytes"
"encoding/json"
"fmt"
"os"
"example.com/shared"
)
func run(user string, host string, dir string) (string, error) {
m := &shared.Manager{}
defer m.Close()
authorize, err := m.Client(dir)
if err != nil {
return "", fmt.Errorf("failed to get client: %w", err)
}
resp, err := authorize.Get(user, host)
if err != nil {
return "", fmt.Errorf("failed to authorize: %w", err)
}
// Pretty print directly from raw JSON response
var out bytes.Buffer
if err := json.Indent(&out, resp, "", " "); err != nil {
return "", fmt.Errorf("error formatting JSON: %w", err)
}
return out.String(), nil
}
func main() {
if len(os.Args) < 3 {
fmt.Printf("Usage: %s <USER> <HOST>\n", os.Args[0])
os.Exit(1)
}
user := os.Args[1]
// "http://localhost:8080/token?user="
host := os.Args[2]
dir := "build/plugins"
out, err := run(user, host, dir)
if err != nil {
fmt.Println("Error calling plugin:", err)
os.Exit(1)
}
fmt.Println(out)
os.Exit(0)
}