xctrl

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: MIT, Apache-2.0 Imports: 14 Imported by: 0

README

XCtrl

XCtrl框架底层逻辑。

Documentation

Overview

Package micro is a pluggable framework for microservices

Index

Constants

This section is empty.

Variables

View Source
var (
	HeaderPrefix = "XCtrl-"
)

Functions

func NewContext

func NewContext(ctx context.Context, s Service) context.Context

NewContext returns a new Context with the Service embedded within it.

func RegisterHandler

func RegisterHandler(s server.Server, h interface{}, opts ...server.HandlerOption) error

RegisterHandler is syntactic sugar for registering a handler

Types

type Function

type Function interface {
	// Inherits Service interface
	Service
	// Done signals to complete execution
	Done() error
	// Handle registers an RPC handler
	Handle(v interface{}) error
	// Subscribe registers a subscriber
	Subscribe(topic string, v interface{}) error
}

Function is a one time executing Service

type Option

type Option func(*Options)

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() Option

func Client

func Client(c client.Client) Option

func Context

func Context(ctx context.Context) Option

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

func HandleSignal

func HandleSignal(b bool) Option

HandleSignal toggles automatic installation of the signal handler that traps TERM, INT, and QUIT. Users of this feature to disable the signal handler, should control liveness of the service through the context.

func Metadata

func Metadata(md map[string]string) Option

Metadata associated with the service

func Name

func Name(n string) Option

Name of the service

func Profile

func Profile(p profile.Profile) Option

Profile to be used for debug profile

func Selector

func Selector() Option

Selector sets the selector for the service client

func Server

func Server(s server.Server) Option

func Version

func Version(v string) Option

Version of the service

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 {
	Client client.Client
	Server server.Server

	// 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

	Signal bool

	Profile profile.Profile
}

type Publisher

type Publisher interface {
	Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error
}

Publisher is syntactic sugar for publishing

type Service

type Service interface {
	// The service name
	Name() string
	// Init initialises options
	Init(...Option)
	// Options returns the current options
	Options() Options
	// Client is used to call services
	Client() client.Client
	// Server is for handling requests and events
	Server() server.Server
	// Run the service
	Run() error
	// The service implementation
	String() string
}

Service is an interface that wraps the lower level libraries within go-micro. Its a convenience method for building and initialising services.

func FromContext

func FromContext(ctx context.Context) (Service, bool)

FromContext retrieves a Service from the Context.

func NewService

func NewService(opts ...Option) Service

NewService creates and returns a new Service based on the packages within.

Directories

Path Synopsis
api
handler
Package handler provides http handlers
Package handler provides http handlers
handler/event
Package event provides a handler which publishes an event
Package event provides a handler which publishes an event
handler/web
Package web contains the web handler including websocket support
Package web contains the web handler including websocket support
resolver
Package resolver resolves a http request to an endpoint
Package resolver resolves a http request to an endpoint
resolver/grpc
Package grpc resolves a grpc service like /greeter.Say/Hello to greeter service
Package grpc resolves a grpc service like /greeter.Say/Hello to greeter service
resolver/host
Package host resolves using http host
Package host resolves using http host
resolver/path
Package path resolves using http path
Package path resolves using http path
resolver/vpath
Package vpath resolves using http path and recognised versioned urls
Package vpath resolves using http path and recognised versioned urls
router
Package router provides api service routing
Package router provides api service routing
router/registry
Package registry provides a dynamic api service router
Package registry provides a dynamic api service router
server
Package server provides an API gateway server which handles inbound requests
Package server provides an API gateway server which handles inbound requests
Package client is an interface for an RPC client
Package client is an interface for an RPC client
Package codec is an interface for encoding messages
Package codec is an interface for encoding messages
bytes
Package bytes provides a bytes codec which does not encode or decode anything
Package bytes provides a bytes codec which does not encode or decode anything
grpc
Package grpc provides a grpc codec
Package grpc provides a grpc codec
json
Package json provides a json codec
Package json provides a json codec
jsonrpc
Package jsonrpc provides a json-rpc 1.0 codec
Package jsonrpc provides a json-rpc 1.0 codec
proto
Package proto provides a proto codec
Package proto provides a proto codec
protorpc
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.
text
Package text reads any text/* content-type
Package text reads any text/* content-type
debug
handler
Package handler implements service debug handler embedded in go-micro services
Package handler implements service debug handler embedded in go-micro services
log
Package log provides debug logging
Package log provides debug logging
log/memory
Package memory provides an in memory log buffer
Package memory provides an in memory log buffer
profile
Package profile is for profilers
Package profile is for profilers
profile/http
Package http enables the http profiler
Package http enables the http profiler
profile/pprof
Package pprof provides a pprof profiler
Package pprof provides a pprof profiler
stats
Package stats provides runtime stats
Package stats provides runtime stats
trace
Package trace provides an interface for distributed tracing
Package trace provides an interface for distributed tracing
Package errors provides a way to return detailed information for an RPC request error.
Package errors provides a way to return detailed information for an RPC request error.
Package log provides a log interface
Package log provides a log interface
Package metadata is a way of defining message headers
Package metadata is a way of defining message headers
Package server is an interface for a micro server
Package server is an interface for a micro server
Package store is an interface for distribute data storage.
Package store is an interface for distribute data storage.
cache
Package cache implements a faulting style read cache on top of multiple micro stores
Package cache implements a faulting style read cache on top of multiple micro stores
file
Package local is a file system backed store
Package local is a file system backed store
memory
Package memory is a in-memory store store
Package memory is a in-memory store store
Package sync is an interface for distributed synchronization
Package sync is an interface for distributed synchronization
memory
Package memory provides a sync.Mutex implementation of the lock for local use
Package memory provides a sync.Mutex implementation of the lock for local use
util
backoff
Package backoff provides backoff functionality
Package backoff provides backoff functionality
buf
ctx
log
Package log is a global internal logger
Package log is a global internal logger
net
qson
Package qson implmenets decoding of URL query params into JSON and Go values (using JSON struct tags).
Package qson implmenets decoding of URL query params into JSON and Go values (using JSON struct tags).
ring
Package ring provides a simple ring buffer for storing local data
Package ring provides a simple ring buffer for storing local data
tls

Jump to

Keyboard shortcuts

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