demo

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 15 Imported by: 0

README

tRPC-Gateway Gateway Demo Plugin

This is a gateway plugin example that can be used as a template to quickly develop your own gateway plugins for your business.

Note that this documentation currently only applies to the development of plugins for the HTTP protocol, which is the main supported protocol of tRPC-Gateway.

Prerequisite Knowledge:

Usage Instructions

Import the Plugin in the main.go file of the Gateway Project
  • Add the import statement
import (
    _ "trpc.group/trpc-go/trpc-gateway/plugin/demo"
)
  • trpc_go.yaml framework configuration file, enable the demo 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 handler functions
  service:                          # Business services provided, can have multiple
    - name: trpc.inews.trpc.gateway      # Route name of the service
      filter:
        - demo                      # Gateway plugin registered as a filter in the service, so that it can be dynamically loaded in router.yaml
plugins:                            # Plugin configuration
  log:                              # Log configuration
  gateway:                          # Plugin type is gateway
    demo:                           # Name of the CORS plugin

Configure the plugin in the gateway routing configuration router.yaml, supporting global, service, and router-level plugin configurations.

router: # Routing configuration
  - method: /v1/user/info
    target_service:
      - service: trpc.user.service
    plugins:
      - name: demo
        props:
          suid_name: xxx
client: # Upstream service configuration, follows the tRPC protocol
  - name: trpc.user.service
    plugins:
      - name: request_transformer  # Service-level configuration, will be effective for all interfaces forwarded to this service
        props:
plugins:
  - name: demo                      # Global configuration, will be effective for all interfaces
    props:

Documentation

Overview

Package demo is an example of developing a gateway plugin. You can refer to this example to develop your own plugin.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServerFilter

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

ServerFilter Server-side interceptor

Types

type Options

type Options struct {
	// Parameter name for receiving suid in the proxy interface
	SUIDName string `yaml:"suid_name"`
}

Options Configuration for the authentication plugin. Here, a separate configuration object needs to be defined.

type Plugin

type Plugin struct{}

Plugin Signature verification plugin

func (*Plugin) CheckConfig

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

CheckConfig verifies the plugin configuration and returns the parsed configuration object. Used in the ServerFilter method for parsing.

func (*Plugin) DependsOn

func (p *Plugin) DependsOn() []string

DependsOn Dependent plugins, such as: config-etcd

func (*Plugin) Setup

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

Setup Plugin initialization

func (*Plugin) Type

func (p *Plugin) Type() string

Type Get the plugin type

Jump to

Keyboard shortcuts

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