Documentation
¶
Overview ¶
Package service implements the functions, types, and interfaces for the module.
Index ¶
- Constants
- Variables
- func ContextFromOptions(opts []options.Option) context.Context
- func NewClient(ctx context.Context, cfg *transportv1.Client, opts ...options.Option) (interfaces.Client, error)
- func NewServer(cfg *transportv1.Server, opts ...options.Option) (interfaces.Server, error)
- func RegisterProtocol(name string, f ProtocolFactory)
- func WithContext(ctx context.Context) options.Option
- func WithContextRegistrar(ctx context.Context, registrar ...ServerRegistrar) options.Option
- func WithServerRegistrar(registrar ...ServerRegistrar) options.Option
- type ProtocolFactory
- type ServerRegisterFunc
- type ServerRegistrar
Constants ¶
const ( ProtocolGRPC = "grpc" ProtocolHTTP = "http" )
Protocol is the name of the gRPC, HTTP, or other protocol.
const Module = "service"
Variables ¶
var ( ErrNilServerConfig = newServiceError("server configuration is nil") ErrMissingServerConfig = newServiceError("missing server configuration") ErrNilClientConfig = newServiceError("client configuration is nil") ErrMissingClientConfig = newServiceError("missing client configuration") ErrMissingProtocol = newServiceError("protocol is not specified") ErrUnsupportedProtocol = newServiceError("unsupported protocol") )
Predefined errors using the common StructuredError
Functions ¶
func ContextFromOptions ¶ added in v0.2.13
ContextFromOptions retrieves the context.Context from a slice of options. If no context is found, context.Background() is returned.
func NewClient ¶ added in v0.2.6
func NewClient(ctx context.Context, cfg *transportv1.Client, opts ...options.Option) (interfaces.Client, error)
NewClient creates a new client instance based on the provided configuration and options. It automatically looks up the appropriate protocol factory from the default registry.
func NewServer ¶ added in v0.2.6
func NewServer(cfg *transportv1.Server, opts ...options.Option) (interfaces.Server, error)
NewServer creates a new server instance based on the provided configuration and options. It automatically looks up the appropriate protocol factory from the default registry.
func RegisterProtocol ¶ added in v0.2.6
func RegisterProtocol(name string, f ProtocolFactory)
RegisterProtocol registers a new protocol factory with the default registry. This function is the public API for registration and is safe for concurrent use.
func WithContext ¶ added in v0.2.13
WithContext sets the context.Context for the service.
func WithContextRegistrar ¶ added in v0.2.13
func WithContextRegistrar(ctx context.Context, registrar ...ServerRegistrar) options.Option
WithContextRegistrar sets both the context.Context and ServerRegistrar for the service.
func WithServerRegistrar ¶ added in v0.2.13
func WithServerRegistrar(registrar ...ServerRegistrar) options.Option
Types ¶
type ProtocolFactory ¶ added in v0.2.6
type ProtocolFactory interface {
NewServer(cfg *transportv1.Server, opts ...options.Option) (interfaces.Server, error)
NewClient(ctx context.Context, cfg *transportv1.Client, opts ...options.Option) (interfaces.Client, error)
}
ProtocolFactory defines the factory standard for creating a specific protocol service instance。
type ServerRegisterFunc ¶ added in v0.2.6
ServerRegisterFunc is a function that implements ServerRegistrar.
type ServerRegistrar ¶ added in v0.2.1
ServerRegistrar defines the single, universal entry point for service registration. It is the responsibility of the transport-specific factories to pass the correct server type (e.g., *GRPCServer or *HTTPServer) to the Register method. The implementation of this interface, typically within the user's project, is expected to perform a type switch to handle the specific server type.
func ServerRegistrarFromContext ¶ added in v0.2.13
func ServerRegistrarFromContext(ctx options.Context) []ServerRegistrar
func ServerRegistrarFromOptions ¶ added in v0.2.13
func ServerRegistrarFromOptions(opts []options.Option) []ServerRegistrar
Directories
¶
| Path | Synopsis |
|---|---|
|
Package selector contains generated code by adptool.
|
Package selector contains generated code by adptool. |
|
Package tls implements the functions, types, and interfaces for the module.
|
Package tls implements the functions, types, and interfaces for the module. |
|
Package transport contains generated code by adptool.
|
Package transport contains generated code by adptool. |