Documentation
¶
Index ¶
- Variables
- func SetSearchIndex(index SearchIndex)
- type AccessTokens
- func (at *AccessTokens) AddToken(name string, permissions bit.Mask) string
- func (at *AccessTokens) ClearTokens()
- func (at *AccessTokens) CompareToken(tok1, tok2 *accesstoken.AccessToken) error
- func (at *AccessTokens) GetToken(accessToken string) (*accesstoken.AccessToken, error)
- func (at *AccessTokens) GetTokenByName(name string) (*accesstoken.AccessToken, error)
- func (at *AccessTokens) GetWithAccessToken(accessToken string) (*accesstoken.AccessToken, error)
- func (at *AccessTokens) Init(e Entity)
- func (at *AccessTokens) MustGetTokenByName(name string) *accesstoken.AccessToken
- func (at *AccessTokens) RemoveToken(name string)
- type AfterCreate
- type AfterDelete
- type AfterUpdate
- type BeforeCreate
- type BeforeDelete
- type BeforeUpdate
- type Defaults
- type Document
- type DocumentSaveLoad
- type Entity
- type ErrFacetMismatch
- type ErrFieldMismatch
- type ErrorMessage
- type JsonResponse
- type Kind
- type Model
- func (m *Model) Clone() Entity
- func (m *Model) CloneFromJSON() Entity
- func (m *Model) Context() context.Context
- func (m *Model) Create() error
- func (m *Model) Created() bool
- func (m *Model) Datastore() *datastore.Datastore
- func (m *Model) Delete() error
- func (m Model) DeleteDocument() error
- func (m *Model) Exists() (bool, error)
- func (m *Model) Get(key datastore.Key) error
- func (m *Model) GetById(id string) error
- func (m *Model) GetOrCreate(filterStr string, value interface{}) error
- func (m *Model) GetOrUpdate(filterStr string, value interface{}) error
- func (m *Model) Id() string
- func (m *Model) IdExists(id string) (datastore.Key, bool, error)
- func (m *Model) Init(db *datastore.Datastore, entity Kind)
- func (m *Model) JSON() []byte
- func (m *Model) JSONString() string
- func (m *Model) Key() (key datastore.Key)
- func (m *Model) KeyExists(key datastore.Key) (bool, error)
- func (m Model) Kind() string
- func (m *Model) Loaded() bool
- func (m *Model) MustCreate()
- func (m *Model) MustDelete()
- func (m *Model) MustGet(key datastore.Key)
- func (m *Model) MustGetById(id string)
- func (m *Model) MustPut()
- func (m *Model) MustSetKey(key interface{})
- func (m *Model) MustUpdate()
- func (m *Model) Namespace() string
- func (m *Model) NewKey() datastore.Key
- func (m *Model) Put() error
- func (m Model) PutDocument() error
- func (m *Model) Query() *ModelQuery
- func (m *Model) RunInTransaction(fn func() error, opts *datastore.TransactionOptions) error
- func (m *Model) SetContext(ctx context.Context)
- func (m *Model) SetEntity(entity interface{})
- func (m *Model) SetKey(key interface{}) (err error)
- func (m *Model) SetNamespace(namespace string)
- func (m *Model) Slice() interface{}
- func (m *Model) Update() error
- func (m *Model) Zero() Entity
- type ModelQuery
- func (q *ModelQuery) All() datastore.Query
- func (q *ModelQuery) Ancestor(key datastore.Key) *ModelQuery
- func (q *ModelQuery) ById(id string) (bool, error)
- func (q *ModelQuery) ByKey(key interface{}) (bool, error)
- func (q *ModelQuery) Filter(filterStr string, value interface{}) *ModelQuery
- func (q *ModelQuery) Get() (bool, error)
- func (q *ModelQuery) GetKey() (bool, error)
- func (q *ModelQuery) IdExists(id string) (datastore.Key, bool, error)
- func (q *ModelQuery) KeyExists(key datastore.Key) (bool, error)
- func (q *ModelQuery) Limit(limit int) *ModelQuery
- func (q *ModelQuery) MustGet()
- func (q *ModelQuery) MustGetKey()
- func (q *ModelQuery) Offset(offset int) *ModelQuery
- func (q *ModelQuery) Order(order string) *ModelQuery
- type Salesforce
- func (so *Salesforce) ExternalId() string
- func (so *Salesforce) LastSync() time.Time
- func (so *Salesforce) SalesforceId() string
- func (so *Salesforce) SalesforceId2() string
- func (so *Salesforce) SetExternalId(id string)
- func (so *Salesforce) SetLastSync()
- func (so *Salesforce) SetSalesforceId(id string)
- func (so *Salesforce) SetSalesforceId2(id string)
- type SearchDocumentMetadata
- type SearchFacet
- type SearchField
- type SearchIndex
- type Searchable
Constants ¶
This section is empty.
Variables ¶
var DefaultIndex = "everything"
var ErrorExpiredToken = errors.New("This token is expired")
Error for expired jti's
var TokenNotFound = errors.New("Token not found")
var TokenNotFoundByName = errors.New("Token not found by name")
Functions ¶
func SetSearchIndex ¶
func SetSearchIndex(index SearchIndex)
SetSearchIndex sets the search index implementation to use
Types ¶
type AccessTokens ¶
type AccessTokens struct {
// Entity is a struct with a Entity mixin
Entity Entity `json:"-" datastore:"-"`
// JWT secret (persisted for token verification)
SecretKey []byte `json:"secretKey,omitempty"`
// UseTokenId as JWT "jti" param, randomly generate upon generating a new key to expire all existing keys
Tokens []accesstoken.AccessToken `json:"tokens,omitempty"`
}
AccessTokens is a mixin for securing objects with an AccessTokens
func (*AccessTokens) AddToken ¶
func (at *AccessTokens) AddToken(name string, permissions bit.Mask) string
func (*AccessTokens) ClearTokens ¶
func (at *AccessTokens) ClearTokens()
func (*AccessTokens) CompareToken ¶
func (at *AccessTokens) CompareToken(tok1, tok2 *accesstoken.AccessToken) error
func (*AccessTokens) GetToken ¶
func (at *AccessTokens) GetToken(accessToken string) (*accesstoken.AccessToken, error)
func (*AccessTokens) GetTokenByName ¶
func (at *AccessTokens) GetTokenByName(name string) (*accesstoken.AccessToken, error)
func (*AccessTokens) GetWithAccessToken ¶
func (at *AccessTokens) GetWithAccessToken(accessToken string) (*accesstoken.AccessToken, error)
func (*AccessTokens) Init ¶
func (at *AccessTokens) Init(e Entity)
func (*AccessTokens) MustGetTokenByName ¶
func (at *AccessTokens) MustGetTokenByName(name string) *accesstoken.AccessToken
func (*AccessTokens) RemoveToken ¶
func (at *AccessTokens) RemoveToken(name string)
type AfterCreate ¶
type AfterCreate interface {
AfterCreate() error
}
type AfterDelete ¶
type AfterDelete interface {
AfterDelete() error
}
type AfterUpdate ¶
type BeforeCreate ¶
type BeforeCreate interface {
BeforeCreate() error
}
type BeforeDelete ¶
type BeforeDelete interface {
BeforeDelete() error
}
type BeforeUpdate ¶
These last two interfaces are largely ignored -- we use helper below to have nicely typed update hooks in models.
type DocumentSaveLoad ¶
type DocumentSaveLoad struct {
// Dummy field for gob, see: https://github.com/golang/go/issues/5819
Dummy string `json:"-" datastore:"-"`
// contains filtered or unexported fields
}
func (*DocumentSaveLoad) GetDocument ¶
func (s *DocumentSaveLoad) GetDocument() reflect.Value
func (*DocumentSaveLoad) Load ¶
func (s *DocumentSaveLoad) Load(fields []SearchField, meta *SearchDocumentMetadata) error
func (DocumentSaveLoad) Save ¶
func (s DocumentSaveLoad) Save() ([]SearchField, *SearchDocumentMetadata, error)
func (*DocumentSaveLoad) SetDocument ¶
func (s *DocumentSaveLoad) SetDocument(doc interface{})
type Entity ¶
type Entity interface {
// TODO: Should not be embedded in Entity I don't think
Kind
// By convention where model is wired to entity
Init(db *datastore.Datastore)
// Get, Set context/namespace
Context() context.Context
SetContext(ctx context.Context)
SetNamespace(namespace string)
Namespace() string
// Get, Set keys
Key() (key datastore.Key)
SetKey(key interface{}) error
NewKey() datastore.Key
Id() string
// Various existential helpers
Exists() (bool, error)
IdExists(id string) (datastore.Key, bool, error)
KeyExists(key datastore.Key) (bool, error)
// Get, Put, Delete + Create, Update
Get(key datastore.Key) error
GetById(id string) error
Put() error
Create() error
Update() error
Delete() error
// Must variants
MustSetKey(key interface{})
MustCreate()
MustDelete()
MustGet(key datastore.Key)
MustGetById(id string)
MustPut()
MustUpdate()
// Document
PutDocument() error
DeleteDocument() error
// Get or Create, Update helpers
GetOrCreate(filterStr string, value interface{}) error
GetOrUpdate(filterStr string, value interface{}) error
// Datastore
Datastore() *datastore.Datastore
RunInTransaction(fn func() error, opts *datastore.TransactionOptions) error
// Query
Query() *ModelQuery
// Various helpers
Zero() Entity
Clone() Entity
CloneFromJSON() Entity
Slice() interface{}
JSON() []byte
JSONString() string
}
A specific datastore entity, with methods inherited from this mixin
type ErrFacetMismatch ¶
ErrFacetMismatch is returned when a facet is to be loaded into a different type than the one it was stored from, or when a field is missing or unexported in the destination struct. StructType is the type of the struct pointed to by the destination argument passed to Iterator.Next.
func (*ErrFacetMismatch) Error ¶
func (e *ErrFacetMismatch) Error() string
type ErrFieldMismatch ¶
ErrFieldMismatch is returned when a field is to be loaded into a different than the one it was stored from, or when a field is missing or unexported in the destination struct.
func (*ErrFieldMismatch) Error ¶
func (e *ErrFieldMismatch) Error() string
type ErrorMessage ¶
type JsonResponse ¶
type JsonResponse struct {
Meta struct {
RetrievedAt string
ExecutionTime int64
CallsUsed int64
}
Errors []ErrorMessage
}
type Kind ¶
type Kind interface {
Kind() string
}
A datastore kind that is compatible with the Model mixin
type Model ¶
type Model struct {
Db *datastore.Datastore `json:"-" datastore:"-"`
Entity Kind `json:"-" datastore:"-"`
Parent datastore.Key `json:"-" datastore:"-"`
Mock bool `json:"-" datastore:"-"`
// Set by our mixin
Id_ string `json:"id,omitempty"`
Loaded_ bool `json:"-" datastore:"-"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
Deleted bool `json:"deleted,omitempty"`
// Flag used to specify that we're using a string key for this kind
UseStringKey bool `json:"-" datastore:"-"`
// contains filtered or unexported fields
}
Model is a mixin which adds Datastore/Validation/Serialization methods to any Kind that it has been embedded in.
func (*Model) CloneFromJSON ¶
Create a clone of currenty entity using only JSON-serializable data
func (Model) DeleteDocument ¶
func (*Model) GetById ¶
Helper that will retrieve entity by id (which may be an encoded key/slug/sku)
func (*Model) GetOrCreate ¶
Get entity from datastore or create new one
func (*Model) GetOrUpdate ¶
Get entity from datastore or create new one
func (*Model) JSONString ¶
func (Model) PutDocument ¶
func (*Model) RunInTransaction ¶
func (m *Model) RunInTransaction(fn func() error, opts *datastore.TransactionOptions) error
Run in transaction using model's current context
func (*Model) SetEntity ¶
func (m *Model) SetEntity(entity interface{})
Set entity on mixin so it can be referenced later
func (*Model) SetNamespace ¶
Set context.Context namespace
type ModelQuery ¶
type ModelQuery struct {
// contains filtered or unexported fields
}
This is a simple Query helper for individual models. Allows you to query for a single entity or key only as a convenience on an individual model.
func (*ModelQuery) All ¶
func (q *ModelQuery) All() datastore.Query
func (*ModelQuery) Ancestor ¶
func (q *ModelQuery) Ancestor(key datastore.Key) *ModelQuery
func (*ModelQuery) Filter ¶
func (q *ModelQuery) Filter(filterStr string, value interface{}) *ModelQuery
func (*ModelQuery) KeyExists ¶
func (q *ModelQuery) KeyExists(key datastore.Key) (bool, error)
Check if key exists
func (*ModelQuery) Limit ¶
func (q *ModelQuery) Limit(limit int) *ModelQuery
func (*ModelQuery) MustGet ¶
func (q *ModelQuery) MustGet()
func (*ModelQuery) MustGetKey ¶
func (q *ModelQuery) MustGetKey()
func (*ModelQuery) Offset ¶
func (q *ModelQuery) Offset(offset int) *ModelQuery
func (*ModelQuery) Order ¶
func (q *ModelQuery) Order(order string) *ModelQuery
type Salesforce ¶
type Salesforce struct {
PrimarySalesforceId_ string `json:"-"`
SecondarySalesforceId_ string `json:"-"`
ExternalId_ string `json:"-"`
LastSync_ time.Time `json:"-"`
}
func (*Salesforce) ExternalId ¶
func (so *Salesforce) ExternalId() string
func (*Salesforce) LastSync ¶
func (so *Salesforce) LastSync() time.Time
func (*Salesforce) SalesforceId ¶
func (so *Salesforce) SalesforceId() string
func (*Salesforce) SalesforceId2 ¶
func (so *Salesforce) SalesforceId2() string
func (*Salesforce) SetExternalId ¶
func (so *Salesforce) SetExternalId(id string)
func (*Salesforce) SetLastSync ¶
func (so *Salesforce) SetLastSync()
func (*Salesforce) SetSalesforceId ¶
func (so *Salesforce) SetSalesforceId(id string)
func (*Salesforce) SetSalesforceId2 ¶
func (so *Salesforce) SetSalesforceId2(id string)
type SearchDocumentMetadata ¶
type SearchDocumentMetadata struct {
Facets []SearchFacet
}
SearchDocumentMetadata holds metadata for a search document
type SearchFacet ¶
type SearchFacet struct {
Name string
Value interface{}
}
SearchFacet represents a facet in a search document
type SearchField ¶
type SearchField struct {
Name string
Value interface{}
}
SearchField represents a field in a search document
type SearchIndex ¶
type SearchIndex interface {
Put(ctx context.Context, id string, doc interface{}) error
Delete(ctx context.Context, id string) error
}
SearchIndex provides an interface for search operations This allows pluggable search backends (Elasticsearch, Meilisearch, etc.)
func GetSearchIndex ¶
func GetSearchIndex() SearchIndex
GetSearchIndex returns the current search index, or nil if not set
type Searchable ¶
type Searchable interface {
Document() Document
}
Searchable is implemented by models that can be indexed for search