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
28
main.go
28
main.go
|
@ -220,21 +220,31 @@ func getBestThumbnail(path string) (newpath string) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
socket := "socket" + string(os.PathSeparator) + "http-proxy.sock"
|
||||
syscall.Unlink(socket)
|
||||
listener, err := net.Listen("unix", socket)
|
||||
port := os.Getenv("PORT")
|
||||
|
||||
srv := &http.Server{
|
||||
ReadTimeout: 5 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
Addr: ":8080",
|
||||
Addr: ":" + port, // Won't be used if listening on a file socket
|
||||
Handler: &requesthandler{},
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println("Failed to bind to UDS, falling back to TCP/IP")
|
||||
fmt.Println(err.Error())
|
||||
srv.ListenAndServe()
|
||||
} else {
|
||||
|
||||
if port == "" {
|
||||
socket := "socket" + string(os.PathSeparator) + "http-proxy.sock"
|
||||
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 {
|
||||
// Listen on port
|
||||
fmt.Println(fmt.Sprintf("Listening on port %s", port))
|
||||
srv.ListenAndServe()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue