func main() { configFile := flag.String("config-file", "", "Config file for RETS connection") metadataFile := flag.String("metadata-options", "", "Config file for metadata options") output := flag.String("output", "", "Directory for file output") config := common.Config{} config.SetFlags() metadataOpts := MetadataOptions{} metadataOpts.SetFlags() flag.Parse() if *configFile != "" { err := config.LoadFrom(*configFile) if err != nil { panic(err) } } fmt.Printf("Connection Settings: %v\n", config) if *metadataFile != "" { err := metadataOpts.LoadFrom(*metadataFile) if err != nil { panic(err) } } fmt.Printf("Search Options: %v\n", metadataOpts) // should we throw an err here too? session, err := config.Initialize() if err != nil { panic(err) } ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) defer cancel() capability, err := rets.Login(session, ctx, rets.LoginRequest{URL: config.URL}) if err != nil { panic(err) } defer rets.Logout(session, ctx, rets.LogoutRequest{URL: capability.Logout}) reader, err := rets.MetadataStream(session, ctx, rets.MetadataRequest{ URL: capability.GetMetadata, Format: metadataOpts.Format, MType: metadataOpts.MType, ID: metadataOpts.ID, }) defer reader.Close() if err != nil { panic(err) } out := os.Stdout if *output != "" { out, _ = os.Create(*output + "/metadata.xml") defer out.Close() } io.Copy(out, reader) }
// GetCompactIncrementalMetadata retrieve the RETS Compact metadata from the server func (ic *IncrementalCompact) Load(sess rets.Requester, ctx context.Context, url string) error { // extract an id'd subesection of metadata get := func(id, mtype string) (*rets.CompactMetadata, error) { if id == "" { id = "0" } req := rets.MetadataRequest{ URL: url, Format: "COMPACT", MType: mtype, ID: id, } reader, er := rets.MetadataStream(sess, ctx, req) if er != nil { return nil, er } return rets.ParseMetadataCompactResult(reader) } msys, err := get("", metadata.MISystem.Name) if err != nil { return err } ic.Response = msys.Response ic.MSystem = msys.MSystem ic.Elements = map[string][]rets.CompactData{} // fmt.Printf("compact system: %v\n", compact) cds, err := ic.extractChildren(get, []string{}, metadata.MISystem) if err != nil { return err } for _, cd := range cds { // extract children from this element and put in the system elem ic.Elements[cd.Element] = append(ic.Elements[cd.Element], cd) } return nil }