runtime

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 12 Imported by: 3

README

Runtime Package

Introduction

The current go package defines the general configuration of the service runtime, as well as the loading of the runtime configuration.

Available Packages
  • proto: For compatibility with other languages, the interface is defined using proto files and implemented using gRPC. All proto definition files used by the Runtime are placed in 'proto' directory.
  • config: The files in this directory define the basic configuration of the service runtime, as well as the loading of the run configuration.
  • registry: This directory defines an alias for 'kratos/v2/registry', primarily for backward compatibility and for placing import error paths.
  • transport: The current directory currently defines only the transport implementation of gins, which is not complete. You can use protoc-gen-go-gins generates the relevant code.

Getting Started

To incorporate the Toolkit into your project, follow these steps:

  1. Add the dependency: Add the Toolkit as a dependency in your go.mod file, specifying the latest version:
go get github.com/origadmin/toolkit/runtime@vX.Y.Z

Replace vX.Y.Z with the desired version or latest to fetch the most recent release.

  1. Import required packages: In your Go source files, import the necessary packages from the Toolkit:
import (
    "github.com/origadmin/toolkit/runtime"
    "github.com/origadmin/toolkit/runtime/config"
    "github.com/origadmin/toolkit/runtime/registry"
)

// NewDiscovery creates a new discovery.
func NewDiscovery(registryConfig *config.RegistryConfig) registry.Discovery {
	if registryConfig == nil {
		panic("no registry config")
	}
	discovery, err := runtime.NewDiscovery(registryConfig)
	if err != nil {
		panic(err)
	}
	return discovery
}

// NewRegistrar creates a new registrar.
func NewRegistrar(registryConfig *config.RegistryConfig) registry.Registrar {
	if registryConfig == nil {
        panic("no registry config")
	}
	registrar, err := runtime.NewRegistrar(registryConfig)
	if err != nil {
        panic(err)
	}
	return registrar
}

Contributing

We welcome contributions from the community to improve and expand the Toolkit. To contribute, please follow these guidelines:

  1. Familiarize yourself with the project: Read the CONTRIBUTING file for details on the contribution process, code style, and Pull Request requirements.
  2. Submit an issue or proposal: If you encounter any bugs, have feature suggestions, or want to discuss potential changes, create an issue in the GitHub repository.
  3. Create a Pull Request: After implementing your changes, submit a Pull Request following the guidelines outlined in CONTRIBUTING.

Contributors

Code of Conduct

All contributors and participants are expected to abide by the Contributor Covenant, version 2.1. This document outlines the expected behavior when interacting with the Toolkit community.

License

The Toolkit is distributed under the terms of the MIT. This permissive license allows for free use, modification, and distribution of the toolkit in both commercial and non-commercial contexts.

Documentation

Overview

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

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

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

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

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

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

Package runtime provides functions for loading configurations and registering services.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.String("not found")

ErrNotFound is an error that is returned when a ConfigBuilder or RegistryBuilder is not found.

Functions

func NewConfig

func NewConfig(cfg *configv1.SourceConfig, ss ...config.SourceSetting) (config.Config, error)

NewConfig creates a new Config using the registered ConfigBuilder.

func NewDiscovery

func NewDiscovery(cfg *configv1.Registry) (registry.Discovery, error)

NewDiscovery creates a new Discovery using the registered RegistryBuilder.

func NewGRPCServiceClient added in v0.0.9

func NewGRPCServiceClient(ctx context.Context, cfg *configv1.Service) (*service.GRPCClient, error)

NewGRPCServiceClient creates a new GRPC client using the provided context and configuration

func NewGRPCServiceServer added in v0.0.9

func NewGRPCServiceServer(cfg *configv1.Service) (*service.GRPCServer, error)

NewGRPCServiceServer creates a new GRPC server using the provided configuration

func NewHTTPServiceClient added in v0.0.9

func NewHTTPServiceClient(ctx context.Context, cfg *configv1.Service) (*service.HTTPClient, error)

NewHTTPServiceClient creates a new HTTP client using the provided context and configuration

func NewHTTPServiceServer added in v0.0.9

func NewHTTPServiceServer(cfg *configv1.Service, opts ...config.ServiceSetting) (*service.HTTPServer, error)

NewHTTPServiceServer creates a new HTTP server using the provided configuration

func NewMiddlewareClient added in v0.0.9

func NewMiddlewareClient(name string, cm *configv1.Customize_Config) (middleware.Middleware, error)

NewMiddlewareClient creates a new Middleware with the builder.

func NewMiddlewareServer added in v0.0.9

func NewMiddlewareServer(name string, cm *configv1.Customize_Config) (middleware.Middleware, error)

NewMiddlewareServer creates a new Middleware with the builder.

func NewMiddlewaresClient added in v0.0.9

func NewMiddlewaresClient(cc *configv1.Customize) []middleware.Middleware

NewMiddlewaresClient creates a new Middleware with the builder.

func NewMiddlewaresServer added in v0.0.9

func NewMiddlewaresServer(cc *configv1.Customize) []middleware.Middleware

NewMiddlewaresServer creates a new Middleware with the builder.

func NewRegistrar

func NewRegistrar(cfg *configv1.Registry) (registry.Registrar, error)

NewRegistrar creates a new Registrar using the registered RegistryBuilder.

func RegisterConfig

func RegisterConfig(name string, configBuilder ConfigBuilder)

RegisterConfig registers a ConfigBuilder with the builder.

func RegisterConfigFunc added in v0.0.6

func RegisterConfigFunc(name string, buildFunc ConfigBuildFunc)

RegisterConfigFunc registers a ConfigBuilder with the builder.

func RegisterConfigSync added in v0.0.10

func RegisterConfigSync(name string, syncFunc ConfigSyncFunc)

func RegisterMiddleware added in v0.0.9

func RegisterMiddleware(name string, middlewareBuilder MiddlewareBuilder)

RegisterMiddleware registers a MiddlewareBuilder with the builder.

func RegisterRegistry

func RegisterRegistry(name string, registryBuilder RegistryBuilder)

RegisterRegistry registers a RegistryBuilder with the builder.

func RegisterService added in v0.0.9

func RegisterService(name string, serviceBuilder ServiceBuilder)

RegisterService registers a service builder with the provided name

func SyncConfig added in v0.0.10

func SyncConfig(cfg *configv1.SourceConfig, v any, ss ...config.SourceSetting) error

SyncConfig synchronizes the given configuration with the given value.

Types

type Builder

type Builder interface {
	ConfigBuilder
	RegistryBuilder
	ServiceBuilder
	MiddlewareBuilders
	// contains filtered or unexported methods
}

func Global added in v0.0.9

func Global() Builder

Global returns the global instance of the builder.

func New

func New() Builder

New creates a new Builder.

type ConfigBuildFunc

type ConfigBuildFunc func(*configv1.SourceConfig, ...config.SourceSetting) (config.Config, error)

ConfigBuildFunc is a function type that takes a SourceConfig and a list of Options and returns a Config and an error.

func (ConfigBuildFunc) NewConfig

NewConfig is a method that implements the ConfigBuilder interface for ConfigBuildFunc.

type ConfigBuilder

type ConfigBuilder interface {
	// NewConfig creates a new config using the given SourceConfig and a list of Options.
	NewConfig(*configv1.SourceConfig, ...config.SourceSetting) (config.Config, error)
}

ConfigBuilder is an interface that defines a method for creating a new config.

type ConfigSyncFunc added in v0.0.10

type ConfigSyncFunc func(*configv1.SourceConfig, any, ...config.SourceSetting) error

ConfigSyncFunc is a function type that takes a SourceConfig and a list of Options and returns an error.

func (ConfigSyncFunc) SyncConfig added in v0.0.10

func (fn ConfigSyncFunc) SyncConfig(cfg *configv1.SourceConfig, v any, ss ...config.SourceSetting) error

SyncConfig is a method that implements the ConfigSyncer interface for ConfigSyncFunc.

type ConfigSyncer added in v0.0.10

type ConfigSyncer interface {
	SyncConfig(*configv1.SourceConfig, any, ...config.SourceSetting) error
}

ConfigSyncer is an interface that defines a method for synchronizing a config.

type DiscoveryBuildFunc

type DiscoveryBuildFunc func(cfg *configv1.Registry) (registry.Discovery, error)

DiscoveryBuildFunc is a function type that takes a *config.RegistryConfig and returns a registry.Discovery and an error.

func (DiscoveryBuildFunc) NewDiscovery

func (fn DiscoveryBuildFunc) NewDiscovery(cfg *configv1.Registry) (registry.Discovery, error)

NewDiscovery is a method that calls the DiscoveryBuildFunc with the given config.

type MiddlewareBuildFunc added in v0.0.9

type MiddlewareBuildFunc = func(*configv1.Customize_Config) (middleware.Middleware, error)

MiddlewareBuildFunc is an interface that defines methods for creating middleware.

type MiddlewareBuilder added in v0.0.9

type MiddlewareBuilder interface {
	// NewMiddlewareClient build middleware
	NewMiddlewareClient(config *configv1.Customize_Config) (middleware.Middleware, error)
	// NewMiddlewareServer build middleware
	NewMiddlewareServer(config *configv1.Customize_Config) (middleware.Middleware, error)
}

MiddlewareBuilder middleware builder interface

type MiddlewareBuilders added in v0.0.9

type MiddlewareBuilders interface {
	// NewMiddlewaresClient build middleware
	NewMiddlewaresClient([]middleware.Middleware, *configv1.Customize) []middleware.Middleware
	// NewMiddlewaresServer build middleware
	NewMiddlewaresServer([]middleware.Middleware, *configv1.Customize) []middleware.Middleware
	// NewMiddlewareClient build middleware
	NewMiddlewareClient(name string, config *configv1.Customize_Config) (middleware.Middleware, error)
	// NewMiddlewareServer build middleware
	NewMiddlewareServer(name string, config *configv1.Customize_Config) (middleware.Middleware, error)
}

MiddlewareBuilders middleware builders for runtime

type RegistrarBuildFunc

type RegistrarBuildFunc func(cfg *configv1.Registry) (registry.Registrar, error)

RegistrarBuildFunc is a function type that takes a *config.RegistryConfig and returns a registry.Registrar and an error.

func (RegistrarBuildFunc) NewRegistrar

func (fn RegistrarBuildFunc) NewRegistrar(cfg *configv1.Registry) (registry.Registrar, error)

NewRegistrar is a method that calls the RegistrarBuildFunc with the given config.

type RegistryBuilder

type RegistryBuilder interface {
	NewRegistrar(cfg *configv1.Registry) (registry.Registrar, error)
	NewDiscovery(cfg *configv1.Registry) (registry.Discovery, error)
}

RegistryBuilder is an interface that defines methods for creating a Discovery and a Registrar.

type ServiceBuilder added in v0.0.7

type ServiceBuilder interface {
	NewGRPCServer(cfg *configv1.Service, opts ...config.ServiceSetting) (*service.GRPCServer, error)
	NewHTTPServer(cfg *configv1.Service, opts ...config.ServiceSetting) (*service.HTTPServer, error)
	NewGRPCClient(ctx context.Context, cfg *configv1.Service, opts ...config.ServiceSetting) (*service.GRPCClient, error)
	NewHTTPClient(ctx context.Context, cfg *configv1.Service, opts ...config.ServiceSetting) (*service.HTTPClient, error)
}

ServiceBuilder is an interface that defines a method for creating a new service.

Directories

Path Synopsis
Package bootstrap implements the functions, types, and interfaces for the module.
Package bootstrap implements the functions, types, and interfaces for the module.
Package config implements the functions, types, and interfaces for the module.
Package config implements the functions, types, and interfaces for the module.
Package customize implements the functions, types, and interfaces for the module.
Package customize implements the functions, types, and interfaces for the module.
Package data implements the functions, types, and interfaces for the module.
Package data implements the functions, types, and interfaces for the module.
gen
kratos module
Package log implements the functions, types, and interfaces for the module.
Package log implements the functions, types, and interfaces for the module.
Package mail implements the functions, types, and interfaces for the module.
Package mail implements the functions, types, and interfaces for the module.
Package middleware implements the functions, types, and interfaces for the module.
Package middleware implements the functions, types, and interfaces for the module.
Package registry implements the functions, types, and interfaces for the module.
Package registry implements the functions, types, and interfaces for the module.
Package service implements the functions, types, and interfaces for the module.
Package service implements the functions, types, and interfaces for the module.
grpc
Package grpc implements the functions, types, and interfaces for the module.
Package grpc implements the functions, types, and interfaces for the module.
http
Package grpc implements the functions, types, and interfaces for the module.
Package grpc implements the functions, types, and interfaces for the module.
selector
Package selector implements the functions, types, and interfaces for the module.
Package selector implements the functions, types, and interfaces for the module.
transport
gins
Package gins is a gin extension package.
Package gins is a gin extension package.
Package upload is the http multipart upload package
Package upload is the http multipart upload package
Package validate implements the functions, types, and interfaces for the module.
Package validate 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