proxy

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

README

elton-proxy

Build Status

Proxy middleware for elton, it can proxy http request to other host.

package main

import (
	"net/url"

	"github.com/vicanso/elton"

	proxy "github.com/vicanso/elton-proxy"
)

func main() {
	e := elton.New()

	target, _ := url.Parse("https://www.baidu.com")

	e.GET("/*url", proxy.New(proxy.Config{
		// proxy done will call this function
		Done: func(c *elton.Context) {

		},
		// http request url rewrite
		Rewrites: []string{
			"/api/*:/$1",
		},
		Target: target,
		// change the request host
		Host:   "www.baidu.com",
	}))

	err := e.ListenAndServe(":3000")
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

View Source
const (
	// ErrCategory proxy error category
	ErrCategory = "elton-proxy"
)

Variables

This section is empty.

Functions

func New

func New(config Config) elton.Handler

New create a proxy middleware

Types

type Config

type Config struct {
	// Done proxy done callback
	Done         Done
	Target       *url.URL
	Rewrites     []string
	Host         string
	Transport    *http.Transport
	TargetPicker TargetPicker
	Skipper      elton.Skipper
}

Config proxy config

type Done

type Done func(*elton.Context)

Done http proxy done callback

type TargetPicker

type TargetPicker func(c *elton.Context) (*url.URL, Done, error)

TargetPicker target picker function

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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