This repository has been archived by the owner on Apr 2, 2021. It is now read-only.
/
fingerprinter.go
71 lines (58 loc) · 1.81 KB
/
fingerprinter.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
// Copyright 2015, 2016 Dominik Pataky <dom@netdecorator.org>
// This file is part of Fingerprinter, for licence details see LICENCE
// Fingerprinter
// Use this tool to let others check if a fingerprint really belongs to one of your keys.
package fingerprinter
import (
"encoding/json"
"log"
"os"
"fingerprinter/repo"
"fingerprinter/utils"
"fingerprinter/web"
)
// Config with all needed fields
type Config struct {
Port string
Baseurl string
Datafile string
Keydir string
Templatedir string
Staticdir string
}
func StartServer() {
config := Config{}
fh, err := os.Open("config.json")
if err != nil {
log.Fatal(err)
}
dec := json.NewDecoder(fh)
err = dec.Decode(&config)
if err != nil {
log.Println("Error parsing config.json")
log.Fatal(err)
}
log.Println("Config okay, checking paths")
// Check needed paths for existence, eg the CSV file, template and static folders
toCheck := []string{config.Datafile, config.Templatedir, config.Staticdir}
for _, e := range toCheck {
if ok, err := utils.PathExistsErr(e); !ok {
log.Fatal(err)
}
}
// If the value is not given in the config, it's an empty string.
if config.Keydir != "" {
// If not an empty string, check if it's a folder.
if ok, _ := utils.IsDirectory(config.Keydir); ok {
repo.ScanPGPKeys(config.Keydir)
} else {
log.Println("config.Keydir is given, but not a valid path.")
}
}
log.Println("Starting server on port", config.Port)
r := repo.GetRepo()
r.ReadDatafile(config.Datafile)
log.Println("The following entities were read:")
r.Print()
web.Run(config.Port, config.Baseurl, config.Templatedir, config.Staticdir)
}