Skip to content

Commit

Permalink
feat: DefaultLocale and better version check
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian Vidmar committed Aug 22, 2023
1 parent ba27368 commit 524dd9d
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 78 deletions.
6 changes: 3 additions & 3 deletions erm/templates/contentful_vo_base.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ type RichTextData struct {

type RichTextGenericNode struct {
NodeType string `json:"nodeType"`
Content []*RichTextGenericNode `json:"content"`
Data map[string]interface{} `json:"data"`
Content []*RichTextGenericNode `json:"content,omitempty"`
Data map[string]interface{} `json:"data,omitempty"`
Value string `json:"value"`
Marks []RichTextMark `json:"marks"`
Marks []RichTextMark `json:"marks,omitempty"`
}

type richTextHtmlTag struct {
Expand Down
4 changes: 2 additions & 2 deletions erm/templates/contentful_vo_lib.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const (
var SpaceLocales = []Locale{ {{ range $index , $locale := $locales }}
"{{$locale.Code}}",{{ end }}
}
{{ range $index , $locale := $locales }}{{ if $locale.Default }}const defaultLocale Locale = SpaceLocale{{ onlyLetters $locale.Name }}{{ end }}
{{ range $index , $locale := $locales }}{{ if $locale.Default }}const DefaultLocale Locale = SpaceLocale{{ onlyLetters $locale.Name }}{{ end }}
{{ end }}var localeFallback = map[Locale]Locale{ {{ range $index, $locale := $locales }}{{if $locale.FallbackCode}} SpaceLocale{{ onlyLetters $locale.Name }}: {{ range $indexSearch, $localeSearch := $locales }}{{ if eq $localeSearch.Code $locale.FallbackCode}}SpaceLocale{{ onlyLetters $localeSearch.Name }}{{ end }}{{ end }}, {{ else }}SpaceLocale{{ onlyLetters $locale.Name }}: "", {{ end }}{{ end }}}

const (
Expand Down Expand Up @@ -422,7 +422,7 @@ func NewAssetFromURL(id string, uploadUrl string, imageFileType string, title st
return nil
}
} else {
loc = defaultLocale
loc = DefaultLocale
}
asset := &contentful.Asset{
Sys: &contentful.Sys{
Expand Down
18 changes: 9 additions & 9 deletions erm/templates/contentful_vo_lib_contenttype.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (vo *Cf{{ firstCap $contentType.Sys.ID }}) {{ firstCap $field.ID }}(locale
}
vo.Fields.RWLock{{ firstCap $field.ID }}.RLock()
defer vo.Fields.RWLock{{ firstCap $field.ID }}.RUnlock()
loc := defaultLocale
loc := DefaultLocale
if len(locale) != 0 {
loc = locale[0]
if _, ok := localeFallback[loc]; !ok {
Expand Down Expand Up @@ -182,7 +182,7 @@ func (vo *Cf{{ firstCap $contentType.Sys.ID }}) {{ firstCap $field.ID }}(locale
}
vo.Fields.RWLock{{ firstCap $field.ID }}.RLock()
defer vo.Fields.RWLock{{ firstCap $field.ID }}.RUnlock()
loc := defaultLocale
loc := DefaultLocale
if len(locale) != 0 {
loc = locale[0]
if _, ok := localeFallback[loc]; !ok {
Expand Down Expand Up @@ -222,7 +222,7 @@ func (vo *Cf{{ firstCap $contentType.Sys.ID }}) {{ firstCap $field.ID }}(locale
vo.Fields.RWLock{{ firstCap $field.ID }}.RLock()
defer vo.Fields.RWLock{{ firstCap $field.ID }}.RUnlock()
{{ $field.ID }} := []*EntryReference{}
loc := defaultLocale
loc := DefaultLocale
if len(locale) != 0 {
loc = locale[0]
if _, ok := localeFallback[loc]; !ok {
Expand Down Expand Up @@ -282,7 +282,7 @@ func (vo *Cf{{ firstCap $contentType.Sys.ID }}) {{ firstCap $field.ID }}(locale
}
vo.Fields.RWLock{{ firstCap $field.ID }}.RLock()
defer vo.Fields.RWLock{{ firstCap $field.ID }}.RUnlock()
loc := defaultLocale
loc := DefaultLocale
if len(locale) != 0 {
loc = locale[0]
if _, ok := localeFallback[loc]; !ok {
Expand Down Expand Up @@ -342,8 +342,8 @@ func (vo *Cf{{ firstCap $contentType.Sys.ID }}) {{ firstCap $field.ID }}(locale
vo.Fields.RWLock{{ firstCap $field.ID }}.RLock()
defer vo.Fields.RWLock{{ firstCap $field.ID }}.RUnlock()
{{ $field.ID }} := []*contentful.AssetNoLocale{}
loc := defaultLocale
reqLoc := defaultLocale
loc := DefaultLocale
reqLoc := DefaultLocale
if len(locale) != 0 {
loc = locale[0]
reqLoc = locale[0]
Expand Down Expand Up @@ -410,8 +410,8 @@ func (vo *Cf{{ firstCap $contentType.Sys.ID }}) {{ firstCap $field.ID }}(locale
}
vo.Fields.RWLock{{ firstCap $field.ID }}.RLock()
defer vo.Fields.RWLock{{ firstCap $field.ID }}.RUnlock()
loc := defaultLocale
reqLoc := defaultLocale
loc := DefaultLocale
reqLoc := DefaultLocale
if len(locale) != 0 {
loc = locale[0]
reqLoc = locale[0]
Expand Down Expand Up @@ -474,7 +474,7 @@ func (vo *Cf{{ firstCap $contentType.Sys.ID }}) Set{{ firstCap $field.ID }}({{ $
if vo == nil {
return errors.New("Set{{ firstCap $field.ID }}({{ $field.ID }}: Value Object is nil")
}
loc := defaultLocale
loc := DefaultLocale
if len(locale) != 0 {
loc = locale[0]
if _, ok := localeFallback[loc]; !ok {
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/foomo/gocontentful/erm"
)

var VERSION = "v1.0.22"
var VERSION = "v1.0.23"

type contentfulRc struct {
ManagementToken string `json:"managementToken"`
Expand Down Expand Up @@ -86,7 +86,7 @@ func main() {
if err != nil {
fatal(err)
}
if conf.RequireVersion != "" && conf.RequireVersion != VERSION {
if conf.RequireVersion != "" && conf.RequireVersion != VERSION && conf.RequireVersion != strings.Trim(VERSION, "v") {
fatal("Required version mismatch. Want: " + conf.RequireVersion + " Have: " + VERSION)
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/testapi/gocontentfulvo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions test/testapi/gocontentfulvobase.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions test/testapi/gocontentfulvolib.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions test/testapi/gocontentfulvolibbrand.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions test/testapi/gocontentfulvolibcategory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 524dd9d

Please sign in to comment.