contract

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 4 Imported by: 20

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

This section is empty.

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 {
	ConfigUnmarshaler
	String(string) string
	Int(string) int
	Strings(string) []string
	Bool(string) bool
	Get(string) interface{}
	Float64(string) float64
	Duration(string) time.Duration
}

ConfigAccessor builds upon the ConfigUnmarshaler and provides a richer set of API. Note: it is recommended to inject ConfigUnmarshaler as the dependency and call config.Upgrade to get the ConfigAccessor. The interface area of ConfigUnmarshaler is much smaller and thus much easier to customize.

type ConfigRouter

type ConfigRouter interface {
	Route(path string) ConfigUnmarshaler
}

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

type ConfigUnmarshaler added in v0.9.0

type ConfigUnmarshaler interface {
	Unmarshal(path string, o interface{}) error
}

ConfigUnmarshaler is a minimum config interface that can be used to retrieve configuration from external system. If the configuration is hot reloaded, ConfigUnmarshaler should fetch the latest info.

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 {
	Modules() []interface{}
}

Container holds modules.

type DIPopulator added in v0.9.0

type DIPopulator interface {
	// Populate is just another way of fetching dependencies from container. It
	// accepts a ptr to target, and populates the target from the container.
	Populate(target interface{}) error
}

DIPopulator is an interface that models a container to which users can fetch dependencies. It is a syntax sugar to dig.Container. See dig.Container for the implementation requirement.

type Dispatcher

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

Dispatcher is the event registry that is able to send payload 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 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 LevelLogger added in v0.9.0

type LevelLogger interface {
	Logger
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Err(args ...interface{})
	Debugf(template string, args ...interface{})
	Infof(template string, args ...interface{})
	Warnf(template string, args ...interface{})
	Errf(template string, args ...interface{})
	Debugw(msg string, fields ...interface{})
	Infow(msg string, fields ...interface{})
	Warnw(msg string, fields ...interface{})
	Errw(msg string, fields ...interface{})
}

LevelLogger is plaintext logger with level.

type Listener

type Listener interface {
	Listen() (topic interface{})
	Process(ctx context.Context, payload interface{}) error
}

Listener is the handler for event.

type Logger added in v0.9.0

type Logger = log.Logger

Logger is an alias of go kit logger

type Printer

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

A Printer models a i18n translator.

Jump to

Keyboard shortcuts

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