proxy

package
v6.3.5 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2021 License: Apache-2.0 Imports: 7 Imported by: 7

README

proxy

A plugin for handling unknown calling or pushing.

Demo
package main

import (
	"time"

	"github.com/henrylee2cn/erpc/v6"
	"github.com/henrylee2cn/erpc/v6/plugin/proxy"
)

func main() {
	defer erpc.FlushLogger()
	srv := erpc.NewPeer(
		erpc.PeerConfig{
			ListenPort: 8080,
		},
		newUnknownProxy(),
	)
	srv.ListenAndServe()
}

func newUnknownProxy() erpc.Plugin {
	cli := erpc.NewPeer(erpc.PeerConfig{RedialTimes: 3})
	var sess erpc.Session
	var stat *erpc.Status
DIAL:
	sess, stat = cli.Dial(":9090")
	if !stat.OK() {
		erpc.Warnf("%v", stat)
		time.Sleep(time.Second * 3)
		goto DIAL
	}
	return proxy.NewPlugin(func(*proxy.Label) proxy.Forwarder {
		return sess
	})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCallPlugin

func NewCallPlugin(fn func(*Label) CallForwarder) erpc.Plugin

NewCallPlugin creates a proxy plugin for handling unknown calling.

func NewPlugin

func NewPlugin(fn func(*Label) Forwarder) erpc.Plugin

NewPlugin creates a proxy plugin for handling unknown calling and pushing.

func NewPushPlugin

func NewPushPlugin(fn func(*Label) PushForwarder) erpc.Plugin

NewPushPlugin creates a proxy plugin for handling unknown pushing.

Types

type CallForwarder

type CallForwarder interface {
	Call(uri string, arg interface{}, result interface{}, setting ...erpc.MessageSetting) erpc.CallCmd
}

CallForwarder the object used to call

type Forwarder

type Forwarder interface {
	CallForwarder
	PushForwarder
}

Forwarder the object used to call and push

type Label

type Label struct {
	SessionID, RealIP, ServiceMethod string
}

Label proxy label information

type PushForwarder

type PushForwarder interface {
	Push(uri string, arg interface{}, setting ...erpc.MessageSetting) *erpc.Status
}

PushForwarder the object used to push

Jump to

Keyboard shortcuts

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