mirror of
https://github.com/TeamPiped/http3-ytproxy.git
synced 2024-08-14 23:56:43 +00:00
Add the ability to listen on a port
This commit is contained in:
parent
f3ef98fbfe
commit
61bdcb10c3
1 changed files with 20 additions and 10 deletions
30
main.go
30
main.go
|
@ -220,21 +220,31 @@ func getBestThumbnail(path string) (newpath string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
socket := "socket" + string(os.PathSeparator) + "http-proxy.sock"
|
port := os.Getenv("PORT")
|
||||||
syscall.Unlink(socket)
|
|
||||||
listener, err := net.Listen("unix", socket)
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
ReadTimeout: 5 * time.Second,
|
ReadTimeout: 5 * time.Second,
|
||||||
WriteTimeout: 10 * time.Second,
|
WriteTimeout: 10 * time.Second,
|
||||||
Addr: ":8080",
|
Addr: ":" + port, // Won't be used if listening on a file socket
|
||||||
Handler: &requesthandler{},
|
Handler: &requesthandler{},
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Failed to bind to UDS, falling back to TCP/IP")
|
if port == "" {
|
||||||
fmt.Println(err.Error())
|
socket := "socket" + string(os.PathSeparator) + "http-proxy.sock"
|
||||||
srv.ListenAndServe()
|
syscall.Unlink(socket)
|
||||||
|
listener, err := net.Listen("unix", socket)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
fmt.Println(fmt.Sprintf("Listening on %s", socket))
|
||||||
|
defer listener.Close()
|
||||||
|
srv.Serve(listener)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintln(os.Stderr, err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
defer listener.Close()
|
// Listen on port
|
||||||
srv.Serve(listener)
|
fmt.Println(fmt.Sprintf("Listening on port %s", port))
|
||||||
|
srv.ListenAndServe()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue