interfaces

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const GlobalDefaultKey = "default"

Variables

View Source
var ErrNotImplemented = runtimeerrors.NewStructured("config", "method not implemented by this decoder")

ErrNotImplemented is returned when a specific decoder method is not implemented by a custom decoder. This signals the runtime to fall back to generic decoding.

Functions

This section is empty.

Types

type AppConfigDecoder

type AppConfigDecoder interface {
	DecodeApp() (*appv1.App, error)
}

type AppInfo

type AppInfo struct {
	// ID is the unique identifier of the application instance.
	ID string `json:"id" yaml:"id" mapstructure:"id"`
	// Name is the name of the application.
	Name string `json:"name" yaml:"name" mapstructure:"name"`
	// Version is the version of the application.
	Version string `json:"version" yaml:"version" mapstructure:"version"`
	// Env is the environment the application is running in (e.g., "dev", "test", "prod").
	Env string `json:"env" yaml:"env" mapstructure:"env"`
	// StartTime is the time when the application started. This is a runtime generated value.
	StartTime time.Time `json:"-" yaml:"-" mapstructure:"-"` // Mark as non-configurable
	// Metadata is a collection of arbitrary key-value pairs.
	Metadata map[string]string `json:"metadata" yaml:"metadata" mapstructure:"metadata"`
}

AppInfo represents the application's metadata. It is now a native Go struct, not a protobuf message.

type Client

type Client interface{}

Client 是一个标记接口,代表一个客户端连接实例,例如 *grpc.ClientConn。 由于不同协议的客户端(如 gRPC, HTTP)没有统一的接口, 我们使用一个空接口来提供灵活性,调用方需要进行类型断言。

type ComponentFactory

type ComponentFactory func(cfg StructuredConfig, container Container) (interface{}, error)

ComponentFactory defines the signature for a function that can create a generic component. It receives the global configuration and the specific configuration map for the component instance.

type Config

type Config interface {
	// Load loads the configuration from its source.
	Load() error

	// Decode provides generic decoding of a configuration key into a target struct.
	// This is the fundamental method that MUST be implemented by any Config instance.
	Decode(key string, value any) error

	// Raw provides an "escape hatch" to the underlying Kratos config.Config instance.
	// Custom implementations can return nil if not applicable.
	Raw() any

	// Close releases any resources held by the configuration.
	// MUST be implemented; can be a no-op if no resources are held.
	Close() error
}

Config is the minimal contract for providing a custom configuration source. Developers wishing to extend the framework with a new config system should implement this interface.

type Container

type Container interface {

	// Discoveries returns a map of all configured service discovery components.
	Discoveries() map[string]registry.Discovery

	// Discovery returns a discovery client by name.
	Discovery(name string) (registry.Discovery, bool)

	// Registrars returns a map of all configured service registrar components.
	Registrars() map[string]registry.Registrar

	// Registrar returns a registrar by name.
	Registrar(name string) (registry.Registrar, bool)

	// DefaultRegistrar returns the default service registrar, used for service self-registration.
	// It may be nil if no default registry is configured.
	DefaultRegistrar() registry.Registrar

	// ServerMiddlewares returns a map of all configured server middlewares.
	ServerMiddlewares() map[string]middleware.Middleware

	// ServerMiddleware returns a server middleware by name.
	ServerMiddleware(name string) (middleware.Middleware, bool)

	// ClientMiddlewares returns a map of all configured client middlewares.
	ClientMiddlewares() map[string]middleware.Middleware

	// ClientMiddleware returns a client middleware by name.
	ClientMiddleware(name string) (middleware.Middleware, bool)

	// StorageProvider returns the configured storage provider.
	StorageProvider() storage.Provider

	// Component retrieves a generic component by its registered name.
	// This allows for future components to be added without changing the interface.
	Component(name string) (component interface{}, ok bool)
}

Container defines the interface for retrieving fully-initialized application components. It is the return type of bootstrap.NewProvider and the input for runtime.New.

type DataConfigDecoder added in v0.2.11

type DataConfigDecoder interface {
	DecodeData() (*datav1.Data, error)
}

type DiscoveriesConfigDecoder

type DiscoveriesConfigDecoder interface {
	DecodeDefaultDiscovery() (string, error)
	DecodeDiscoveries() (*discoveryv1.Discoveries, error)
}

DiscoveriesConfigDecoder defines an OPTIONAL interface for providing a "fast path" to decode service discovery configurations. Custom Config implementations can implement this interface to provide an optimized decoding path.

type Encoder

type Encoder func(v any) ([]byte, error)

type KMiddleware

type KMiddleware = middleware.Middleware

KMiddleware is an alias for the Kratos middleware type.

type LoggerConfigDecoder

type LoggerConfigDecoder interface {
	DecodeLogger() (*loggerv1.Logger, error)
}

LoggerConfigDecoder defines an OPTIONAL interface for providing a "fast path" to decode logger configuration. Custom Config implementations can implement this interface to provide an optimized decoding path.

type Mailer

type Mailer interface {
	Send(msg *Message) error
}

Mailer is the interface that wraps the basic Send method. Implementations of this interface are responsible for sending emails.

type Message

type Message struct {
	From    string
	To      []string
	Cc      []string
	Bcc     []string
	Subject string
	Body    string
	HTML    bool
}

Message represents a generic email message.

type MiddlewareBuilder added in v0.2.7

type MiddlewareBuilder interface {
	factory.Registry[MiddlewareFactory]
	BuildClientMiddlewares(*middlewarev1.Middlewares, ...options.Option) []KMiddleware
	BuildServerMiddlewares(*middlewarev1.Middlewares, ...options.Option) []KMiddleware
}

MiddlewareBuilder is an interface that defines a method for registering a buildImpl.

type MiddlewareConfigDecoder

type MiddlewareConfigDecoder interface {
	DecodeMiddlewares() (*middlewarev1.Middlewares, error)
}

MiddlewareConfigDecoder defines an OPTIONAL interface for providing a "fast path" to decode middleware configurations. Custom Config implementations can implement this interface to provide an optimized decoding path.

type MiddlewareFactory added in v0.2.7

type MiddlewareFactory interface {
	// NewMiddlewareClient builds a client-side middleware.
	NewMiddlewareClient(*middlewarev1.Middleware, ...options.Option) (KMiddleware, bool)
	// NewMiddlewareServer builds a server-side middleware.
	NewMiddlewareServer(*middlewarev1.Middleware, ...options.Option) (KMiddleware, bool)
}

MiddlewareFactory is an interface that defines a method for creating a new buildImpl. It receives the middleware-specific Protobuf configuration and the generic options.Option slice. Each factory is responsible for parsing the options it cares about (e.g., by using log.FromOptions).

type Server

type Server interface {
	transport.Server // <-- 核心:确保与 Kratos App 的完全兼容
}

Server 是我们框架内所有服务类型的顶层抽象。 它通过内嵌 transport.Server,确保了任何实现了我们 Server 接口的类型, 同时也自动满足了 Kratos App 所需的 transport.Server 接口。

type ServiceConfigDecoder added in v0.2.7

type ServiceConfigDecoder interface {
	DecodeServers() (*transportv1.Servers, error)
	DecodeClients() (*transportv1.Clients, error)
}

ServiceConfigDecoder defines an OPTIONAL interface for providing a "fast path" to decode service configurations. Custom Config implementations can implement this interface to provide an optimized decoding path.

type StructuredConfig

StructuredConfig defines a set of type-safe, recommended methods for decoding configuration. It embeds the generic Config interface to allow for decoding arbitrary values.

Directories

Path Synopsis
Package database implements the functions, types, and interfaces for the module.
Package database implements the functions, types, and interfaces for the module.
Package pagination implements the functions, types, and interfaces for the module.
Package pagination implements the functions, types, and interfaces for the module.
Package security implements the functions, types, and interfaces for the module.
Package security implements the functions, types, and interfaces for the module.
token
Package token provides token caching functionality for security module
Package token provides token caching functionality for security module
Package storage implements the functions, types, and interfaces for the module.
Package storage implements the functions, types, and interfaces for the module.
components/blob
Package blob implements the functions, types, and interfaces for the module.
Package blob implements the functions, types, and interfaces for the module.
components/layout
Package layout provides a generic interface for storage layouts.
Package layout provides a generic interface for storage layouts.
components/meta
Package meta implements the functions, types, and interfaces for the module.
Package meta implements the functions, types, and interfaces for the module.

Jump to

Keyboard shortcuts

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