service

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package service implements the functions, types, and interfaces for the module.

Index

Constants

View Source
const (
	ProtocolGRPC = "grpc"
	ProtocolHTTP = "http"
)

Protocol is the name of the gRPC, HTTP, or other protocol.

View Source
const Module = "service"

Variables

View Source
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

func ContextFromOptions(opts []options.Option) context.Context

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

func WithContext(ctx context.Context) options.Option

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

type ServerRegisterFunc func(ctx context.Context, srv any) error

ServerRegisterFunc is a function that implements ServerRegistrar.

func (ServerRegisterFunc) Register added in v0.2.6

func (f ServerRegisterFunc) Register(ctx context.Context, srv any) error

Register implements the ServerRegistrar interface for ServerRegisterFunc.

type ServerRegistrar added in v0.2.1

type ServerRegistrar interface {
	Register(ctx context.Context, srv any) error
}

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.

Jump to

Keyboard shortcuts

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