Documentation
¶
Index ¶
- func App(name string, loadFuncs ...gone.LoadFunc) (app *gone.Application)
- func BuildOnceLoadFunc(ops ...*LoadOp) gone.LoadFunc
- func ErrorPrinter(logger gone.Logger, err error, msg string, args ...any)
- func GetComponentByName[T any](keeper gone.GonerKeeper, name string) (T, error)
- func GetLocalIps() []net.IP
- func GetServerValue(instance Service) string
- func GetServiceId(instance Service) string
- func IsLoaded(loader gone.Loader, goner gone.Goner) bool
- func NamedThirdComponentLoadFunc[T any](name string, component T) gone.LoadFunc
- func PanicIfErr(err error)
- func Recover(logger gone.Logger)
- func ResultError[T any](t *T, err error, msg string) (*T, error)
- func SingLoadProviderFunc[P any, T any](fn gone.FunctionProvider[P, T], options ...gone.Option) gone.LoadFunc
- type Cmux
- type Controller
- type CtxLogger
- type DoLocker
- type HTTPDoer
- type HandlerFunc
- type IRoutes
- type IsOtelLogLoaded
- type IsOtelMeterLoaded
- type IsOtelTracerLoaded
- type LoadBalanceStrategy
- type LoadBalancer
- type LoadOp
- type Metadata
- type MountError
- type ProtocolType
- type Service
- type ServiceDiscovery
- type ServiceRegistry
- type Tracer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func App ¶ added in v1.1.0
func App(name string, loadFuncs ...gone.LoadFunc) (app *gone.Application)
App creates or retrieves an application instance with the specified name and loading functions name: Application name loadFuncs: Loading functions Returns: Application instance
func BuildOnceLoadFunc ¶ added in v1.0.9
BuildOnceLoadFunc builds a loading function that executes only once ops: List of LoadOps to execute Returns: Loading function that ensures single execution
func ErrorPrinter ¶ added in v1.2.1
func GetComponentByName ¶ added in v1.0.10
func GetComponentByName[T any](keeper gone.GonerKeeper, name string) (T, error)
GetComponentByName gets a component of specified type by name T: Component type to get keeper: Component manager name: Component name Returns: Found component instance and possible error
func GetLocalIps ¶ added in v1.0.9
GetLocalIps gets all non-loopback IPv4 addresses of the local machine Returns: List of all available IPv4 addresses
func GetServerValue ¶ added in v1.0.11
func GetServiceId ¶ added in v1.0.11
func NamedThirdComponentLoadFunc ¶ added in v1.0.10
NamedThirdComponentLoadFunc creates a named third-party component loading function T: Component type name: Component name component: Third-party component instance Returns: Loading function for third-party components
func Recover ¶ added in v1.0.9
Recover captures and logs panics to prevent program crashes logger: Logger for recording panic information
func ResultError ¶ added in v1.2.1
ResultError return wrapped error if error occurs, otherwise returns the result
func SingLoadProviderFunc ¶ added in v1.0.10
func SingLoadProviderFunc[P any, T any](fn gone.FunctionProvider[P, T], options ...gone.Option) gone.LoadFunc
SingLoadProviderFunc creates a loading function for singleton Provider P: Provider's parameter type T: Component type provided by Provider fn: Function to create components options: Loading options Returns: Loading function that ensures single loading Deprecated since v2.1.0, use gone.BuildSingProviderLoadFunc instead:
Types ¶
type Controller ¶ added in v1.2.1
type Controller interface {
// Mount Route mount interface, this interface will be called before the service starts, the implementation of this function should usually return `nil`
Mount() MountError
}
type CtxLogger ¶ added in v1.2.1
CtxLogger Log tracking, which is used to assign a unified traceId to the same call link to facilitate log tracking. Examples:
type user struct {
gone.Flag
logger CtxLogger `gone:"*"` //Inject Logger
}
func (u *user) Use(ctx context.Context) (err error) {
// get traceId from openTelemetry context and inject it into the logger
logger := u.logger.Ctx(ctx)
logger.Infof("hello")
return
}
type HandlerFunc ¶ added in v1.2.1
type HandlerFunc any
type IRoutes ¶ added in v1.2.1
type IRoutes interface {
Use(...HandlerFunc) IRoutes
Handle(string, string, ...HandlerFunc) IRoutes
Any(string, ...HandlerFunc) IRoutes
GET(string, ...HandlerFunc) IRoutes
POST(string, ...HandlerFunc) IRoutes
DELETE(string, ...HandlerFunc) IRoutes
PATCH(string, ...HandlerFunc) IRoutes
PUT(string, ...HandlerFunc) IRoutes
OPTIONS(string, ...HandlerFunc) IRoutes
HEAD(string, ...HandlerFunc) IRoutes
}
type IsOtelLogLoaded ¶ added in v1.2.1
type IsOtelLogLoaded bool
type IsOtelMeterLoaded ¶ added in v1.2.1
type IsOtelMeterLoaded bool
type IsOtelTracerLoaded ¶ added in v1.2.1
type IsOtelTracerLoaded bool
type LoadBalanceStrategy ¶ added in v1.0.9
type LoadBalanceStrategy interface {
// Select chooses a service instance from the provided list of instances
// Returns an error if selection fails or no suitable instance is found
Select(ctx context.Context, instances []Service) (Service, error)
}
LoadBalanceStrategy defines the interface for implementing different load balancing algorithms It allows for custom instance selection logic based on various factors
type LoadBalancer ¶ added in v1.0.9
type LoadBalancer interface {
// GetInstance returns a service instance based on the load balancing strategy
// Returns an error if no instance is available or selection fails
GetInstance(ctx context.Context, serviceName string) (Service, error)
}
LoadBalancer provides load balancing functionality for service instances It selects an appropriate instance from available service instances
type LoadOp ¶ added in v1.0.9
type LoadOp struct {
// contains filtered or unexported fields
}
LoadOp struct encapsulates loading operations goner: Component to be loaded options: Loading options f: Loading function
type MountError ¶ added in v1.2.1
type MountError error
type ProtocolType ¶
type ProtocolType int
const ( GRPC ProtocolType = 0x01 HTTP1 ProtocolType = 0x01 << 1 )
type Service ¶
type Service interface {
// GetName returns the service name of the instance
GetName() string
GetIP() string
GetPort() int
// GetMetadata returns the metadata associated with the service instance
GetMetadata() Metadata
GetWeight() float64
// IsHealthy returns the health status of the service instance
IsHealthy() bool
}
Service represents a service instance in the service registry It provides basic information about a service instance including its identity, location, metadata, and health status
func NewService ¶ added in v1.0.9
func ParseService ¶ added in v1.0.11
type ServiceDiscovery ¶ added in v1.0.9
type ServiceDiscovery interface {
// GetInstances returns all instances of a specified service
// Returns an error if the service discovery fails
GetInstances(serviceName string) ([]Service, error)
// Watch creates a channel that receives updates when the service instances change
// Returns an error if watching fails
Watch(serviceName string) (ch <-chan []Service, stop func() error, err error)
}
ServiceDiscovery provides methods for discovering and monitoring service instances It allows clients to find available service instances and watch for changes
type ServiceRegistry ¶ added in v1.0.9
type ServiceRegistry interface {
// Register adds a new service instance to the registry
// Returns an error if registration fails
Register(instance Service) error
// Deregister removes a service instance from the registry
// Returns an error if de registration fails
Deregister(instance Service) error
}
ServiceRegistry provides methods for service registration and management It handles service instance registration, deregistration, and heartbeat updates
type Tracer ¶
type Tracer interface {
//SetTraceId to set `traceId` to the calling function. If traceId is an empty string, an automatic one will
//be generated. TraceId can be obtained by using the GetTraceId () method in the calling function.
SetTraceId(traceId string, fn func())
//GetTraceId Get the traceId of the current goroutine
GetTraceId() string
//Go Start a new goroutine instead of `go func`, which can pass the traceId to the new goroutine.
Go(fn func())
}
Tracer Log tracking, which is used to assign a unified traceId to the same call link to facilitate log tracking.