Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Assets do not seem to support locales correctly #45

Open
lc-jordanfelix opened this issue Oct 7, 2019 · 0 comments · May be fixed by #62
Open

Assets do not seem to support locales correctly #45

lc-jordanfelix opened this issue Oct 7, 2019 · 0 comments · May be fixed by #62

Comments

@lc-jordanfelix
Copy link

The assets that we are using have multiple locales, and whenever we try to func (service *AssetsService) Get OR func (service *AssetsService) List we get a a panic: interface conversion: interface {} is nil, not string.

We believe this is due to the types as defined below:

// FileFields model
type FileFields struct {
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	File        *File  `json:"file,omitempty"`
}

// Asset model
type Asset struct {
	locale string
	Sys    *Sys        `json:"sys"`
	Fields *FileFields `json:"fields"`
}

whereas an example of the the json return from the get request is as follows:

{
  "sys": {...},
  "fields": {
    "title": {
      "en-GB": "..."
    },
    "description": {
      "en-GB": "..."
    },
    "file": {
      "en-GB": {...}
    }
  }
}

which would mean the assets would unmarshall into structs more like the below:

// FileFields model
type FileFields struct {
	Title       map[string]string `json:"title,omitempty"`
	Description map[string]string `json:"description,omitempty"`
	File        map[string]*File  `json:"file,omitempty"`
}

or similar.

We tried switching to single locale, and it still seems to have the same issue.

florian-besser pushed a commit to florian-besser/contentful-go that referenced this issue Apr 20, 2021
Allow localized unmarshalling

This should fix contentful-labs#45
@florian-besser florian-besser linked a pull request Apr 20, 2021 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant