-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
64 lines (57 loc) · 1.43 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
61
62
63
64
package main
import (
"crypto/rand"
"encoding/base64"
"flag"
"fmt"
)
func main() {
serverMode := flag.Bool("s", false, "server mode")
name := flag.String("name", "", "name")
delete := flag.String("delete", "", "key to delete")
pub := flag.String("pub", "", "public identity")
secret := flag.String("secret", "", "secret key")
app := flag.String("app", "", "application name")
port := flag.String("p", "4242", "server port")
host := flag.String("host", "127.0.0.1", "server addr")
db := flag.String("db", "database.db", "database file")
flag.Parse()
dal, err := newDAL(*db)
if err != nil {
fmt.Println(err)
}
if *serverMode {
runAPI(dal, *host, *port)
} else {
if *app != "" {
randomkey := make([]byte, 256)
_, err := rand.Read(randomkey)
if err != nil {
fmt.Println("error getting random data:", err)
} else {
app, err := dal.CreateApp(&App{Name: *app, Key: randomkey})
if err != nil {
fmt.Println(err)
} else {
fmt.Println("app created, id:", app.Id, "key:", base64.StdEncoding.EncodeToString(app.Key))
}
}
} else {
if *delete != "" {
err := dal.DeleteKey(&Key{Name: *delete})
if err != nil {
fmt.Println(err)
} else {
fmt.Println("key deleted: OK")
}
} else {
err := dal.CreateKey(&Key{Name: *name, Public: *pub, Secret: *secret})
if err != nil {
fmt.Println(err)
} else {
fmt.Println("creation of the key: OK")
}
}
}
}
}