extensions.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package ext
  2. // Extensions is the generic extension map for Feeds and Items.
  3. // The first map is for the element namespace prefix (e.g., itunes).
  4. // The second map is for the element name (e.g., author).
  5. type Extensions map[string]map[string][]Extension
  6. // Extension represents a single XML element that was in a non
  7. // default namespace in a Feed or Item/Entry.
  8. type Extension struct {
  9. Name string `json:"name"`
  10. Value string `json:"value"`
  11. Attrs map[string]string `json:"attrs"`
  12. Children map[string][]Extension `json:"children"`
  13. }
  14. func parseTextExtension(name string, extensions map[string][]Extension) (value string) {
  15. if extensions == nil {
  16. return
  17. }
  18. matches, ok := extensions[name]
  19. if !ok || len(matches) == 0 {
  20. return
  21. }
  22. match := matches[0]
  23. return match.Value
  24. }
  25. func parseTextArrayExtension(name string, extensions map[string][]Extension) (values []string) {
  26. if extensions == nil {
  27. return
  28. }
  29. matches, ok := extensions[name]
  30. if !ok || len(matches) == 0 {
  31. return
  32. }
  33. values = []string{}
  34. for _, m := range matches {
  35. values = append(values, m.Value)
  36. }
  37. return
  38. }