runtime

package module
v0.1.35 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: MIT Imports: 13 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.

The Runtime controls the resources required when a project is started, including configuration files, logs, monitoring, caches, and databases.

Before You Start

Before you start using the Runtime package, ensure that you have the following prerequisites: In order to prevent import conflicts caused by packages with the same name as kratos, packages with the same name in this database will import the export content from kratos. All type definitions will be prefixed with the K fixed prefix. Note: Only type declarations are prefixed, not functions.

Available Packages
  • bootstrap: The bootstrap package contains Configuration file reading and writing, initialization variable declaration, etc
  • config: The files in this directory define the basic configuration of the service runtime, as well as the loading of the run configuration.
  • context: The context directory defines the context interface and the context implementation.
  • data: The data directory defines the data interface, caching, database, and other storage implementation.
  • gen: The protobuf directory contains the definition of the protobuf protocol.
  • 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.
  • mail: The mail directory defines the email interface and the email implementation.
  • middleware: The middleware directory defines the middleware interface and the middleware
  • registry: This directory defines an alias for 'kratos/v2/registry', primarily for backward compatibility and for placing import error paths.
  • service: The service directory contains the definition of the service interface, which is used to define the interface of the service and the implementation of the service.

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 provides functions for loading configurations and registering services.

Index

Constants

View Source
const (
	DefaultEnvPrefix = "ORIGADMIN_RUNTIME_SERVICE"
)

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.OptionSetting) (config.KConfig, error)

NewConfig creates a new Selector using the registered ConfigBuilder.

func NewDiscovery

func NewDiscovery(cfg *configv1.Registry, ss ...registry.OptionSetting) (registry.KDiscovery, error)

NewDiscovery creates a new discovery using the registered RegistryBuilder.

func NewGRPCServiceClient

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

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

func NewGRPCServiceServer

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

NewGRPCServiceServer creates a new GRPC server using the provided configuration

func NewHTTPServiceClient

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

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

func NewHTTPServiceServer

func NewHTTPServiceServer(cfg *configv1.Service, ss ...service.OptionSetting) (*service.HTTPServer, error)

NewHTTPServiceServer creates a new HTTP server using the provided configuration

func NewMiddlewareClient

func NewMiddlewareClient(name string, cm *configv1.Customize_Config, ss ...middleware.OptionSetting) (middleware.KMiddleware, error)

NewMiddlewareClient creates a new KMiddleware with the builder.

func NewMiddlewareServer

func NewMiddlewareServer(name string, cm *configv1.Customize_Config, ss ...middleware.OptionSetting) (middleware.KMiddleware, error)

NewMiddlewareServer creates a new KMiddleware with the builder.

func NewMiddlewaresClient

func NewMiddlewaresClient(cc *configv1.Customize, ss ...middleware.OptionSetting) []middleware.KMiddleware

NewMiddlewaresClient creates a new KMiddleware with the builder.

func NewMiddlewaresServer

func NewMiddlewaresServer(cc *configv1.Customize, ss ...middleware.OptionSetting) []middleware.KMiddleware

NewMiddlewaresServer creates a new KMiddleware with the builder.

func NewRegistrar

func NewRegistrar(cfg *configv1.Registry, ss ...registry.OptionSetting) (registry.KRegistrar, error)

NewRegistrar creates a new KRegistrar using the registered RegistryBuilder.

func RegisterConfig

func RegisterConfig(name string, factory config.Factory)

RegisterConfig registers a ConfigBuilder with the builder.

func RegisterConfigFunc

func RegisterConfigFunc(name string, buildFunc config.BuildFunc)

RegisterConfigFunc registers a ConfigBuilder with the builder.

func RegisterConfigSync

func RegisterConfigSync(name string, syncFunc ConfigSyncFunc)

func RegisterMiddleware

func RegisterMiddleware(name string, middlewareBuilder MiddlewareBuilder)

RegisterMiddleware registers a MiddlewareBuilder with the builder.

func RegisterRegistry

func RegisterRegistry(name string, factory registry.Factory)

RegisterRegistry registers a RegistryBuilder with the builder.

func RegisterService

func RegisterService(name string, factory service.Factory)

RegisterService registers a service builder with the provided name

func SyncConfig

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

SyncConfig synchronizes the given configuration with the given value.

Types

type Builder

type Builder interface {
	config.Builder
	registry.Builder
	service.Builder
	MiddlewareBuilders
	// contains filtered or unexported methods
}

func Global

func Global() Builder

Global returns the global instance of the builder.

func NewBuilder added in v0.1.15

func NewBuilder() Builder

NewBuilder creates a new Builder.

type ConfigSyncFunc

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

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

func (ConfigSyncFunc) SyncConfig

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

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

type MiddlewareBuildFunc

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

MiddlewareBuildFunc is an interface that defines methods for creating middleware.

type MiddlewareBuilder

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

MiddlewareBuilder middleware builder interface

type MiddlewareBuilders

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

MiddlewareBuilders middleware builders for runtime

type Runtime added in v0.1.15

type Runtime struct {
	Debug       bool
	EnvPrefix   string
	WorkDir     string
	Application application.Application
	Logging     log.Logging
	Config      config.Config
	Registry    registry.Registry
	Middleware  middleware.Middleware
	Service     service.Service
	// contains filtered or unexported fields
}

func New

func New() Runtime

func (*Runtime) Build added in v0.1.27

func (r *Runtime) Build(rr registry.Registry, servers ...transport.Server) *kratos.App

func (*Runtime) Load added in v0.1.27

func (r *Runtime) Load() error

Directories

Path Synopsis
Package agent implements the functions, types, and interfaces for the module.
Package agent implements the functions, types, and interfaces for the module.
middleware/security
Package security implements the functions, types, and interfaces for the module.
Package security implements the functions, types, and interfaces for the module.
Package application implements the functions, types, and interfaces for the module.
Package application implements the functions, types, and interfaces for the module.
Package bootstrap is a package that provides the bootstrap information for the service.
Package bootstrap is a package that provides the bootstrap information for the service.
Package config implements the functions, types, and interfaces for the module.
Package config implements the functions, types, and interfaces for the module.
Package context provides the context functions
Package context provides the context functions
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.
Package fileupload implements the functions, types, and interfaces for the module.
Package fileupload implements the functions, types, and interfaces for the module.
gen
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.
empty
Package empty implements the functions, types, and interfaces for the module.
Package empty implements the functions, types, and interfaces for the module.
optimize
Package optimize implements the functions, types, and interfaces for the module.
Package optimize 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.
validate
Package validate implements the functions, types, and interfaces for the module.
Package validate 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 builder implements the functions, types, and interfaces for the module.
Package builder 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 http implements the functions, types, and interfaces for the module.
Package http 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.

Jump to

Keyboard shortcuts

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