proxy

package module
v0.0.5 Latest Latest
Warning

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

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

README

cod-proxy

Build Status

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

package main

import (
	"net/url"

	"github.com/vicanso/cod"

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

func main() {
	d := cod.New()

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

	d.GET("/*url", proxy.New(proxy.Config{
		Target: target,
		Host:   "www.baidu.com",
	}))

	d.ListenAndServe(":7001")
}

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func New

func New(config Config) cod.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      cod.Skipper
}

Config proxy config

type Done added in v0.0.4

type Done func(*cod.Context)

Done http proxy done callback

type TargetPicker

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

TargetPicker target picker function

Jump to

Keyboard shortcuts

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