Package app

import "github.com/gonitro/nitro/app"

Overview ▾

Package app encapsulates the client, server and other interfaces to provide a complete dapp

func New

func New(opts ...Option) *nitroProgram

New returns a new application program

type Option

type Option func(*Options)

func AddInterval

func AddInterval(t time.Duration) Option

AddInterval specifies the interval on which to re-register

func AddTTL

func AddTTL(t time.Duration) Option

AddTTL specifies the TTL to use when registering the app

func Address

func Address(addr string) Option

Address sets the address of the server

func AfterStart

func AfterStart(fn func() error) Option

func AfterStop

func AfterStop(fn func() error) Option

func BeforeStart

func BeforeStart(fn func() error) Option

func BeforeStop

func BeforeStop(fn func() error) Option

func Broker

func Broker(b event.Broker) Option

func Client

func Client(c client.Client) Option

func Context

func Context(ctx context.Context) Option

Context specifies a context for the app. Can be used to signal shutdown of the app. Can be used for extra option values.

func Metadata

func Metadata(md map[string]string) Option

Metadata associated with the app

func Name

func Name(n string) Option

Name of the app

func Registry

func Registry(r registry.Table) Option

Registry sets the registry for the app and the underlying components

func Server

func Server(s server.Server) Option

Server sets the server for handling requests

func Transport

func Transport(t network.Transport) Option

Transport sets the app client/server network

func Version

func Version(v string) Option

Version of the app

func WrapCall

func WrapCall(w ...client.CallWrapper) Option

WrapCall is a convenience method for wrapping a Client CallFunc

func WrapClient

func WrapClient(w ...client.Wrapper) Option

WrapClient is a convenience method for wrapping a Client with some middleware component. A list of wrappers can be provided. Wrappers are applied in reverse order so the last is executed first.

func WrapHandler

func WrapHandler(w ...server.HandlerWrapper) Option

WrapHandler adds a handler Wrapper to a list of options passed into the server

func WrapSubscriber

func WrapSubscriber(w ...server.SubscriberWrapper) Option

WrapSubscriber adds a subscriber Wrapper to a list of options passed into the server

type Options

type Options struct {
    Broker   event.Broker
    Client   client.Client
    Server   server.Server
    Registry registry.Table

    // Before and After funcs
    BeforeStart []func() error
    BeforeStop  []func() error
    AfterStart  []func() error
    AfterStop   []func() error

    // Other options for implementations of the interface
    // can be stored in a context
    Context context.Context

type Program

Program is an interface for distributed application programming

type Program interface {
    // Set the current application name
    // Execute a function in a remote program
    Execute(prog, fn string, req, rsp interface{}) error
    // Broadcast an event to subscribers
    Broadcast(event string, msg interface{}) error
    // Register a function e.g a public Go struct/method with signature func(context.Context, *Request, *Response) error
    Register(fn interface{}) error
    // Subscribe to broadcast events. Signature is public Go func or struct with signature func(context.Context, *Message) error
    Subscribe(event string, fn interface{}) error
    // Run the application program
    Run() error


Name Synopsis
cache Package cache is a caching interface
memory Package memory is an in memory cache
client Package client is an interface for an RPC client
rpc Package rpc provides a network agnostic RPC client
codec Package codec is an interface for encoding messages
bytes Package bytes provides a bytes codec which does not encode or decode anything
json Package json provides a json codec
jsonrpc Package jsonrpc provides a json-rpc 1.0 codec
crypto Package crypto provides authentication and authorization capability
errors Package errors provides a way to return detailed information for an RPC request error.
event Package event is an interface used for asynchronous messaging
memory Package memory provides a memory event
logger Package log provides a log interface
metadata Package metadata is a way of defining message headers
network Package network is an interface for synchronous connection based communication
memory Package memory is an in-memory network
socket Package socket provides a net socket network
registry Package registry is an interface for service discovery
memory Package memory provides an in-memory registry
router Package router provides a network routing control plane
static Package static is a static router which returns the service name as the address + port
server Package server is an interface for a micro server
rpc Package rpc provides a network agnostic RPC server