Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: use listen address instead of port, change default #49

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ COPY *.go ./

RUN go build -o /someguy

EXPOSE 8080

CMD [ "/someguy", "start", "--port", "8080" ]
Comment on lines -13 to -15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ removed defaults from Dockerfile. Rainbow did not have them, Someguy also should not.

CMD [ "/someguy", "start" ]
8 changes: 4 additions & 4 deletions docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
`someguy` ships with some implicit defaults that can be adjusted via env variables below.

- [Configuration](#configuration)
- [`SOMEGUY_PORT`](#someguy_port)
- [`SOMEGUY_LISTEN_ADDRESS`](#someguy_listen_address)
- [`SOMEGUY_ACCELERATED_DHT`](#someguy_accelerated_dht)
- [`SOMEGUY_PROVIDER_ENDPOINTS`](#someguy_provider_endpoints)
- [`SOMEGUY_PEER_ENDPOINTS`](#someguy_peer_endpoints)
Expand All @@ -16,11 +16,11 @@

## Configuration

### `SOMEGUY_PORT`
### `SOMEGUY_LISTEN_ADDRESS`

The port to listen on to.
The address to listen on.

Default: `8080`
Default: `127.0.0.1:8190`

### `SOMEGUY_ACCELERATED_DHT`

Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
{
Name: "start",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "port",
Value: 8080,
EnvVars: []string{"SOMEGUY_PORT"},
Usage: "port to serve requests on",
&cli.StringFlag{
Name: "listen-address",
Value: "127.0.0.1:8190",
EnvVars: []string{"SOMEGUY_LISTEN_ADDRESS"},
Usage: "listen address",

Check warning on line 29 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L25-L29

Added lines #L25 - L29 were not covered by tests
},
&cli.BoolFlag{
Name: "accelerated-dht",
Expand Down Expand Up @@ -54,7 +54,7 @@
},
},
Action: func(ctx *cli.Context) error {
return start(ctx.Context, ctx.Int("port"), ctx.Bool("accelerated-dht"), ctx.StringSlice("provider-endpoints"), ctx.StringSlice("peer-endpoints"), ctx.StringSlice("ipns-endpoints"))
return start(ctx.Context, ctx.String("listen-address"), ctx.Bool("accelerated-dht"), ctx.StringSlice("provider-endpoints"), ctx.StringSlice("peer-endpoints"), ctx.StringSlice("ipns-endpoints"))

Check warning on line 57 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L57

Added line #L57 was not covered by tests
},
},
{
Expand Down
15 changes: 10 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import (
"context"
"log"
"net"
"net/http"
"strconv"

"github.com/CAFxX/httpcompression"
"github.com/felixge/httpsnoop"
Expand Down Expand Up @@ -32,7 +32,7 @@
})
}

func start(ctx context.Context, port int, runAcceleratedDHTClient bool, contentEndpoints, peerEndpoints, ipnsEndpoints []string) error {
func start(ctx context.Context, listenAddress string, runAcceleratedDHTClient bool, contentEndpoints, peerEndpoints, ipnsEndpoints []string) error {

Check warning on line 35 in server.go

View check run for this annotation

Codecov / codecov/patch

server.go#L35

Added line #L35 was not covered by tests
h, err := newHost(runAcceleratedDHTClient)
if err != nil {
return err
Expand Down Expand Up @@ -68,8 +68,13 @@
return err
}

log.Printf("Listening on http://0.0.0.0:%d", port)
log.Printf("Delegated Routing API on http://127.0.0.1:%d/routing/v1", port)
_, port, err := net.SplitHostPort(listenAddress)
if err != nil {
return err
}

Check warning on line 74 in server.go

View check run for this annotation

Codecov / codecov/patch

server.go#L71-L74

Added lines #L71 - L74 were not covered by tests

log.Printf("Listening on %s", listenAddress)
log.Printf("Delegated Routing API on http://127.0.0.1:%s/routing/v1", port)

Check warning on line 77 in server.go

View check run for this annotation

Codecov / codecov/patch

server.go#L76-L77

Added lines #L76 - L77 were not covered by tests

mdlw := middleware.New(middleware.Config{
Recorder: metrics.NewRecorder(metrics.Config{Prefix: "someguy"}),
Expand Down Expand Up @@ -103,7 +108,7 @@

http.Handle("/debug/metrics/prometheus", promhttp.Handler())
http.Handle("/", handler)
server := &http.Server{Addr: ":" + strconv.Itoa(port), Handler: nil}
server := &http.Server{Addr: listenAddress, Handler: nil}

Check warning on line 111 in server.go

View check run for this annotation

Codecov / codecov/patch

server.go#L111

Added line #L111 was not covered by tests
return server.ListenAndServe()
}

Expand Down
Loading