little bit different approach
This commit is contained in:
parent
6b2b48c5ff
commit
214cda122c
@ -3,37 +3,43 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.pbiernat.dev/golang/ngkrok/internal/ngkrok"
|
|
||||||
vhost "github.com/inconshreveable/go-vhost"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
addr, host, port := "::", "hop.pbiernat.dev", "18181"
|
// addr, host, port := "::", "hop.pbiernat.dev", "18181"
|
||||||
|
|
||||||
lst, err := net.Listen("tcp", net.JoinHostPort(addr, port))
|
// lst, err := net.Listen("tcp", net.JoinHostPort(addr, port))
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Fatal(err)
|
// log.Fatal(err)
|
||||||
}
|
// }
|
||||||
|
|
||||||
vmux, err := vhost.NewHTTPMuxer(lst, 3*time.Second)
|
// vmux, err := vhost.NewHTTPMuxer(lst, 3*time.Second)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Fatal(err)
|
// log.Fatal(err)
|
||||||
}
|
// }
|
||||||
defer vmux.Close()
|
// defer vmux.Close()
|
||||||
|
|
||||||
srv := ngkrok.NewServer(addr, host, port, vmux)
|
// srv := ngkrok.NewServer(addr, host, port, vmux)
|
||||||
go srv.Serve()
|
// go srv.Serve()
|
||||||
|
|
||||||
log.Printf("NgKrok server [%s] ready!\n", host)
|
// log.Printf("NgKrok server [%s] ready!\n", host)
|
||||||
|
|
||||||
for {
|
// for {
|
||||||
conn, err := vmux.NextError()
|
// conn, err := vmux.NextError()
|
||||||
fmt.Println("vmux error:", err)
|
// fmt.Println("vmux error:", err)
|
||||||
if conn != nil {
|
// if conn != nil {
|
||||||
conn.Close()
|
// conn.Close()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
port := ":18181"
|
||||||
|
|
||||||
|
reverseProxy := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
fmt.Printf("[reverse proxy server] received request at: %s\n", time.Now())
|
||||||
|
})
|
||||||
|
|
||||||
|
fmt.Printf("Server started at %s\n", port)
|
||||||
|
log.Fatal(http.ListenAndServe(port, reverseProxy))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user