Skip to content

Commit

Permalink
Use net.JoinHostPort and some refactoring (#7)
Browse files Browse the repository at this point in the history
* main: use net.JoinHostPort

Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>

* main: use fmt.Fprintln

Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>

* main: use errors.Is

Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
  • Loading branch information
zchee committed Dec 16, 2021
1 parent a0eb45b commit e62b5db
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"context"
"errors"
"flag"
"fmt"
"net"
Expand Down Expand Up @@ -53,7 +54,7 @@ var (

func main() {
if err := realMain(); err != nil {
fmt.Fprint(os.Stderr, err.Error(), "\n")
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}
Expand Down Expand Up @@ -87,7 +88,7 @@ func realMain() error {
}
bind := &url.URL{
Scheme: "http",
Host: bindHost + ":" + bindPort,
Host: net.JoinHostPort(bindHost, bindPort),
}

// Construct the proxy.
Expand All @@ -103,7 +104,7 @@ func realMain() error {
errCh := make(chan error, 1)
go func() {
fmt.Fprintf(os.Stderr, "%s proxies to %s\n", bind, host)
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
select {
case errCh <- err:
default:
Expand Down

0 comments on commit e62b5db

Please sign in to comment.