Documentation
¶
Index ¶
- Constants
- Variables
- func NewRepository(store protosource.Store, serializer protosource.Serializer, ...) *protosource.Repository
- type Builder
- type Create
- func (m *Create) CommandName() string
- func (*Create) Descriptor() ([]byte, []int)deprecated
- func (m *Create) EmitEvents(aggregate protosource.Aggregate) []protosource.Event
- func (x *Create) GetActor() string
- func (x *Create) GetBody() string
- func (x *Create) GetId() string
- func (*Create) ProtoMessage()
- func (x *Create) ProtoReflect() protoreflect.Message
- func (m *Create) ProtoValidate() error
- func (x *Create) Reset()
- func (x *Create) String() string
- func (m *Create) ValidateVersion(version int64) error
- type Created
- func (*Created) Descriptor() ([]byte, []int)deprecated
- func (m *Created) EventName() string
- func (x *Created) GetActor() string
- func (x *Created) GetAt() int64
- func (x *Created) GetBody() string
- func (x *Created) GetId() string
- func (x *Created) GetVersion() int64
- func (*Created) ProtoMessage()
- func (x *Created) ProtoReflect() protoreflect.Message
- func (x *Created) Reset()
- func (x *Created) String() string
- type HTTPClient
- func (c *HTTPClient) Create(ctx context.Context, id string, body string) (*responsev1.CommandResponse, error)
- func (c *HTTPClient) Get(ctx context.Context, id string) (*Sample, error)
- func (c *HTTPClient) History(ctx context.Context, id string) (*historyv1.History, error)
- func (c *HTTPClient) Load(ctx context.Context, id string) (*Sample, error)
- func (c *HTTPClient) QueryByCreateBy(ctx context.Context, createBy string) ([]*Sample, error)
- func (c *HTTPClient) QueryByCreateByBetweenCreateAt(ctx context.Context, createBy string, createAtFrom int64, createAtTo int64) ([]*Sample, error)
- func (c *HTTPClient) QueryByCreateByWithCreateAt(ctx context.Context, createBy string, skOp string, createAt int64) ([]*Sample, error)
- func (c *HTTPClient) Update(ctx context.Context, id string, body string) (*responsev1.CommandResponse, error)
- type Handler
- func (h *Handler) HandleCreate(ctx context.Context, request protosource.Request) protosource.Response
- func (h *Handler) HandleGet(ctx context.Context, request protosource.Request) protosource.Response
- func (h *Handler) HandleGetMaterialized(ctx context.Context, request protosource.Request) protosource.Response
- func (h *Handler) HandleHistory(ctx context.Context, request protosource.Request) protosource.Response
- func (h *Handler) HandleQueryByCreateBy(ctx context.Context, request protosource.Request) protosource.Response
- func (h *Handler) HandleUpdate(ctx context.Context, request protosource.Request) protosource.Response
- func (h *Handler) RegisterRoutes(router *protosource.Router)
- type Repo
- type Sample
- func (*Sample) Descriptor() ([]byte, []int)deprecated
- func (m *Sample) GSI1PK() string
- func (m *Sample) GSI1SK() string
- func (m *Sample) GSI2PK() string
- func (m *Sample) GSI2SK() string
- func (m *Sample) GSI3PK() string
- func (m *Sample) GSI3SK() string
- func (m *Sample) GSI4PK() string
- func (m *Sample) GSI4SK() string
- func (m *Sample) GSI5PK() string
- func (m *Sample) GSI5SK() string
- func (m *Sample) GSI6PK() string
- func (m *Sample) GSI6SK() string
- func (m *Sample) GSI7PK() string
- func (m *Sample) GSI7SK() string
- func (m *Sample) GSI8PK() string
- func (m *Sample) GSI8SK() string
- func (m *Sample) GSI9PK() string
- func (m *Sample) GSI9SK() string
- func (m *Sample) GSI10PK() string
- func (m *Sample) GSI10SK() string
- func (m *Sample) GSI11PK() string
- func (m *Sample) GSI11SK() string
- func (m *Sample) GSI12PK() string
- func (m *Sample) GSI12SK() string
- func (m *Sample) GSI13PK() string
- func (m *Sample) GSI13SK() string
- func (m *Sample) GSI14PK() string
- func (m *Sample) GSI14SK() string
- func (m *Sample) GSI15PK() string
- func (m *Sample) GSI15SK() string
- func (m *Sample) GSI16PK() string
- func (m *Sample) GSI16SK() string
- func (m *Sample) GSI17PK() string
- func (m *Sample) GSI17SK() string
- func (m *Sample) GSI18PK() string
- func (m *Sample) GSI18SK() string
- func (m *Sample) GSI19PK() string
- func (m *Sample) GSI19SK() string
- func (m *Sample) GSI20PK() string
- func (m *Sample) GSI20SK() string
- func (x *Sample) GetBody() string
- func (x *Sample) GetCreateAt() int64
- func (x *Sample) GetCreateBy() string
- func (x *Sample) GetId() string
- func (x *Sample) GetModifyAt() int64
- func (x *Sample) GetModifyBy() string
- func (x *Sample) GetVersion() int64
- func (m *Sample) Hydrate(body []byte) error
- func (aggregate *Sample) On(event protosource.Event) error
- func (m *Sample) PK() string
- func (*Sample) ProtoMessage()
- func (x *Sample) ProtoReflect() protoreflect.Message
- func (x *Sample) Reset()
- func (aggregate *Sample) RestoreSnapshot(snapshot *Snapshot)
- func (m *Sample) SK() string
- func (aggregate *Sample) Snapshot(version int64) protosource.Event
- func (aggregate *Sample) SnapshotInterval() int32
- func (x *Sample) String() string
- type SampleClient
- func (c *SampleClient) AddSample(ctx context.Context, d *Sample, opts ...opaquedata.Option) error
- func (c *SampleClient) DeleteSample(ctx context.Context, id string) error
- func (c *SampleClient) GetSample(ctx context.Context, id string) (*Sample, error)
- func (c *SampleClient) SelectSampleByCreateBy(ctx context.Context, create_by string) ([]*Sample, error)
- func (c *SampleClient) SelectSampleByCreateByWithCreateAt(ctx context.Context, create_by string, op opaquedata.SortOperator, ...) ([]*Sample, error)
- func (c *SampleClient) UpdateSample(ctx context.Context, d *Sample, opts ...opaquedata.Option) error
- type SampleGSI1SK
- type SampleList
- type Snapshot
- func (*Snapshot) Descriptor() ([]byte, []int)deprecated
- func (m *Snapshot) EventName() string
- func (x *Snapshot) GetActor() string
- func (x *Snapshot) GetAt() int64
- func (x *Snapshot) GetId() string
- func (x *Snapshot) GetSnapshot() *Sample
- func (x *Snapshot) GetVersion() int64
- func (*Snapshot) ProtoMessage()
- func (x *Snapshot) ProtoReflect() protoreflect.Message
- func (x *Snapshot) Reset()
- func (x *Snapshot) String() string
- type Update
- func (m *Update) CommandName() string
- func (*Update) Descriptor() ([]byte, []int)deprecated
- func (m *Update) EmitEvents(aggregate protosource.Aggregate) []protosource.Event
- func (x *Update) GetActor() string
- func (x *Update) GetBody() string
- func (x *Update) GetId() string
- func (*Update) ProtoMessage()
- func (x *Update) ProtoReflect() protoreflect.Message
- func (m *Update) ProtoValidate() error
- func (x *Update) Reset()
- func (x *Update) String() string
- func (m *Update) ValidateVersion(version int64) error
- type Updated
- func (*Updated) Descriptor() ([]byte, []int)deprecated
- func (m *Updated) EventName() string
- func (x *Updated) GetActor() string
- func (x *Updated) GetAt() int64
- func (x *Updated) GetBody() string
- func (x *Updated) GetId() string
- func (x *Updated) GetVersion() int64
- func (*Updated) ProtoMessage()
- func (x *Updated) ProtoReflect() protoreflect.Message
- func (x *Updated) Reset()
- func (x *Updated) String() string
Constants ¶
const SnapshotEveryNEvents int32 = 50
SnapshotEveryNEvents is the snapshot interval from the proto annotation.
Variables ¶
var File_example_app_sample_v1_sample_v1_proto protoreflect.FileDescriptor
Functions ¶
func NewRepository ¶
func NewRepository(store protosource.Store, serializer protosource.Serializer, opts ...protosource.Option) *protosource.Repository
NewRepository creates a new protosource.Repository for the Sample aggregate.
Types ¶
type Builder ¶
type Builder struct {
Events []protosource.Event
// contains filtered or unexported fields
}
func NewBuilder ¶
type Create ¶
type Create struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Actor string `protobuf:"bytes,2,opt,name=actor,proto3" json:"actor,omitempty"`
Body string `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"`
// contains filtered or unexported fields
}
Create is the command that is used to create a sample.
func (*Create) CommandName ¶
func (*Create) Descriptor
deprecated
func (*Create) EmitEvents ¶
func (m *Create) EmitEvents(aggregate protosource.Aggregate) []protosource.Event
func (*Create) ProtoMessage ¶
func (*Create) ProtoMessage()
func (*Create) ProtoReflect ¶
func (x *Create) ProtoReflect() protoreflect.Message
func (*Create) ProtoValidate ¶
func (*Create) ValidateVersion ¶
type Created ¶
type Created struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Version int64 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"`
At int64 `protobuf:"varint,3,opt,name=at,proto3" json:"at,omitempty"`
Actor string `protobuf:"bytes,4,opt,name=actor,proto3" json:"actor,omitempty"`
Body string `protobuf:"bytes,5,opt,name=body,proto3" json:"body,omitempty"`
// contains filtered or unexported fields
}
Created is the event emitted when we create a sample.
func (*Created) Descriptor
deprecated
func (*Created) GetVersion ¶
func (*Created) ProtoMessage ¶
func (*Created) ProtoMessage()
func (*Created) ProtoReflect ¶
func (x *Created) ProtoReflect() protoreflect.Message
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient is a typed HTTP client for the Sample aggregate.
func NewHTTPClient ¶
func NewHTTPClient(c httpclient.Doer) *HTTPClient
NewHTTPClient creates a new Sample HTTP client. Accepts httpclient.Doer for testability — use *httpclient.Client in production and a mock in tests.
func (*HTTPClient) Create ¶
func (c *HTTPClient) Create(ctx context.Context, id string, body string) (*responsev1.CommandResponse, error)
Create sends the Create command.
func (*HTTPClient) Load ¶
Load retrieves the current state of the Sample aggregate via event replay.
func (*HTTPClient) QueryByCreateBy ¶
QueryByCreateBy queries by create_by via GSI1.
func (*HTTPClient) QueryByCreateByBetweenCreateAt ¶
func (c *HTTPClient) QueryByCreateByBetweenCreateAt(ctx context.Context, createBy string, createAtFrom int64, createAtTo int64) ([]*Sample, error)
QueryByCreateByBetweenCreateAt queries with a between sort key condition (inclusive range).
func (*HTTPClient) QueryByCreateByWithCreateAt ¶
func (c *HTTPClient) QueryByCreateByWithCreateAt(ctx context.Context, createBy string, skOp string, createAt int64) ([]*Sample, error)
QueryByCreateByWithCreateAt queries with a sort key condition (eq, lt, le, gt, ge, begins_with). For between queries, use QueryByCreateByBetweenCreateAt instead.
func (*HTTPClient) Update ¶
func (c *HTTPClient) Update(ctx context.Context, id string, body string) (*responsev1.CommandResponse, error)
Update sends the Update command.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler provides request handler functions for the Sample aggregate.
func NewHandler ¶
func NewHandler(repo Repo, client *SampleClient, authorizer authz.Authorizer) *Handler
NewHandler creates a new Handler instance with the given repository, client, and authorizer. Every generated command handler calls authorizer.Authorize with the canonical function name "example.app.sample.v1.{CommandMessageName}" before running the command pipeline. Applications that do not enforce authorization at this layer should wire in allowall.Authorizer.
authorizer is required; passing nil panics immediately with a descriptive message rather than deferring to an opaque nil-pointer dereference on the first request.
func (*Handler) HandleCreate ¶
func (h *Handler) HandleCreate(ctx context.Context, request protosource.Request) protosource.Response
HandleCreate processes a Create command.
func (*Handler) HandleGet ¶
func (h *Handler) HandleGet(ctx context.Context, request protosource.Request) protosource.Response
HandleGet retrieves the current state of a Sample aggregate.
func (*Handler) HandleGetMaterialized ¶
func (h *Handler) HandleGetMaterialized(ctx context.Context, request protosource.Request) protosource.Response
HandleGetMaterialized retrieves the Sample aggregate from the materialized store.
func (*Handler) HandleHistory ¶
func (h *Handler) HandleHistory(ctx context.Context, request protosource.Request) protosource.Response
HandleHistory retrieves the full event history for a Sample aggregate.
func (*Handler) HandleQueryByCreateBy ¶
func (h *Handler) HandleQueryByCreateBy(ctx context.Context, request protosource.Request) protosource.Response
HandleQueryByCreateBy queries GSI1 by partition key with optional sort key condition.
func (*Handler) HandleUpdate ¶
func (h *Handler) HandleUpdate(ctx context.Context, request protosource.Request) protosource.Response
HandleUpdate processes a Update command.
func (*Handler) RegisterRoutes ¶
func (h *Handler) RegisterRoutes(router *protosource.Router)
RegisterRoutes registers all handler routes on the given router.
type Repo ¶
type Repo interface {
protosource.Repo
}
Repo is a package-specific interface for dependency injection. It embeds protosource.Repo so that *protosource.Repository satisfies it, while giving each aggregate package a distinct type for Wire.
type Sample ¶
type Sample struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Version int64 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"`
CreateAt int64 `protobuf:"varint,3,opt,name=create_at,json=createAt,proto3" json:"create_at,omitempty"`
CreateBy string `protobuf:"bytes,4,opt,name=create_by,json=createBy,proto3" json:"create_by,omitempty"`
ModifyAt int64 `protobuf:"varint,5,opt,name=modify_at,json=modifyAt,proto3" json:"modify_at,omitempty"`
ModifyBy string `protobuf:"bytes,6,opt,name=modify_by,json=modifyBy,proto3" json:"modify_by,omitempty"`
Body string `protobuf:"bytes,7,opt,name=body,proto3" json:"body,omitempty"`
// contains filtered or unexported fields
}
Sample is the aggregate.
It must be defined first in the proto, its name must match the first part of the package.
func (*Sample) Descriptor
deprecated
func (*Sample) GetCreateAt ¶
func (*Sample) GetCreateBy ¶
func (*Sample) GetModifyAt ¶
func (*Sample) GetModifyBy ¶
func (*Sample) GetVersion ¶
func (*Sample) On ¶
func (aggregate *Sample) On(event protosource.Event) error
On applies an event to the aggregate, rebuilding its state. This method is called during Repository.Load to reconstruct from stored events, and during test scenarios. Events represent facts — never reject based on business rules.
func (*Sample) ProtoMessage ¶
func (*Sample) ProtoMessage()
func (*Sample) ProtoReflect ¶
func (x *Sample) ProtoReflect() protoreflect.Message
func (*Sample) RestoreSnapshot ¶
func (*Sample) SnapshotInterval ¶
type SampleClient ¶
type SampleClient struct {
// contains filtered or unexported fields
}
func NewSampleClient ¶
func NewSampleClient(store opaquedata.OpaqueStore) *SampleClient
func (*SampleClient) AddSample ¶
func (c *SampleClient) AddSample(ctx context.Context, d *Sample, opts ...opaquedata.Option) error
func (*SampleClient) DeleteSample ¶
func (c *SampleClient) DeleteSample(ctx context.Context, id string) error
func (*SampleClient) SelectSampleByCreateBy ¶
func (c *SampleClient) SelectSampleByCreateBy(ctx context.Context, create_by string) ([]*Sample, error)
SelectSampleByCreateBy queries GSI1 by partition key.
func (*SampleClient) SelectSampleByCreateByWithCreateAt ¶
func (c *SampleClient) SelectSampleByCreateByWithCreateAt(ctx context.Context, create_by string, op opaquedata.SortOperator, vals ...SampleGSI1SK) ([]*Sample, error)
SelectSampleByCreateByWithCreateAt queries GSI1 with a sort key condition.
func (*SampleClient) UpdateSample ¶
func (c *SampleClient) UpdateSample(ctx context.Context, d *Sample, opts ...opaquedata.Option) error
type SampleGSI1SK ¶
type SampleGSI1SK struct {
CreateAt int64
}
func (SampleGSI1SK) String ¶
func (v SampleGSI1SK) String() string
type SampleList ¶
type SampleList struct {
Items []*Sample `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"`
// contains filtered or unexported fields
}
func (*SampleList) Descriptor
deprecated
func (*SampleList) Descriptor() ([]byte, []int)
Deprecated: Use SampleList.ProtoReflect.Descriptor instead.
func (*SampleList) GetItems ¶
func (x *SampleList) GetItems() []*Sample
func (*SampleList) ProtoMessage ¶
func (*SampleList) ProtoMessage()
func (*SampleList) ProtoReflect ¶
func (x *SampleList) ProtoReflect() protoreflect.Message
func (*SampleList) Reset ¶
func (x *SampleList) Reset()
func (*SampleList) String ¶
func (x *SampleList) String() string
type Snapshot ¶
type Snapshot struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Version int64 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"`
At int64 `protobuf:"varint,3,opt,name=at,proto3" json:"at,omitempty"`
Actor string `protobuf:"bytes,4,opt,name=actor,proto3" json:"actor,omitempty"`
Snapshot *Sample `protobuf:"bytes,5,opt,name=snapshot,proto3" json:"snapshot,omitempty"`
// contains filtered or unexported fields
}
PUT THE SNAPSHOT (IF USING ONE) in this section What is a snapshot? A snapshot is a recorded version of the aggregate at a point in time. Its main purpose is cost control, but it also helps with archival and record retention. Snapshots are NOT required, but they are EXTREMELY helpful for the operational folks managing the data.
Snapshots facilitate rules such as:
- After every snapshot, delete all older versions.
- After every snapshot, set a TTL on older versions of 30 days so that they delete themselves
- After every snapshot
- Extract, serialize, and write the older records to durable storage
- Delete the older records.
The format of the snapshot must be EXACTLY as detailed below. The only change is the name of the aggregate.
func (*Snapshot) Descriptor
deprecated
func (*Snapshot) GetSnapshot ¶
func (*Snapshot) GetVersion ¶
func (*Snapshot) ProtoMessage ¶
func (*Snapshot) ProtoMessage()
func (*Snapshot) ProtoReflect ¶
func (x *Snapshot) ProtoReflect() protoreflect.Message
type Update ¶
type Update struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Actor string `protobuf:"bytes,2,opt,name=actor,proto3" json:"actor,omitempty"`
Body string `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"`
// contains filtered or unexported fields
}
Update is the command that is used to update a sample.
func (*Update) CommandName ¶
func (*Update) Descriptor
deprecated
func (*Update) EmitEvents ¶
func (m *Update) EmitEvents(aggregate protosource.Aggregate) []protosource.Event
func (*Update) ProtoMessage ¶
func (*Update) ProtoMessage()
func (*Update) ProtoReflect ¶
func (x *Update) ProtoReflect() protoreflect.Message
func (*Update) ProtoValidate ¶
func (*Update) ValidateVersion ¶
type Updated ¶
type Updated struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Version int64 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"`
At int64 `protobuf:"varint,3,opt,name=at,proto3" json:"at,omitempty"`
Actor string `protobuf:"bytes,4,opt,name=actor,proto3" json:"actor,omitempty"`
Body string `protobuf:"bytes,5,opt,name=body,proto3" json:"body,omitempty"`
// contains filtered or unexported fields
}
Updated is the event emitted when we update a sample.
func (*Updated) Descriptor
deprecated
func (*Updated) GetVersion ¶
func (*Updated) ProtoMessage ¶
func (*Updated) ProtoMessage()
func (*Updated) ProtoReflect ¶
func (x *Updated) ProtoReflect() protoreflect.Message
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Code generated by protoc-gen-protosource.
|
Code generated by protoc-gen-protosource. |