func main() { start := time.Now() flag.Usage = usage flag.Parse() overrideFlags() if *version { fmt.Printf("%s %s\n", Name, Version) os.Exit(1) } target := flag.Arg(0) if target == "" { flag.Usage() os.Exit(1) } initLoggers() logInfo.Printf("Initializing %s:%s...", Name, Version) logInfo.Printf("Loading archives from %s", *arcsloc) body, err := readArchives() if err != nil { fmt.Fprintf(os.Stderr, "Error reading list of archives (%s): %s\n", *arcsloc, err) os.Exit(1) } err = json.Unmarshal(body, &archives) archives.filterIgnored() sort.Sort(archives) if err != nil { fmt.Fprintf(os.Stderr, "Error parsing JSON (%s): %s\n", *arcsloc, err) os.Exit(1) } if target == "server" { fmt.Printf(appInfo()) fmt.Printf(serviceInfo()) addr := fmt.Sprintf(":%d", *port) http.HandleFunc("/", welcome) http.ListenAndServe(addr, http.HandlerFunc(router)) } else { urir, err := parseURI(target) if err != nil { os.Exit(1) } var dttm *time.Time if rawdtm := flag.Arg(1); rawdtm != "" { if regs["dttmstr"].MatchString(rawdtm) { dttm, err = paddedTime(rawdtm) if err != nil { os.Exit(1) } } else { logError.Printf("Malformed datetime {YYYY[MM[DD[hh[mm[ss]]]]]}: %s", rawdtm) os.Exit(1) } } memgatorCli(urir, *format, dttm) } elapsed := time.Since(start) logInfo.Printf("Uptime: %s", elapsed) }
func main() { start := time.Now() flag.Usage = usage flag.Parse() overrideFlags() if *version { fmt.Printf("%s %s\n", Name, Version) os.Exit(1) } target := flag.Arg(0) if target == "" { flag.Usage() os.Exit(1) } initLoggers() initNetwork() logInfo.Printf("Initializing %s:%s...", Name, Version) logInfo.Printf("Loading archives from %s", *arcsloc) body, err := readArchives() if err != nil { logFatal.Fatalf("Error reading list of archives (%s): %s\n", *arcsloc, err) } err = json.Unmarshal(body, &archives) archives.sanitize() archives.filterIgnored() sort.Sort(archives) if err != nil { logFatal.Fatalf("Error parsing JSON (%s): %s\n", *arcsloc, err) } if target == "server" { fmt.Printf(appInfo()) fmt.Printf(serviceInfo()) if *monitor { broker = sse.NewServer() } addr := fmt.Sprintf(":%d", *port) err = http.ListenAndServe(addr, http.HandlerFunc(router)) if err != nil { logFatal.Fatalf("Error listening: %s\n", err) } } else { urir, err := parseURI(target) if err != nil { logFatal.Fatalf("URI parsing error (%s): %v\n", target, err) } var dttm *time.Time if rawdtm := flag.Arg(1); rawdtm != "" { if regs["dttmstr"].MatchString(rawdtm) { dttm, err = paddedTime(rawdtm) if err != nil { logFatal.Fatalf("Time parsing error (%s): %v\n", rawdtm, err) } } else { logFatal.Fatalf("Malformed datetime (%s): %s\n", validDatetimes, rawdtm) } } memgatorCli(urir, *format, dttm) } elapsed := time.Since(start) logInfo.Printf("Uptime: %s", elapsed) }