foomo-docs/docs/projects/cms/gocontentful/api-reference.html
2024-06-10 09:44:34 +00:00

240 lines
29 KiB
HTML

<!doctype html>
<html lang="en" dir="ltr" class="docs-wrapper plugin-docs plugin-id-default docs-version-current docs-doc-page docs-doc-id-projects/cms/gocontentful/api-reference" data-has-hydrated="false">
<head>
<meta charset="UTF-8">
<meta name="generator" content="Docusaurus v3.0.0">
<title data-rh="true">API Reference | foomo project docs</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:url" content="https://www.foomo.org/docs/projects/cms/gocontentful/api-reference"><meta data-rh="true" property="og:locale" content="en"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="docusaurus_version" content="current"><meta data-rh="true" name="docusaurus_tag" content="docs-default-current"><meta data-rh="true" name="docsearch:version" content="current"><meta data-rh="true" name="docsearch:docusaurus_tag" content="docs-default-current"><meta data-rh="true" property="og:title" content="API Reference | foomo project docs"><meta data-rh="true" name="description" content="Client and cache"><meta data-rh="true" property="og:description" content="Client and cache"><link data-rh="true" rel="icon" href="/img/favicon.ico"><link data-rh="true" rel="canonical" href="https://www.foomo.org/docs/projects/cms/gocontentful/api-reference"><link data-rh="true" rel="alternate" href="https://www.foomo.org/docs/projects/cms/gocontentful/api-reference" hreflang="en"><link data-rh="true" rel="alternate" href="https://www.foomo.org/docs/projects/cms/gocontentful/api-reference" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://SUATUVZDDM-dsn.algolia.net" crossorigin="anonymous"><link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="foomo project docs RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="foomo project docs Atom Feed">
<link rel="search" type="application/opensearchdescription+xml" title="foomo project docs" href="/opensearch.xml"><link rel="stylesheet" href="/assets/css/styles.78fe5ce6.css">
<script src="/assets/js/runtime~main.638e5c2c.js" defer="defer"></script>
<script src="/assets/js/main.1248442c.js" defer="defer"></script>
</head>
<body class="navigation-with-keyboard">
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return localStorage.getItem("theme")}catch(t){}}();t(null!==e?e:"light")}(),function(){try{const c=new URLSearchParams(window.location.search).entries();for(var[t,e]of c)if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}()</script><div id="__docusaurus"><div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="#__docusaurus_skipToContent_fallback">Skip to main content</a></div><nav aria-label="Main" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><b class="navbar__title text--truncate">foomo</b></a><a class="navbar__item navbar__link" href="/docs/general">General</a><a class="navbar__item navbar__link" href="/docs/frontend">Frontend</a><a class="navbar__item navbar__link" href="/docs/backend">Backend</a><a class="navbar__item navbar__link" href="/docs/devops">DevOps</a><a aria-current="page" class="navbar__item navbar__link navbar__link--active" href="/docs/projects">Projects</a></div><div class="navbar__items navbar__items--right"><a class="navbar__item navbar__link" href="/blog">Blog</a><div class="navbarSearchContainer_Bca1"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"></span></button></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="__docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_z2l0"><div class="docsWrapper_hBAB"><button aria-label="Scroll back to top" class="clean-btn theme-back-to-top-button backToTopButton_sjWU" type="button"></button><div class="docRoot_UBD9"><aside class="theme-doc-sidebar-container docSidebarContainer_YfHR"><div class="sidebarViewport_aRkj"><div class="sidebar_njMd"><nav aria-label="Docs sidebar" class="menu thin-scrollbar menu_SIkG"><ul class="theme-doc-sidebar-menu menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/docs/projects">Overview</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/docs/projects/architecture">Architecture</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--active" aria-expanded="true" href="/docs/projects/cms">CMS</a><button aria-label="Collapse sidebar category &#x27;CMS&#x27;" type="button" class="clean-btn menu__caret"></button></div><ul style="display:block;overflow:visible;height:auto" class="menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/docs/projects/cms/contentserver">contentserver</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/docs/projects/cms/contentful">contentful</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--active" aria-expanded="true" tabindex="0" href="/docs/projects/cms/gocontentful">Gocontentful</a><button aria-label="Collapse sidebar category &#x27;Gocontentful&#x27;" type="button" class="clean-btn menu__caret"></button></div><ul style="display:block;overflow:visible;height:auto" class="menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-3 menu__list-item"><a class="menu__link" tabindex="0" href="/docs/projects/cms/gocontentful/getting-started">Getting started</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-3 menu__list-item"><a class="menu__link" tabindex="0" href="/docs/projects/cms/gocontentful/test-api">Play with the test API</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-3 menu__list-item"><a class="menu__link" tabindex="0" href="/docs/projects/cms/gocontentful/working-with-gocontentful-api">Working with the Gocontentful API</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-3 menu__list-item"><a class="menu__link" tabindex="0" href="/docs/projects/cms/gocontentful/caching">Caching</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-3 menu__list-item"><a class="menu__link menu__link--active" aria-current="page" tabindex="0" href="/docs/projects/cms/gocontentful/api-reference">API Reference</a></li></ul></li></ul></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/docs/projects/gograpple">gograpple</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/docs/projects/gotsrpc">gotsrpc</a><button aria-label="Expand sidebar category &#x27;gotsrpc&#x27;" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/docs/projects/keel">keel</a><button aria-label="Expand sidebar category &#x27;keel&#x27;" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/docs/projects/pagespeed-exporter">pagespeed exporter</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/docs/projects/webgrapple">webgrapple</a></li></ul></nav></div></div></aside><main class="docMainContainer_TBSr"><div class="container padding-top--md padding-bottom--lg"><div class="row"><div class="col docItemCol_VOVn"><div class="docItemContainer_Djhp"><article><nav class="theme-doc-breadcrumbs breadcrumbsContainer_Z_bl" aria-label="Breadcrumbs"><ul class="breadcrumbs" itemscope="" itemtype="https://schema.org/BreadcrumbList"><li class="breadcrumbs__item"><a aria-label="Home page" class="breadcrumbs__link" href="/"><svg viewBox="0 0 24 24" class="breadcrumbHomeIcon_YNFT"><path d="M10 19v-5h4v5c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-7h1.7c.46 0 .68-.57.33-.87L12.67 3.6c-.38-.34-.96-.34-1.34 0l-8.36 7.53c-.34.3-.13.87.33.87H5v7c0 .55.45 1 1 1h3c.55 0 1-.45 1-1z" fill="currentColor"></path></svg></a></li><li itemscope="" itemprop="itemListElement" itemtype="https://schema.org/ListItem" class="breadcrumbs__item"><a class="breadcrumbs__link" itemprop="item" href="/docs/projects/cms"><span itemprop="name">CMS</span></a><meta itemprop="position" content="1"></li><li itemscope="" itemprop="itemListElement" itemtype="https://schema.org/ListItem" class="breadcrumbs__item"><a class="breadcrumbs__link" itemprop="item" href="/docs/projects/cms/gocontentful"><span itemprop="name">Gocontentful</span></a><meta itemprop="position" content="2"></li><li itemscope="" itemprop="itemListElement" itemtype="https://schema.org/ListItem" class="breadcrumbs__item breadcrumbs__item--active"><span class="breadcrumbs__link" itemprop="name">API Reference</span><meta itemprop="position" content="3"></li></ul></nav><div class="tocCollapsible_ETCw theme-doc-toc-mobile tocMobile_ITEo"><button type="button" class="clean-btn tocCollapsibleButton_TO0P">On this page</button></div><div class="theme-doc-markdown markdown"><h1 id="api-reference">API Reference</h1>
<h2 id="client-and-cache">Client and cache</h2>
<pre><code class="language-go">NewContentfulClient(
spaceID string,
clientMode string,
clientKey string,
optimisticPageSize uint16,
logFn func(fields map[string]interface{}, level int, args ...interface{}),
logLevel int,
debug bool,
) (*ContentfulClient, error)
</code></pre>
<p>Creates a Contentful client, <a href="./working-with-gocontentful-api#get-a-client">read this</a> for an explanation of all parameters.</p>
<pre><code class="language-go">SetOfflineFallback(filename string) error
</code></pre>
<p>Sets a path to a space export JSON file to be used as a fallback in case
Contentful is not reachable when you call UpdateCache() on the client. This ensures availability
but can make your content look outdated if the export file is older (and typically it is).</p>
<pre><code class="language-go">NewOfflineContentfulClient(
filename string,
logFn func(fields map[string]interface{}, level int, args ...interface{}),
logLevel int,
cacheAssets bool,
) (*ContentfulClient, error)
</code></pre>
<p>Creates an offline Contentful client that loads space data from a JSON file containing a space export.</p>
<pre><code class="language-go">(cc *ContentfulClient) SetEnvironment(environment string)
</code></pre>
<p>Sets the Contentful client&#x27;s environment. All subsequent API calls will be directed to that environment in the selected
space. Pass an empty string to reset to the <em>master</em> environment.</p>
<pre><code class="language-go">(cc *ContentfulClient) CacheHasContentType(contentTypeID string) bool
</code></pre>
<p>Returns true if the specified contentTypeID is cached by the client, false otherwise.</p>
<pre><code class="language-go">(cc *ContentfulClient) SetCacheUpdateTimeout(seconds int64)
</code></pre>
<p>Sets the cache update timeout to the specified length. A new client by default times out
caching in 120 seconds. A timeout is used to prevent deadlocks when a service panics and recovers
while the gocontentful goroutines are running and the main caching job is waiting for all
them to finish.</p>
<pre><code class="language-go">(cc *ContentfulClient) SetSyncMode(mode bool) error
</code></pre>
<p>Switches on/off the cache sync mode. This method will return an error if called on an offline client.</p>
<pre><code class="language-go">(cc *ContentfulClient) ResetSync()
</code></pre>
<p>Resets the sync token: the next call to UpdateCache() will rebuild the cache from scratch.</p>
<pre><code class="language-go">(cc *ContentfulClient) UpdateCache(ctx context.Context, contentTypes []string, cacheAssets bool) error
</code></pre>
<p>Builds or re-builds the entire client cache.</p>
<pre><code class="language-go">(cc *ContentfulClient) UpdateCacheForEntity(ctx context.Context, sysType string, contentType string, entityID string) error
</code></pre>
<p>Updates a single entry or asset (the sysType can take const sysTypeEntry or sysTypeAsset values) in the cache.</p>
<h2 id="content-functions-and-methods">Content functions and methods</h2>
<p><em>For these we&#x27;re assuming a content type named &quot;Person&quot;.</em></p>
<pre><code class="language-go">NewCfPerson(contentfulClient ...*ContentfulClient) (cfPerson *CfPerson)
</code></pre>
<p>Creates a new Person entry. You can manipulate and upsert this later. The contentfulClient parameter is optional but you
might want to pass it most of the times or you won&#x27;t be able to save the entry.</p>
<pre><code class="language-go">(cc *ContentfulClient) GetAllPerson() (voMap map[string]*CfPerson, err error)
</code></pre>
<p>Retrieves all Person entries from the client and returnes a map where the key is the ID of the entry and the value is
the Go value object for that entry.</p>
<pre><code class="language-go">(cc *ContentfulClient) GetFilteredPerson(query *contentful.Query) (voMap map[string]*CfPerson, err error)
</code></pre>
<p>Retrieves Person entries matching the specified query.</p>
<pre><code class="language-go">(cc *ContentfulClient) GetPersonByID(id string, forceNoCache ...bool) (vo *CfPerson, err error)
</code></pre>
<p>Retrieves the Person entry with the specified ID. The optional <em>forceNoCache</em> parameter, if true,
makes the function bypass the existing cache and load a fresh copy of the entry from Contentful.</p>
<pre><code class="language-go">(ref ContentfulReferencedEntry) ContentType() (contentType string)
</code></pre>
<p>Returns the Sys.ID of the content type of the referenced entry</p>
<pre><code class="language-go">(cc *ContentfulClient) GetContentTypeOfID(ID string) (contentType string)
</code></pre>
<p>Returns the Contentful content type of an entry ID.</p>
<pre><code class="language-go">(vo *CfPerson) ToReference() (refSys ContentTypeSys)
</code></pre>
<p>Converts a value object into a reference that can be added to a reference field of an entry. Note that functions that
retrieve referenced entries return a more flexible and useful <em>[]*EntryReference</em> (see Quickstart above) but to store
a reference you need a ContentTypeSys.</p>
<pre><code class="language-go">(vo *CfPerson) GetParents() (parents []EntryReference, err error)
(ref *EntryReference) GetParents(cc *ContentfulClient) (parents []EntryReference, err error)
</code></pre>
<p>Return a slice of EntryReference objects that represent entries that reference the value object or the entry reference.</p>
<p>Note that in case of parents of an entry reference you need to pass a pointer to a ContentfulClient because
EntryReference objects are generic and can&#x27;t carry any.</p>
<pre><code class="language-go">(vo *CfPerson) GetPublishingStatus() string
</code></pre>
<p>Returns the publishing status of the entry as per the Contentful editor UI.
Value returned is one of the following:</p>
<pre><code class="language-go">const (
StatusDraft = &quot;draft&quot;
StatusChanged = &quot;changed&quot;
StatusPublished = &quot;published&quot;
)
</code></pre>
<h2 id="entry-field-getters-and-setters">Entry field getters and setters</h2>
<p>Field getters are named after the field ID in Contentful and return the proper type. For example, if the Person content
type has a Symbol (short text) field named &#x27;Name&#x27;, this will be the getter:</p>
<pre><code class="language-go">(vo *CfPerson) Name(locale ...string) (string)
</code></pre>
<p>The locale parameter is optional and if not passed, the function will return the value for the default locale of the
space. If the locale is specified and it&#x27;s not available for the space, an error is returned. If the locale is valid
but a value doesn&#x27;t exist for the field and locale, the function will return the value for the default locale if that&#x27;s
specified as a fallback locale in the space definition in Contentful, otherwise will return an error.</p>
<p>Possible return types are:</p>
<ul>
<li><em>string</em> for fields of types Symbol, Text, Date</li>
<li><em>[]string</em> for fields of type List</li>
<li><em>float64</em> for fields of type Integer or Number</li>
<li><em>bool</em> for fields of type Boolean</li>
<li><em>*ContentTypeSys</em> for single reference fields</li>
<li><em>[]*ContentTypeSys</em> for multiple reference fields</li>
<li><em>*ContentTypeFieldLocation</em> for fields of type Location</li>
<li>*interface<!-- --> for fields of type Object or RichText</li>
</ul>
<p>If logLevel is set to LogDebug retrieving the value of a field that is not set and so not available in the API response
even as a fallback to the default locale will log the event. This can become incredibly verbose, use with care.</p>
<p>Field setters are named after the field ID in Contentful and require to pass in the proper type. See FIELD GETTERS above
for a reference. Example:</p>
<pre><code class="language-go">(vo *CfPerson) SetName(title string, locale ...string) (err error)
</code></pre>
<h2 id="entry-write-ops--only-available-for-clientmodecma">Entry write ops (only available for <em>ClientModeCMA</em>)</h2>
<pre><code class="language-go">(vo *CfPerson) UpsertEntry(cc *ContentfulClient) (err error)
</code></pre>
<p>Upserts the entry. This will appear as &quot;Draft&quot; (if it&#x27;s a new entry) or &quot;Changed&quot; if it&#x27;s already existing. In the
latter case, you will need to retrieve the entry with one of the Manage* functions above to acquire the Sys object
that contains the version information. Otherwise the API call will fail with a &quot;Version mismatch&quot; error.</p>
<pre><code class="language-go">(vo *CfPerson) PublishEntry(cc *ContentfulClient) (err error)
</code></pre>
<p>Publishes the entry. Note that before publishing you will need to retrieve the entry with one of the Manage* functions
above to acquire the Sys object that contains the version information. Otherwise the API call will fail with a &quot;Version
mismatch&quot; error. This is needed even if you have just upserted the entry with the function above!</p>
<pre><code class="language-go">(vo *CfPerson) UnpublishEntry(cc *ContentfulClient) (err error)
</code></pre>
<p>Unpublishes the entry. Note that before unpublishing you will need to retrieve the entry with one of the Manage*
functions above to acquire the Sys object that contains the version information. Otherwise the API call will fail with
a &quot;Version mismatch&quot; error. This is needed even if you have just upserted the entry with the function above!</p>
<pre><code class="language-go">(vo *CfPerson) UpdateEntry(cc *ContentfulClient) (err error)
</code></pre>
<p>Shortcut function that upserts and publishes the entry. Note that before calling this you will need to retrieve the
entry with one of the Manage* functions above to acquire the Sys object that contains the version information. Otherwise
the API call will fail with a &quot;Version mismatch&quot; error. Using this shortcut function avoids retrieving the entry twice.</p>
<pre><code class="language-go">(vo *CfPerson) DeleteEntry(cc *ContentfulClient) (err error)
</code></pre>
<p>Unpublishes and deletes the entry</p>
<h3 id="asset-functions">Asset functions</h3>
<pre><code class="language-go">(cc *ContentfulClient) DeleteAsset(asset *contentful.Asset) error
</code></pre>
<p>Deletes an asset from the space (only available in CMA)</p>
<pre><code class="language-go">(cc *ContentfulClient) DeleteAssetFromCache(key string) error {
</code></pre>
<p>Deletes an asset from the client&#x27;s cache</p>
<pre><code class="language-go">(cc *ContentfulClient) GetAllAssets() (map[string]*contentful.Asset, error)
</code></pre>
<p>Retrieve all assets from a space</p>
<pre><code class="language-go">(cc *ContentfulClient) GetAssetByID(id string, forceNoCache ...bool) (*contentful.Asset, error)
</code></pre>
<p>Retrieve an asset from a space by its ID. The optional <em>forceNoCache</em> parameter, if true,
makes the function bypass the existing cache and load a fresh copy of the asset from Contentful.</p>
<pre><code class="language-go">NewAssetFromURL(id string, uploadUrl string, imageFileType string, title string, locale ...string) *contentful.Asset
</code></pre>
<p>Creates an Asset from an URL of an existing file online (you still need to upsert it later).</p>
<pre><code class="language-go">ToAssetReference(asset *contentful.Asset) (refSys ContentTypeSys)
</code></pre>
<p>Converts the asset to a reference. You need to do this before you add the asset to a reference field of an entry.</p>
<pre><code class="language-go">(cc *ContentfulClient) DeleteAsset(asset *contentful.Asset) error
</code></pre>
<p>Deletes an asset from a space by its ID (only available for <em>ClientModeCMA</em>)</p>
<h3 id="other-helper-functions-and-methods">Other helper functions and methods</h3>
<pre><code class="language-go">(cc *ContentfulClient) BrokenReferences() (brokenReferences []BrokenReference)
</code></pre>
<p>Returns a slice of BrokenReference objects with details of where entries have been
referenced but they are not found in the cache. This might naturally return false
positives for content types that are in the space but not included in the cache.</p>
<pre><code class="language-go">FieldToObject(jsonField interface{}, targetObject interface{}) error
</code></pre>
<p>Converts a JSON field into an object. Make sure you pass a pointer to an object which type has JSON definition for all
fields you want to retrieve.</p>
<pre><code class="language-go">HtmlToRichText(htmlSrc string) *RichTextNode
</code></pre>
<p>Converts an HTML fragment to a RichTextNode. This is useful to migrate data from third-party systems to Contentful or
support HTML paste operations in Web applications. It currently supports headings, paragraphs, hyperlinks, italic and
bold tags, horizontal rules, blockquote, ordered and unordered lists, code. Unknown tags are stripped. This function
doesn&#x27;t return any error as it converts the input text into something as good as possible, without validation.</p>
<pre><code class="language-go">RichTextToHtml(rt interface{}, linkResolver LinkResolverFunc, entryLinkResolver EntryLinkResolverFunc, imageResolver ImageResolverFunc, locale Locale) (string, error) {
</code></pre>
<p>Converts an interface representing a Contentful RichText value (usually from a field getter) into HTML.
The function takes in three (optional) functions as parameters to resolve
hyperlink URLs, permalinks to entries and to derive IMG tag attributes for embedded image assets. The three functions
return a map of attributes for the HTML tag the RichTextToHtml function will emit (either an A or an IMG) and have the
following signature. Note that the ImageResolverFunc function must return a customHTML value that can be empty but if
set it will substitute the IMG tag with the returned HTML snippet. This allows you to emit custom mark-up for your
images, e.g. a PICTURE tag.</p>
<pre><code class="language-go">type LinkResolverFunc func(url string) (resolvedAttrs map[string]string, resolveError error)
type EntryLinkResolverFunc func(entryID string, locale Locale) (resolvedAttrs map[string]string, resolveError error)
type ImageResolverFunc func(assetID string, locale Locale) (attrs map[string]string, customHTML string, resolveError error)
type EmbeddedEntryResolverFunc func(entryID string, locale Locale) (html string, resolveError error)
</code></pre>
<p>All the three functions above can be passed as nil with different levels of graceful degrading.</p>
<h3 id="constants-and-global-variables">Constants and global variables</h3>
<p>Each generated content type library file exports a constant with the Contentful ID of the content type itself, for
example in <em>contentful_vo_lib_person.go</em>:</p>
<pre><code class="language-go">const ContentTypePerson = &quot;person&quot;
</code></pre>
<p>Constants are available for each locale supported by the space at the time of code generation, e.g.:</p>
<pre><code class="language-go">const SpaceLocaleGerman Locale = &quot;de&quot;
const SpaceLocaleFrench Locale = &quot;fr&quot;
const defaultLocale Locale = SpaceLocaleGerman
</code></pre>
<p>Four levels of logging are supported (even if only partially used at this time):</p>
<pre><code class="language-go">const (
LogDebug = 0
LogInfo = 1
LogWarn = 2
LogError = 3
)
</code></pre>
<p>A global variable named <em>SpaceContentTypeInfoMap</em> contains an ID-indexed map of all content types
with their names and descriptions</p></div><footer class="theme-doc-footer docusaurus-mt-lg"><div class="theme-doc-footer-edit-meta-row row"><div class="col"><a href="https://github.com/foomo/foomo-docs/tree/main/foomo/docs/projects/cms/gocontentful/99-api-reference.md" target="_blank" rel="noopener noreferrer" class="theme-edit-this-page"><svg fill="currentColor" height="20" width="20" viewBox="0 0 40 40" class="iconEdit_Z9Sw" aria-hidden="true"><g><path d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"></path></g></svg>Edit this page</a></div><div class="col lastUpdated_vwxv"></div></div></footer></article><nav class="pagination-nav docusaurus-mt-lg" aria-label="Docs pages"><a class="pagination-nav__link pagination-nav__link--prev" href="/docs/projects/cms/gocontentful/caching"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">Caching</div></a><a class="pagination-nav__link pagination-nav__link--next" href="/docs/projects/gograpple"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">gograpple</div></a></nav></div></div><div class="col col--3"><div class="tableOfContents_bqdL thin-scrollbar theme-doc-toc-desktop"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#client-and-cache" class="table-of-contents__link toc-highlight">Client and cache</a></li><li><a href="#content-functions-and-methods" class="table-of-contents__link toc-highlight">Content functions and methods</a></li><li><a href="#entry-field-getters-and-setters" class="table-of-contents__link toc-highlight">Entry field getters and setters</a></li><li><a href="#entry-write-ops--only-available-for-clientmodecma" class="table-of-contents__link toc-highlight">Entry write ops (only available for <em>ClientModeCMA</em>)</a><ul><li><a href="#asset-functions" class="table-of-contents__link toc-highlight">Asset functions</a></li><li><a href="#other-helper-functions-and-methods" class="table-of-contents__link toc-highlight">Other helper functions and methods</a></li><li><a href="#constants-and-global-variables" class="table-of-contents__link toc-highlight">Constants and global variables</a></li></ul></li></ul></div></div></div></div></main></div></div></div><footer class="footer"><div class="container container-fluid"><div class="row footer__links"><div class="col footer__col"><div class="footer__title">github</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://github.com/foomo" target="_blank" rel="noopener noreferrer" class="footer__link-item">https://github.com/foomo</a></li></ul></div><div class="col footer__col"><div class="footer__title">legal</div><ul class="footer__items clean-list"><li class="footer__item"><a class="footer__link-item" href="/etc/imprint">Imprint</a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">© 2024 bestbytes</div></div></div></footer></div>
</body>
</html>