gps package - github.com/Crtrpt/gps - Go Packages

gps

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: GPL-3.0 Imports: 20 Imported by: 0

README

golang proxy server

Go

golang 实现的外网代理回调服务器 主要让外网访问内网api用途

运行

git clone git@github.com:Crtrpt/gps.git
cd gps
go mod tidy
go run cmd/gps/main.go

流程图

流程图

特性

  • ssh隧道代理
  • 本地代理
  • 远程代理

问题

  • 增加完善的测试用例
  • static 安全访问
  • ssh不稳定问题 断开的问题
  • 文档
  • 错误处理的问题
  • 增加对udp tcp的支持

注意

如果需要sshd远程隧道 需要开启 sshd 隧道功能 否则无法监听外部端口 当前只支持key访问

GatewayPorts yes

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigFile *string

Functions

func GetTransportLayer

func GetTransportLayer(protocol string) string

func InitFlag

func InitFlag()

Types

type App

type App struct {
	Config       *Config
	ProxyMapLock *sync.Mutex
	ProxyList    []*ProxyConfig
	SSHTunnelMap map[string]any //ssh 隧道
	ListenMap    map[string]any //http 代理
}

func NewApp

func NewApp(ctx context.Context) *App

func (*App) Do

func (app *App) Do(resp http.ResponseWriter, r *http.Request, cfg *ProxyConfig, url, RequestURI string) (err error)

func (*App) InitConfig

func (app *App) InitConfig(ctx context.Context) (res any, err error)

func (*App) ListenHttpPort

func (app *App) ListenHttpPort(scheme string, cfg ProxyConfig, urlp *url.URL)

监听本地端口

func (*App) ListenSSHTunnel

func (app *App) ListenSSHTunnel(cfg ProxyConfig)

func (*App) ProxyBackend

func (app *App) ProxyBackend(resp http.ResponseWriter, r *http.Request, cfg *ProxyConfig, frontendUrl, RequestURI string) (err error)

判断对后端文件的代理

func (*App) ProxyStatic

func (app *App) ProxyStatic(resp http.ResponseWriter, r *http.Request, cfg *ProxyConfig, frontUrl, RequestURI string) bool

判断对静态文件的代理

func (*App) Reload

func (app *App) Reload(ctx context.Context) (res any, err error)

Reload 重启

func (*App) Run

func (app *App) Run(ctx context.Context) (res any, err error)

Run 执行

func (*App) ServeHTTP

func (app *App) ServeHTTP(resp http.ResponseWriter, r *http.Request)

func (*App) Stop

func (app *App) Stop(ctx context.Context) (res any, err error)

Stop 停止执行

type Config

type Config struct {
	Proxy map[string]ProxyConfig `toml:"proxy"`
}

type Interrupt

type Interrupt interface {
	Run() error
	SetHeader(key string, val any)
	Do(resp http.ResponseWriter, r *http.Request, cfg *ProxyConfig, url, RequestURI string)
}

type JavaScriptInterrupt

type JavaScriptInterrupt struct {
	Script *otto.Script
	Vm     *otto.Otto
}

func NewJavascriptVm

func NewJavascriptVm(cfg *ProxyConfig) (*JavaScriptInterrupt, error)

func (*JavaScriptInterrupt) Run

func (vm *JavaScriptInterrupt) Run(app *App, resp http.ResponseWriter, req *http.Request, cfg *ProxyConfig, url, RequestURI string) error

type ProxyConfig

type ProxyConfig struct {
	Name      string
	Url       string            //要代理的地址
	Proxy     string            //代理请求的地址
	Header    map[string]string //输出的header
	Hook      map[string]string //各种hook的能力
	Root      string            //静态文件目录 如果不存在 访问proxy的 后端服务器
	Interrupt string            //中断文件路径
	Ssh       struct {
		Auth       string //password key
		Host       string
		UserName   string //用户名
		Password   string //密码
		PrivateKey string //私钥登陆
		Addr       string //要监听的地址
	} `toml:"ssh"`
}

Directories

Path Synopsis
cmd
gps command

Jump to

Keyboard shortcuts

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