func worker(queue, out chan string, timeout time.Duration, wg *sync.WaitGroup) { defer wg.Done() for endpoint := range queue { ri, err := oaimi.AboutEndpoint(endpoint, timeout) if err != nil { if Verbose { log.Printf("failed %s: %s", endpoint, err) } continue } b, err := json.Marshal(ri) if err != nil { log.Fatal(err) } out <- string(b) if Verbose { log.Printf("done: %s", endpoint) } } }
func main() { var err error home, err := homedir.Dir() if err != nil { home = "." } cacheDir := flag.String("cache", filepath.Join(home, oaimi.DefaultCacheDir), "oaimi cache dir") showRepoInfo := flag.Bool("id", false, "show repository info") set := flag.String("set", "", "OAI set") prefix := flag.String("prefix", "oai_dc", "OAI metadataPrefix") from := flag.String("from", "", "OAI from") until := flag.String("until", time.Now().Format("2006-01-02"), "OAI until") root := flag.String("root", "", "name of artificial root element tag to use") showVersion := flag.Bool("v", false, "prints current program version") verbose := flag.Bool("verbose", false, "more output") dirname := flag.Bool("dirname", false, "show shard directory for request") flag.Parse() if *showVersion { fmt.Println(oaimi.Version) os.Exit(0) } if flag.NArg() == 0 { log.Fatal("endpoint URL required") } endpoint := flag.Arg(0) if !strings.HasPrefix(endpoint, "http") { endpoint = "http://" + endpoint } if *cacheDir == "" { log.Fatal("cache dir must be set") } if *showRepoInfo { ri, err := oaimi.AboutEndpoint(endpoint, 10*time.Minute) if err != nil { log.Fatal(err) } b, err := json.Marshal(ri) if err != nil { log.Fatal(err) } fmt.Println(string(b)) os.Exit(0) } oaimi.Verbose = *verbose client := oaimi.NewCachingClientDir(os.Stdout, *cacheDir) if *root != "" { client.RootTag = *root } req := oaimi.Request{ Endpoint: endpoint, Verb: "ListRecords", Prefix: *prefix, } if *set != "" { req.Set = *set } if *from != "" { if req.From, err = time.Parse("2006-01-02", *from); err != nil { log.Fatal(err) } } if *until != "" { if req.Until, err = time.Parse("2006-01-02", *until); err != nil { log.Fatal(err) } } if *dirname { req.UseDefaults() dir, err := client.RequestCacheDir(req) if err != nil { log.Fatal(err) } fmt.Println(dir) os.Exit(0) } if err := client.Do(req); err != nil { log.Fatal(err) } }