contract

package
v0.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2021 License: MIT Imports: 9 Imported by: 22

Documentation

Overview

Package contract defines a set of common interfaces for all packages in this repository.

Note the purpose of this packages is to document what contract the libraries for package core should agree upon.

In general, use a centralized package for contracts is an anti-pattern in go as it prevents progressive upgrade. It is recommended to redeclare them in each individual package, unless there is a reason not to, eg. import cycle.

Package contract should be considered a closed set. Adding new interfaces to this package is strongly discouraged.

Index

Constants

View Source
const (
	IpKey         contextKey = "ip"         // IP address
	TenantKey     contextKey = "tenant"     // Tenant
	TransportKey  contextKey = "transport"  // Transport, such as HTTP
	RequestUrlKey contextKey = "requestUrl" // Request url
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppName

type AppName interface {
	String() string
}

AppName is the name of the application.

type Codec added in v0.4.0

type Codec interface {
	Unmarshal(data []byte, value interface{}) error
	Marshal(value interface{}) ([]byte, error)
}

Codec is an interface for serialization and deserialization.

type ConfigAccessor

type ConfigAccessor interface {
	String(string) string
	Int(string) int
	Strings(string) []string
	Bool(string) bool
	Get(string) interface{}
	Float64(string) float64
	Unmarshal(path string, o interface{}) error
}

ConfigAccessor models a the basic configuration. If the configuration is hot reloaded, ConfigAccessor should fetch the latest info.

type ConfigRouter

type ConfigRouter interface {
	Route(path string) ConfigAccessor
}

ConfigRouter enables modular configuration by giving every piece of configuration a path.

type ConfigWatcher

type ConfigWatcher interface {
	Watch(ctx context.Context, reload func() error) error
}

ConfigWatcher is an interface for hot-reload provider.

type Container

type Container interface {
	ApplyRouter(router *mux.Router)
	ApplyGRPCServer(server *grpc.Server)
	ApplyCron(crontab *cron.Cron)
	ApplyRunGroup(g *run.Group)
	ApplyRootCommand(command *cobra.Command)
	Shutdown()
	Modules() ifilter.Collection
	AddModule(module interface{})
}

Container holds modules.

type Dispatcher

type Dispatcher interface {
	Dispatch(ctx context.Context, event Event) error
	Subscribe(listener Listener)
}

Dispatcher is the event registry that is able to send event to each listener.

type Env

type Env interface {
	IsLocal() bool
	IsDevelopment() bool
	IsTesting() bool
	IsStaging() bool
	IsProduction() bool
	String() string
}

Env is the interface for environment of the application.

type Event

type Event interface {
	Type() string
	Data() interface{}
}

Event is an interface for event, the unit of message.

type HttpDoer

type HttpDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HttpDoer is the interface for a http client.

type Keyer

type Keyer interface {
	Key(delimiter string, args ...string) string
	Spread() []string
}

Keyer is an interface for key passing.

type Listener

type Listener interface {
	Listen() []Event
	Process(ctx context.Context, event Event) error
}

Listener is the handler for event.

type MapTenant

type MapTenant map[string]interface{}

MapTenant is an demo Tenant implementation. Useful for testing.

func (MapTenant) KV

func (d MapTenant) KV() map[string]interface{}

KV contains key values about this tenant.

func (MapTenant) String

func (d MapTenant) String() string

String should uniquely represent this user. It should be human friendly.

type Marshaller

type Marshaller interface {
	Marshal() ([]byte, error)
}

Marshaller is an interface for the data type that knows how to marshal itself.

type Printer

type Printer interface {
	Sprintf(msg string, val ...interface{}) string
}

A Printer models a i18n translator.

type Tenant

type Tenant interface {
	// KV contains key values about this tenant.
	KV() map[string]interface{}
	// String should uniquely represent this user. It should be human friendly.
	String() string
}

Tenant is interface representing a user or a consumer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL