Documentation
¶
Index ¶
- func DefaultOrganisationExtractor(_ context.Context) string
- type AuthenticationMethod
- type BoundaryType
- type ChangelogEntry
- type Client
- func (c *Client) Changelog(ctx context.Context, start int, limit int) (*Feed, error)
- func (c *Client) CheckExists(ctx context.Context, uuid string) (*ExistsResponse, error)
- func (c *Client) ConsistencyCheck(ctx context.Context, uuid string) (*ConsistencyStatus, error)
- func (c *Client) ContentTypes(ctx context.Context, req ContentTypesRequest) (*ContentTypesResponse, error)
- func (c *Client) Contentlog(ctx context.Context, event int) ([]ContentlogEvent, error)
- func (c *Client) Delete(ctx context.Context, uuid string, options *DeleteOptions) error
- func (c *Client) DeleteMetadataFile(ctx context.Context, req DeleteMetadataRequest) error
- func (c *Client) Eventlog(ctx context.Context, event int) ([]EventlogEvent, error)
- func (c *Client) Get(ctx context.Context, req GetRequest) (*GetResponse, error)
- func (c *Client) GetFile(ctx context.Context, uuid string, filename string, version int64) (*FileResponse, error)
- func (c *Client) GetMetadataFile(ctx context.Context, uuid string, version int) (*FileResponse, error)
- func (c *Client) GetObject(ctx context.Context, uuid string, version int64) (*ObjectResponse, error)
- func (c *Client) GetVersion(ctx context.Context) (string, error)
- func (c *Client) Head(ctx context.Context, uuid string) (int64, error)
- func (c *Client) Health(ctx context.Context, req HealthRequest) (Health, error)
- func (c *Client) ListFiles(ctx context.Context, uuid string, version int64) (*FileList, error)
- func (c *Client) Properties(ctx context.Context, uuid string, properties PropertyList) (*PropertyResult, error)
- func (c *Client) PropertiesVersion(ctx context.Context, uuid string, version int64, properties PropertyList) (*PropertyResult, error)
- func (c *Client) Purge(ctx context.Context, uuid string, options *PurgeOptions) error
- func (c *Client) ReplaceMetadataFile(ctx context.Context, req ReplaceMetadataRequest) error
- func (c *Client) Search(ctx context.Context, req SearchRequest) (*SearchResponse, error)
- func (c *Client) Suggest(ctx context.Context, req SuggestRequest) (*SuggestResponse, error)
- func (c *Client) Undelete(ctx context.Context, uuid string, options *UndeleteOptions) error
- func (c *Client) Upload(ctx context.Context, req UploadRequest) (*UploadResponse, error)
- type ConsistencyCheckResponse
- type ConsistencyStatus
- type ContentTypesRequest
- type ContentTypesResponse
- type ContentlogEvent
- type DateBoundary
- type DateRange
- type DeleteMetadataRequest
- type DeleteOptions
- type EventlogEvent
- type ExistsResponse
- type FacetField
- type FacetFields
- type Feed
- type File
- type FileList
- type FileResponse
- type FileSet
- type Frequency
- type GetRequest
- type GetResponse
- type Health
- type HealthRequest
- type Highlights
- type Hit
- type Hits
- type Metrics
- type ObjectFile
- type ObjectResponse
- type Options
- type Properties
- type Property
- type PropertyList
- func (pl *PropertyList) AddProperty(name string, nested ...string) *PropertyReference
- func (pl *PropertyList) Append(names ...string)
- func (pl *PropertyList) Ensure(names ...string) *PropertyReference
- func (pl *PropertyList) MarshalText() ([]byte, error)
- func (pl *PropertyList) UnmarshalText(text []byte) error
- type PropertyReference
- type PropertyResult
- type PropertyValue
- type PurgeOptions
- type ReplaceMetadataRequest
- type ResponseError
- type SearchFacets
- type SearchRequest
- type SearchResponse
- type SearchSort
- type Stats
- type SuggestField
- type SuggestIndexField
- type SuggestRequest
- type SuggestResponse
- type SuggestType
- type Term
- type UndeleteOptions
- type UploadRequest
- type UploadResponse
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AuthenticationMethod ¶
AuthenticationMethod is a function that adds authentication information to a request.
func BasicAuth ¶
func BasicAuth(username, password string) AuthenticationMethod
BasicAuth adds a basic auth authorisation header to the outgoing requests.
func BearerAuth ¶
func BearerAuth(token string) AuthenticationMethod
BasicAuth adds a bearer token authorisation header to the outgoing requests.
type BoundaryType ¶ added in v1.5.1
type BoundaryType int
const ( Inclusive BoundaryType = iota Exclusive )
func (BoundaryType) String ¶ added in v1.5.1
func (ts BoundaryType) String() string
type ChangelogEntry ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an Open Content client.
func (*Client) CheckExists ¶
CheckExists does a HEAD request against an object and returns information about the object.
func (*Client) ConsistencyCheck ¶
ConsistencyCheck performs a check against the database, storage, and index.
func (*Client) ContentTypes ¶
func (c *Client) ContentTypes(ctx context.Context, req ContentTypesRequest) (*ContentTypesResponse, error)
ContentTypes gets the schema (all content types and properties) from Open Content.
func (*Client) Contentlog ¶
func (*Client) DeleteMetadataFile ¶
func (c *Client) DeleteMetadataFile(ctx context.Context, req DeleteMetadataRequest) error
func (*Client) Get ¶
func (c *Client) Get(ctx context.Context, req GetRequest) (*GetResponse, error)
Get is used to retrieve properties for a given set of uuids. It requires a backend of OC 3.0+, because it uses a new endpoint `/get`. This endpoint uses what is called 'real-time get' in solr. This basically means retrieving document in a way that is cheaper than an ordinary search but you are still assured you get what is in the index.
func (*Client) GetMetadataFile ¶
func (*Client) Properties ¶
func (c *Client) Properties(ctx context.Context, uuid string, properties PropertyList) (*PropertyResult, error)
func (*Client) PropertiesVersion ¶
func (c *Client) PropertiesVersion( ctx context.Context, uuid string, version int64, properties PropertyList, ) (*PropertyResult, error)
func (*Client) ReplaceMetadataFile ¶
func (c *Client) ReplaceMetadataFile(ctx context.Context, req ReplaceMetadataRequest) error
func (*Client) Search ¶
func (c *Client) Search(ctx context.Context, req SearchRequest) (*SearchResponse, error)
Search performs a search against Open Content.
Example ¶
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/navigacontentlab/oc-client-go"
)
func main() {
client, err := oc.New(oc.Options{
BaseURL: os.Getenv("OC_BASEURL"),
Auth: oc.BasicAuth(
os.Getenv("OC_USERNAME"),
os.Getenv("OC_PASSWORD"),
),
})
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
searchReq := oc.SearchRequest{
Start: 0,
Limit: 15,
Properties: "uuid,Headline,created,updated",
ContentType: "Article",
Sort: []oc.SearchSort{
{IndexField: "updated"},
},
}
_, err = client.Search(ctx, searchReq)
if err != nil {
fmt.Println(err)
}
}
Output:
func (*Client) Suggest ¶
func (c *Client) Suggest(ctx context.Context, req SuggestRequest) (*SuggestResponse, error)
Suggest performs a suggest against Open Content.
func (*Client) Upload ¶
func (c *Client) Upload(ctx context.Context, req UploadRequest) (*UploadResponse, error)
Upload saves the fileset in the OC database.
Example ¶
Will not actually be run since there is no output because we cannot run this multiple times to the same oc.
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/google/uuid"
"github.com/navigacontentlab/oc-client-go"
)
func main() {
client, err := oc.New(oc.Options{
BaseURL: os.Getenv("OC_BASEURL"),
Auth: oc.BasicAuth(
os.Getenv("OC_USERNAME"),
os.Getenv("OC_PASSWORD"),
),
})
if err != nil {
log.Fatal(err)
}
reader, err := os.Open("sample.jpeg")
if err != nil {
log.Fatal(err)
}
metadataReader, err := os.Open("sample-image-metadata.xml")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
uploadReq := oc.UploadRequest{
UUID: uuid.New().String(),
Source: "mycustomuploader",
Files: oc.FileSet{
"file": oc.File{
Name: "sample.jpeg",
Reader: reader,
Mimetype: "image/jpeg",
},
"metadata": oc.File{
Name: "sample-image.metadata.xml",
Reader: metadataReader,
Mimetype: "application/vnd.iptc.g2.newsitem+xml.picture",
},
},
}
_, err = client.Upload(ctx, uploadReq)
if err != nil {
fmt.Println(err)
}
}
Output:
type ConsistencyCheckResponse ¶
type ConsistencyCheckResponse struct {
Database ConsistencyStatus `json:"database"`
Index ConsistencyStatus `json:"index"`
Storage ConsistencyStatus `json:"storage"`
}
type ConsistencyStatus ¶
type ContentTypesRequest ¶
type ContentTypesRequest struct {
Temporary bool
}
func (*ContentTypesRequest) QueryValues ¶
func (cr *ContentTypesRequest) QueryValues() (url.Values, error)
type ContentTypesResponse ¶
type ContentTypesResponse struct {
ContentTypes []struct {
Name string `json:"name"`
Properties []struct {
Name string `json:"name"`
Type string `json:"type"`
MultiValued bool `json:"multiValued"`
Searchable bool `json:"searchable"`
ReadOnly bool `json:"readOnly"`
Description string `json:"description"`
Suggest bool `json:"suggest"`
IndexFieldType string `json:"indexFieldType"`
} `json:"properties"`
} `json:"contentTypes"`
}
type ContentlogEvent ¶
type ContentlogEvent struct {
ID int `json:"id"`
UUID string `json:"uuid"`
EventType string `json:"eventType"`
Created time.Time `json:"created"`
Content struct {
UUID string `json:"uuid"`
Version int `json:"version"`
Created time.Time `json:"created"`
Source interface{} `json:"source"`
ContentType string `json:"contentType"`
Batch bool `json:"batch"`
} `json:"content"`
}
type DateBoundary ¶ added in v1.5.1
type DateBoundary struct {
Type BoundaryType
Date *time.Time
}
type DateRange ¶ added in v1.5.1
type DateRange struct {
Start DateBoundary
End DateBoundary
}
type DeleteMetadataRequest ¶
type DeleteMetadataRequest struct {
// UUID of the document to delete a metadata file for.
UUID string
// Filename of the metadata file to delete.
Filename string
// IfMatch only deletes the metadata file if the main object
// still has a matching ETag. Optional.
IfMatch string
// Unit is used when passing a X-Imid-Unit header to OC
Unit string
}
type DeleteOptions ¶
type EventlogEvent ¶
type EventlogEvent struct {
ID int `json:"id"`
UUID string `json:"uuid"`
EventType string `json:"eventType"`
Created time.Time `json:"created"`
Content struct {
UUID string `json:"uuid"`
Version int `json:"version"`
Created time.Time `json:"created"`
Source interface{} `json:"source"`
ContentType string `json:"contentType"`
Batch bool `json:"batch"`
} `json:"content"`
}
type ExistsResponse ¶
type FacetField ¶
type FacetFields ¶
type FacetFields struct {
Fields []FacetField `json:"fields"`
}
type FileList ¶
type FileList struct {
Version int64
Primary ObjectFile `json:"primary"`
Metadata []ObjectFile `json:"metadata"`
Preview ObjectFile `json:"preview"`
Thumb ObjectFile `json:"thumb"`
Created *time.Time `json:"created"`
Updated *time.Time `json:"updated"`
EventType string `json:"eventType"`
}
type FileResponse ¶
type FileResponse struct {
ETag string
ContentType string
Version int64
Body io.ReadCloser
}
type GetRequest ¶
GetRequest is the request payload for a call to client.Get().
type GetResponse ¶
type GetResponse SearchResponse
type Health ¶
type Health struct {
Indexer bool `json:"indexer"`
Solr bool `json:"index"`
Database bool `json:"database"`
Storage bool `json:"filesystem"`
FreeSystemDiskSpace int64 `json:"freeSystemDiskSpace"`
MaximumMemory int `json:"maximumMemory"`
CurrentMemory int `json:"currentMemory"`
ActiveConfiguration struct {
Checksum string `json:"checksum"`
LastModified time.Time `json:"lastModified"`
} `json:"activeConfiguration"`
TempConfiguration struct {
Checksum string `json:"checksum"`
LastModified time.Time `json:"lastModified"`
} `json:"tempConfiguration"`
}
Health is a OpenContent health check response.
type HealthRequest ¶
type HealthRequest struct {
// SkipIndexer tells OC to omit the indexer health check.
SkipIndexer bool
// SkipSolr tells OC to omit the Solr health check.
SkipSolr bool
// SkipStorage tells OC to omit the storage health check.
SkipStorage bool
}
HealthRequest is a request to the health check endpoint.
type Highlights ¶
type Hit ¶
type Hit struct {
ID string `json:"id"`
Version int `json:"version"`
Properties Properties `json:"properties"`
}
func (Hit) MarshalJSON ¶
func (*Hit) UnmarshalJSON ¶
type Metrics ¶
type Metrics struct {
StatusCodes *prometheus.CounterVec
Duration *prometheus.HistogramVec
OrgExtractor func(ctx context.Context) string
}
func NewMetrics ¶
func NewMetrics(reg prometheus.Registerer, orgExtractor func(ctx context.Context) string) (*Metrics, error)
type ObjectFile ¶
type ObjectResponse ¶
type ObjectResponse struct {
ETag string
ContentType string
Body io.ReadCloser
Version int64
}
type Options ¶
type Options struct {
BaseURL string
HTTPClient *http.Client
Auth AuthenticationMethod
Logger log.Logger
Metrics *Metrics
}
Options controls the behaviour of the Open Content client.
type Properties ¶
type Properties map[string][]interface{}
func (Properties) Relationships ¶
func (p Properties) Relationships(property string) ([]Properties, bool)
type Property ¶
type Property struct {
Name string `json:"name"`
Type string `json:"type"`
MultiValued bool `json:"multiValued"`
ReadOnly bool `json:"readOnly"`
Values []PropertyValue `json:"values"`
}
type PropertyList ¶
type PropertyList []*PropertyReference
func (*PropertyList) AddProperty ¶
func (pl *PropertyList) AddProperty(name string, nested ...string) *PropertyReference
func (*PropertyList) Append ¶
func (pl *PropertyList) Append(names ...string)
func (*PropertyList) Ensure ¶
func (pl *PropertyList) Ensure(names ...string) *PropertyReference
func (*PropertyList) MarshalText ¶
func (pl *PropertyList) MarshalText() ([]byte, error)
Example ¶
package main
import (
"fmt"
"log"
"github.com/navigacontentlab/oc-client-go"
)
func main() {
var list oc.PropertyList
list.Append("UUID", "Headline")
list.AddProperty("Image", "Width", "Height")
list.AddProperty("Author", "Title", "UUID", "URL")
list.Ensure("Author", "Avatar").AddNested("Width", "Height")
txt, err := list.MarshalText()
if err != nil {
log.Fatal(err)
}
fmt.Println(string(txt))
}
Output: UUID,Headline,Image[Width,Height],Author[Title,UUID,URL,Avatar[Width,Height]]
func (*PropertyList) UnmarshalText ¶
func (pl *PropertyList) UnmarshalText(text []byte) error
Example ¶
package main
import (
"fmt"
"log"
"github.com/navigacontentlab/oc-client-go"
)
func main() {
var list oc.PropertyList
err := list.UnmarshalText([]byte("UUID,Headline,Image[Width,Height],Author[Title,UUID,URL,Avatar[Width,Height]]"))
if err != nil {
log.Fatal(err)
}
txt, err := list.MarshalText()
if err != nil {
log.Fatal(err)
}
fmt.Println(string(txt))
}
Output: UUID,Headline,Image[Width,Height],Author[Title,UUID,URL,Avatar[Width,Height]]
type PropertyReference ¶
type PropertyReference struct {
Name string
Nested PropertyList
}
func NewPropertyReference ¶
func NewPropertyReference(name string, nested ...string) *PropertyReference
func (*PropertyReference) AddNested ¶
func (p *PropertyReference) AddNested(nested ...string)
type PropertyResult ¶
type PropertyValue ¶
type PropertyValue struct {
NestedProperty *PropertyResult
Value string
}
func (*PropertyValue) UnmarshalJSON ¶
func (pv *PropertyValue) UnmarshalJSON(data []byte) error
type PurgeOptions ¶
type PurgeOptions struct {
// IfMatch causes the object to only be purged if its ETag
// matches the provided value.
IfMatch string
}
type ReplaceMetadataRequest ¶
type ResponseError ¶
type ResponseError struct {
Response *http.Response
Body *bytes.Buffer
// contains filtered or unexported fields
}
ResponseError contains the response struct so that it can be inspected by the client.
func (*ResponseError) Error ¶
func (re *ResponseError) Error() string
Error formats an error message.
type SearchFacets ¶
type SearchRequest ¶
type SearchRequest struct {
IfNoneMatch string
Start int
Limit int
Property string
Properties string
Filters string
Query string
FilterQuery string
Sort []SearchSort
ContentType string // OC type, i.e. Article
Deleted bool
Facets SearchFacets
Highlight []string
Created DateRange
Updated DateRange
}
func (*SearchRequest) QueryValues ¶
func (sr *SearchRequest) QueryValues() (url.Values, error)
type SearchResponse ¶
type SearchResponse struct {
Hits Hits `json:"hits"`
Facet FacetFields `json:"facet"`
Stats Stats `json:"stats"`
Highlight map[string]Properties `json:"highlight"`
}
type SearchSort ¶
type SuggestField ¶
type SuggestIndexField ¶
type SuggestRequest ¶
type SuggestRequest struct {
IndexFields []SuggestIndexField
Limit int
Query string
IncompleteWordInText string
Type SuggestType
Timezone string
}
func (*SuggestRequest) QueryValues ¶
func (sr *SuggestRequest) QueryValues() (url.Values, error)
type SuggestResponse ¶
type SuggestResponse struct {
Fields []SuggestField `json:"facetFields"`
}
type SuggestType ¶
type SuggestType int
const ( Facet SuggestType = iota Ngram )
func (SuggestType) String ¶
func (s SuggestType) String() string
type UndeleteOptions ¶
type UndeleteOptions struct {
// Unit is passed to OC as a X-Imid-Unit HTTP header is passed
Unit string
}