server

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: MIT Imports: 10 Imported by: 0

README

Service

TODO: https://go-zero.dev/docs/advance/rpc-call

Usage

type Config struct {
service.ServerConfiguration
Mysql struct {
DataSource string
}
CacheRedis cache.CacheConf
}
Name: user.rpc
ListenOn: 127.0.0.1:8080
Etcd:
  Hosts:
    - $etcdHost
  Key: user.rpc
Mysql:
  DataSource: $user:$password@tcp($url)/$db?charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai
CacheRedis:
  - Host: $host
    Pass: $pass
    Type: node 

Documentation

Index

Constants

View Source
const (
	// DefaultName default server name
	DefaultName = "mkit.service.default"
	// DefaultAddress random port
	DefaultAddress = ":0"
	// DefaultMaxRecvMsgSize maximum message that client can receive
	// (16 MB).
	DefaultMaxRecvMsgSize = 1024 * 1024 * 16

	// DefaultMaxSendMsgSize maximum message that client can send
	// (16 MB).
	DefaultMaxSendMsgSize = 1024 * 1024 * 16
)

Variables

This section is empty.

Functions

func NewClient

func NewClient(target string, opts ...ClientOption) (*grpc.ClientConn, error)

NewClient creates and returns a new grpc client connection Users should call ClientConn.Close() to terminate all the pending operations. also keep track of all clients so that, it disconnects client connections gracefully on kill signal. throw error if connection fail or if there is already a client created with same name

func SetServingStatus

func SetServingStatus(service string, servingStatus grpc_health_v1.HealthCheckResponse_ServingStatus)

SetServingStatus updates service health status. concurrency safe

func Start

func Start() error

Start all daemon services and wait for kill signal, then gracefully shutdown

Types

type ClientConfiguration added in v0.3.0

type ClientConfiguration struct {
	Endpoints []string `json:",optional"`
	Target    string   `json:",optional"`
	App       string   `json:",optional"`
	Token     string   `json:",optional"`
	NonBlock  bool     `json:",optional"`
	Timeout   int64    `json:",default=2000"`
}

ClientConfiguration is for gRPC client config.

type ClientOption

type ClientOption func(*ClientOptions)

func ClientName

func ClientName(n string) ClientOption

ClientName Name of the client

func WithDialOptions

func WithDialOptions(opts ...grpc.DialOption) ClientOption

WithDialOptions DialOptions for client

type ClientOptions

type ClientOptions struct {
	Name        string
	DialOptions []grpc.DialOption
	Context     context.Context
}

type Server

type Server interface {
	// Server returns grpc server previously created with NewServer()
	Server() *grpc.Server
	// Client creates and returns a new grpc client connection
	// Users should call ClientConn.Close() to terminate all the pending operations.
	// also keep track of all clients so that, it disconnect client connections gracefully on kill signal.
	// throw error if connection fail or if there is already a client created with same name
	Client(target string, opts ...ClientOption) (*grpc.ClientConn, error)
	// SetServingStatus updates service health status. concurrency safe
	// empty service string represents the health of the whole system
	SetServingStatus(service string, servingStatus grpc_health_v1.HealthCheckResponse_ServingStatus)
	Start() error
	// Stop will force stop server
	Stop()
}

Server is a grpc Server

var DefaultServer Server

func NewServer

func NewServer(ctx context.Context, opts ...ServerOption) Server

NewServer creates and returns a new grpc Server

type ServerConfiguration added in v0.3.0

type ServerConfiguration struct {
	Name          string
	Log           string
	Mode          string       `json:",default=pro,options=dev|test|rt|pre|pro"`
	MetricsURL    string       `json:",optional"`
	Telemetry     trace.Config `json:",optional"`
	ListenOn      string
	Auth          bool `json:",optional"`
	StrictControl bool `json:",optional"`
	// setting 0 means no timeout
	Timeout      int64 `json:",default=2000"`
	CPUThreshold int64 `json:",default=900,range=[0:1000]"`
}

ServerConfiguration is for gRPC server config.

type ServerOption

type ServerOption func(*ServerOptions)

func Context

func Context(ctx context.Context) ServerOption

Context appContext to trigger terminate signal

func ServerName

func ServerName(n string) ServerOption

ServerName Name of the service

func WithListener

func WithListener(listener net.Listener) ServerOption

WithListener specifies the net.Listener to use instead of the default

func WithServerOptions

func WithServerOptions(opts ...grpc.ServerOption) ServerOption

WithServerOptions ServerOptions for server

type ServerOptions

type ServerOptions struct {
	Name          string
	Listener      net.Listener
	ServerOptions []grpc.ServerOption
	Context       context.Context
}

Jump to

Keyboard shortcuts

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