-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (57 loc) · 1.39 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
65
66
67
68
69
70
71
72
73
package main
import (
"net/http"
"os"
"github.com/BurntSushi/toml"
"github.com/superp00t/etc"
"github.com/Cryptodog/bex-attachment-server/server"
"github.com/superp00t/etc/yo"
)
func getConfig(path string) *server.Config {
if etc.ParseSystemPath(path).IsExtant() == false {
fl, err := etc.FileController(path)
if err != nil {
yo.Fatal(err)
}
enc := toml.NewEncoder(fl)
err = enc.Encode(&server.Config{
AttachmentAddress: ":8080",
TURNAddress: "0.0.0.0:3478",
StorageLimit: 300 * server.MB,
DataLocation: "/tmp/bex-attachments",
Proxied: false,
Accounts: map[string]string{
"user": "password",
},
})
if err != nil {
yo.Fatal(err)
}
yo.Ok("A basic configuration file has been created at", path, ". You should edit it to your liking.")
os.Exit(0)
}
f, err := etc.FileController(path)
if err != nil {
yo.Fatal(err)
}
cfg := new(server.Config)
_, err = toml.DecodeReader(f, cfg)
if err != nil {
yo.Fatal(err)
}
f.Close()
return cfg
}
func sserver(s []string) {
cerr := make(chan error)
cfg := getConfig(yo.StringG("c"))
go func() {
cerr <- http.ListenAndServe(cfg.AttachmentAddress, server.New(cfg))
}()
yo.Fatal(<-cerr)
}
func main() {
yo.Stringf("c", "config", "configuration file", os.Getenv("HOME")+"/config.toml")
yo.Main("allows users to upload files using the Cryptodog BEX API", sserver)
yo.Init()
}