devenv

package module
v0.0.0-...-5c29987 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 14 Imported by: 0

README

Development Environment Configuration Plugin

To address the issue of multiple environments, this plugin can be configured to specify the target environment for forwarding based on the "request-domain" request header.

Technical Solution

img.png The plugin maintains a list of environment configurations, supporting all fields in the tRPC client, such as namespace, env_name, set_name, etc. The "disable_servicerouter" field is set to true.

Plugin Usage

  • This plugin is designed for offline environments and is not recommended for use in production as it may affect service stability.
  • It can be used in conjunction with the mocking plugin to provide an API for querying the environment list, allowing flexible environment switching on the client side.
  • The response will include the "X-Proxy-Env" header for easy debugging.
    • Example value: target=polaris://trpc.inews.service&namespace=Development&env_name=f9283c03&set_name=
Importing the Plugin in the Gateway Project's main.go
  • Add the import statement
import (
 _ "trpc.group/trpc-go/trpc-gateway/plugin/devenv"
)
  • tRPC framework configuration file, enable the devenv interceptor.

Note: Make sure to register it under server.service.filter, not server.filter.

global:                             # Global configuration
server:                             # Server configuration
  filter:                          # Interceptor list for all service handlers
  service:                          # Business services provided, can have multiple
    - name: trpc.inews.trpc.gateway      # Service routing name
      filter:
        - devenv # Gateway plugin registered under service.filter, so that it can be dynamically loaded in router.yaml
plugins:                            # Plugin configuration
  log:                              # Log configuration
  gateway:                          # Plugin type is gateway
    devenv:                         # Devenv plugin
      env_key: request-domain       # Request parameter name that identifies the environment, default is request-domain
Configuring the Plugin in the Gateway's router.yaml File

Plugins at different levels will only be executed once, with the priority order: router plugin > service plugin > global plugin

router:                             # Router configuration
  - method: /v1/user/info
    id: "xxxxxx"
    target_service:
      - service: trpc.user.service
    plugins:
      - name: devenv                # Router-level plugin
        props:
          env_list:
            - request_domain: grey.epc.webdev.com   # Environment identifier
              disable: false                         # Whether to disable this environment
              namespace: Production
              env_name: formal                       # Environment name, same as env_name in trpc client
              target: "polaris://xxxx"               # Target service, same as target in trpc client
              set_name: ""                           # Set name, same as set_name in trpc client
client:                             # Upstream service configuration, follows the trpc protocol
  - name: trpc.user.service
    plugins:
      - name: devenv                # Service-level configuration
        props:
          - request_domain: grey.epc.webdev.com
            disable: false                         # Whether to disable this environment
            env_name: formal
            namespace: Production
            set_name: ""
            target: ""
plugins:
  - name: devenv                    # Global configuration
    props:
      - request_domain: grey.epc.webdev.com
        disable: false                         # Whether to disable this environment
        env_name: formal
        namespace: Production
        set_name: ""
        target: ""
Configuring the Plugin using the Console

img.png

Documentation

Overview

Package devenv provides the ability to configure the development environment

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnvConfig

type EnvConfig struct {
	// Personal environment name, usually the English name of the enterprise micro
	RequestDomain string `yaml:"request_domain"`
	// Whether to enable
	Disable              bool `yaml:"disable"`
	client.BackendConfig `yaml:",inline"`
}

EnvConfig is environment configuration

type EnvHandler

type EnvHandler struct {
	EnvKey string
}

EnvHandler is environment handler object

func (*EnvHandler) ServerFilter

func (ehl *EnvHandler) ServerFilter(ctx context.Context, req interface{},
	handler filter.ServerHandleFunc) (interface{}, error)

ServerFilter executes plugin logic

type Options

type Options struct {
	EnvList []*EnvConfig `yaml:"env_list"`
}

Options is plugin configuration

type Plugin

type Plugin struct {
	// Parameter name that identifies the environment
	EnvKey string `yaml:"env_key"`
}

Plugin is plugin definition

func (*Plugin) CheckConfig

func (p *Plugin) CheckConfig(_ string, decoder plugin.Decoder) error

CheckConfig validate the plugin configuration and return the parsed configuration object. Used in the ServerFilter method for parsing.

func (*Plugin) Setup

func (p *Plugin) Setup(_ string, decoder plugin.Decoder) error

Setup Plugin initialization plugin

func (*Plugin) Type

func (p *Plugin) Type() string

Type return plugin type

Jump to

Keyboard shortcuts

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