proxy

package
Version: v6.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

README

proxy

A plugin for handling unknown calling or pushing.

Demo
package main

import (
	"time"

	tp "github.com/henrylee2cn/teleport/v6"
	"github.com/henrylee2cn/teleport/v6/plugin/proxy"
)

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

func newUnknownProxy() tp.Plugin {
	cli := tp.NewPeer(tp.PeerConfig{RedialTimes: 3})
	var sess tp.Session
	var stat *tp.Status
DIAL:
	sess, stat = cli.Dial(":9090")
	if !stat.OK() {
		tp.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) tp.Plugin

NewCallPlugin creates a proxy plugin for handling unknown calling.

func NewPlugin

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

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

func NewPushPlugin

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

NewPushPlugin creates a proxy plugin for handling unknown pushing.

Types

type CallForwarder

type CallForwarder interface {
	Call(uri string, arg interface{}, result interface{}, setting ...tp.MessageSetting) tp.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 ...tp.MessageSetting) *tp.Status
}

PushForwarder the object used to push

Source Files

Jump to

Keyboard shortcuts

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