Skip to content

influx6/dime

Repository files navigation

Dime

Dime provides streaming structures for native go types using channels, which allows services, message queues and other systems to be exposed to match such interfaces easily.

Dime is inspired from the work done on Vice by Mat Ryer.

Dime uses code generation to create all the types interface and adapters using the Moz.

Custom Interface And Adapters

Dime provides easy means of creating new service types and adapters by simply declaring specific annotations in the package comments which indicate the template and details necessary to generate those artifacts.

For example, within the dime.go package comments, you would see comment lines like below:

// @templaterTypesFor(id => Service, filename => bool_service.go, ServiceName => BoolService, Type => bool)
// @templaterTypesFor(id => Service, filename => bool_slice_service.go, ServiceName => BoolSliceService, Type => []bool)

These commentary above is responsible for the generation of the BoolService and BoolSliceService.

Where each @templateTypesFor dictate the giving details needed to use the default dime template to create new code specific for different internal go types. These easily can be customized to create new interfaces and adapters for specific custom structs as exposed services.

To learn more about annotation code generation, see Moz.

A Dime Adapter

An adapter in Dime, is simply any function that can take a channel of a type and return a channel of another type, where by it does certain transformation within to produce such a conversion. As an example the BoolService adapters.

// BoolFromByteAdapter defines a function that that will take a channel of bytes and return a channel of bool.
type BoolFromByteAdapterWithContext func(CancelContext, chan []byte) chan bool

// BoolToByteAdapter defines a function that that will take a channel of bytes and return a channel of bool.
type BoolToByteAdapter func(CancelContext, chan bool) chan []byte

A Dime Service

A service in Dime, is simply any implementation that match a giving interface type, such has the ByteService.

Dime contains auto-generated code for all go's base types supported for usage outside of the package in Services directory.

type MonoBoolService interface {
	ReadErrors() <-chan error
	Read() (<-chan bool, error)
	Write(<-chan bool) error
	Done() chan struct{}
	Stop() error
}
type BoolService interface {
	ReadErrors() <-chan error
	Read(string) (<-chan bool, error)
	Write(string, <-chan bool) error
	Done() chan struct{}
	Stop() error
}

Releases

No releases published

Packages

No packages published

Languages