Skip to main content

Overview

The Kratos framework abstracts the transport layer, the developers can access the implementation through the implementation interface, and the framework implements the communication protocol transport layer of gRPC and HTTP by default. Developers can refer to the official implementation code when implementing the communication protocol transport layer.

Interface

server

// The start and stop for server lifecycle management.
type Server interface {
Start(context.Context) error
Stop(context.Context) error
}

Transporter

type Transporter interface {
// The type of transporter, such the included "http" and "grpc", you could also implement new kind such as mqtt, websocket etc.
Kind() Kind
// The address of the server
Endpoint() string
// The full route of method
// E.g.: /helloworld.Greeter/SayHello
Operation() string
// The metadata of gRPC or the Header of HTTP
Header() Header
}

Endpointer

type Endpointer interface {
// This method is required for service register
Endpoint() (*url.URL, error)
}

Usage

Register http or grpc into server.

app := kratos.New(
kratos.Name(Name),
kratos.Server(
httpSrv,
),
)