meta_position.go 622 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package helper
  2. import (
  3. "github.com/gshopify/service-wrapper/model"
  4. "gshopper.com/gshopify/products/graphql/generated"
  5. "strconv"
  6. )
  7. func ExtractMetaPosition(namespace model.Gid, metas []*generated.Metafield) int64 {
  8. for _, meta := range metas {
  9. if meta == nil {
  10. continue
  11. }
  12. if model.Gid(meta.Namespace) != namespace {
  13. continue
  14. }
  15. t := model.MetaFieldType(meta.Type)
  16. if !t.IsValid() || model.MetaFieldTypeNumberInteger != t {
  17. continue
  18. }
  19. if meta.Key != "position" {
  20. continue
  21. }
  22. i, err := strconv.ParseInt(meta.Value, 10, 64)
  23. if err != nil {
  24. i = -1
  25. }
  26. return i
  27. }
  28. return -1
  29. }