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) }
// Collect all files in `rootpath` and parse them as OpenPGP ASCII armor files. func ScanPGPKeys(rootpath string) { // Walk through all directories and fetch pubkeys err := filepath.Walk(rootpath, func(path string, f os.FileInfo, err error) error { if err != nil { panic(err) } if dir, err := utils.IsDirectory(path); dir && err == nil { // Don't scan a directory for ascii blocks return nil } // Pass a file path to parser function ParseArmorFile(path) return nil }) if err != nil { log.Printf("filepath.Walk() returned %v\n", err) } }