Skip to content
Morlay edited this page Jul 26, 2018 · 1 revision

Motivation

Courier is a micro service framework which inspired by Go kit.

Goals

  1. Writing code as less as possible.
    • Following standard
    • Simple and extendable tag configuration.
    • Interface types for common processing units.
    • Code generating
  2. Consistent abstraction medium for transforming in different transports.
    • value contains data, type interfaces describes metadata
  3. Scan code base to generate spec for service, then generate client for downstream.

Core Concepts

Operator

Operator is the least processing unit in Courier. Any struct can be an Operator with a method Output(ctx context.Context) (interface{}, error):

type Operator interface {
    Output(ctx context.Context) (interface{}, error) 
}

The struct is used to define input parameters of the Operator, which will be unmarshal values by Transport. The method Output(ctx context.Context) (interface{}, error) will return success or failed results of this Operator with matched input parameters. We can also pick some value form context.Context which be set by upstream,Operator or Transport

Router and Route

Router is a carrier of Operator, so one Router have to contain at least one Operator. Router can register another Routers as children, and the Routers will form multiple Routes which are organized and distributed by Transport

var RouterRoot  = courier.NewRouter(&OperatorRoot{})
var RouterA = courier.NewRouter(&OperatorA{})
var RouterB = courier.NewRouter(&OperatorB{})

func init() {
    RouterRoot.Register(RouterA)
    RouterRoot.Register(RouterB)
    
    RouterA.Register(courier.NewRouter(&OperatorA1{}, &OperatorA2{}))
    RouterA.Register(courier.NewRouter(&OperatorA3{}, &OperatorA4{}))
    RouterB.Register(courier.NewRouter(&OperatorB1{}, &OperatorB2{}))
    
    // We will get routes:
    // OperatorRoot -> OperatorA -> OperatorA1 -> OperatorA2
    // OperatorRoot -> OperatorA -> OperatorA3 -> OperatorA4
    // OperatorRoot -> OperatorB -> OperatorB1 -> OperatorB2
}

Transport

Transport will do routing distribution and transform incoming data to Operators on matched Route. And send response which is transformed from results of last Operator with format of corresponding protocol.

Transport may do extension for Operator.

Clone this wiki locally