proxy

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2021 License: MIT Imports: 3 Imported by: 1

README

proxy

Package proxy routes an HTTP request to target server.

Get started

Install
go get github.com/hslam/handler
Import
import "github.com/hslam/handler"
Usage
Example
package main

import (
	"github.com/hslam/handler/proxy"
	"github.com/hslam/mux"
	"log"
	"net/http"
)

func main() {
	go func() {
		m := mux.New()
		m.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
			w.Write([]byte("hello from 8081"))
		}).All()
		log.Fatal(http.ListenAndServe(":8081", m))
	}()
	m := mux.New()
	m.HandleFunc("/proxy", func(w http.ResponseWriter, r *http.Request) {
		proxy.Proxy(w, r, "http://localhost:8081/hello")
	}).All()
	log.Fatal(http.ListenAndServe(":8080", m))
}

curl http://localhost:8080/proxy

hello from 8081
License

This package is licensed under a MIT license (Copyright (c) 2019 Meng Huang)

Author

proxy was written by Meng Huang.

Documentation

Index

Constants

View Source
const MaxConnsPerHost = 16384

Variables

This section is empty.

Functions

func Proxy

func Proxy(w http.ResponseWriter, r *http.Request, targetUrl string)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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