Skip to content

Commit 6e12187

Browse files
committed
feat: configure server with env variables
1 parent f6f7c9e commit 6e12187

File tree

3 files changed

+124
-17
lines changed

3 files changed

+124
-17
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ $ docker pull ghcr.io/ipfs/someguy:main-latest
2929
$ docker run --rm -it --net=host -e ghcr.io/ipfs/someguy:main-latest
3030
```
3131

32+
See [`/docs/environment-variables.md`](./docs/environment-variables.md).
33+
3234
## Build
3335

3436
```bash

docs/environment-variables.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Someguy Environment Variables
2+
3+
`someguy` ships with some implicit defaults that can be adjusted via env variables below.
4+
5+
- [Configuration](#configuration)
6+
- [`SOMEGUY_PORT`](#someguy_port)
7+
- [`SOMEGUY_ACCELERATED_DHT`](#someguy_accelerated_dht)
8+
- [`SOMEGUY_PROVIDER_ENDPOINTS`](#someguy_provider_endpoints)
9+
- [`SOMEGUY_PEER_ENDPOINTS`](#someguy_peer_endpoints)
10+
- [`SOMEGUY_IPNS_ENDPOINTS`](#someguy_ipns_endpoints)
11+
- [Logging](#logging)
12+
- [`GOLOG_LOG_LEVEL`](#golog_log_level)
13+
- [`GOLOG_LOG_FMT`](#golog_log_fmt)
14+
- [`GOLOG_FILE`](#golog_file)
15+
- [`GOLOG_TRACING_FILE`](#golog_tracing_file)
16+
17+
## Configuration
18+
19+
### `SOMEGUY_PORT`
20+
21+
The port to listen on to.
22+
23+
Default: `8080`
24+
25+
### `SOMEGUY_ACCELERATED_DHT`
26+
27+
Whether or not the Accelerated DHT is enabled or not.
28+
29+
Default: `true`
30+
31+
### `SOMEGUY_PROVIDER_ENDPOINTS`
32+
33+
Comma-separated list of other Delegated Routing V1 endpoints to proxy provider requests to.
34+
35+
Default: `https://cid.contact`
36+
37+
### `SOMEGUY_PEER_ENDPOINTS`
38+
39+
Comma-separated list of other Delegated Routing V1 endpoints to proxy peer requests to.
40+
41+
Default: none
42+
43+
### `SOMEGUY_IPNS_ENDPOINTS`
44+
45+
Comma-separated list of other Delegated Routing V1 endpoints to proxy IPNS requests to.
46+
47+
Default: none
48+
49+
## Logging
50+
51+
### `GOLOG_LOG_LEVEL`
52+
53+
Specifies the log-level, both globally and on a per-subsystem basis. Level can
54+
be one of:
55+
56+
* `debug`
57+
* `info`
58+
* `warn`
59+
* `error`
60+
* `dpanic`
61+
* `panic`
62+
* `fatal`
63+
64+
Per-subsystem levels can be specified with `subsystem=level`. One global level
65+
and one or more per-subsystem levels can be specified by separating them with
66+
commas.
67+
68+
Default: `error`
69+
70+
Example:
71+
72+
```console
73+
GOLOG_LOG_LEVEL="error,someguy=debug" someguy
74+
```
75+
76+
### `GOLOG_LOG_FMT`
77+
78+
Specifies the log message format. It supports the following values:
79+
80+
- `color` -- human readable, colorized (ANSI) output
81+
- `nocolor` -- human readable, plain-text output.
82+
- `json` -- structured JSON.
83+
84+
For example, to log structured JSON (for easier parsing):
85+
86+
```bash
87+
export GOLOG_LOG_FMT="json"
88+
```
89+
The logging format defaults to `color` when the output is a terminal, and
90+
`nocolor` otherwise.
91+
92+
### `GOLOG_FILE`
93+
94+
Sets the file to which the logs are saved. By default, they are printed to the standard error output.
95+
96+
### `GOLOG_TRACING_FILE`
97+
98+
Sets the file to which the tracing events are sent. By default, tracing is disabled.
99+
100+
Warning: Enabling tracing will likely affect performance.

main.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,34 @@ func main() {
2323
Name: "start",
2424
Flags: []cli.Flag{
2525
&cli.IntFlag{
26-
Name: "port",
27-
Usage: "port to serve requests on",
28-
Value: 8080,
26+
Name: "port",
27+
Value: 8080,
28+
EnvVars: []string{"SOMEGUY_PORT"},
29+
Usage: "port to serve requests on",
2930
},
3031
&cli.BoolFlag{
31-
Name: "accelerated-dht",
32-
Usage: "run the accelerated DHT client",
33-
Value: true,
32+
Name: "accelerated-dht",
33+
Value: true,
34+
EnvVars: []string{"SOMEGUY_ACCELERATED_DHT"},
35+
Usage: "run the accelerated DHT client",
3436
},
3537
&cli.StringSliceFlag{
36-
Name: "provider-endpoints",
37-
Usage: "other Delegated Routing V1 endpoints to proxy provider requests to",
38-
Value: cli.NewStringSlice(cidContactEndpoint),
38+
Name: "provider-endpoints",
39+
Value: cli.NewStringSlice(cidContactEndpoint),
40+
EnvVars: []string{"SOMEGUY_PROVIDER_ENDPOINTS"},
41+
Usage: "other Delegated Routing V1 endpoints to proxy provider requests to",
3942
},
4043
&cli.StringSliceFlag{
41-
Name: "peer-endpoints",
42-
Usage: "other Delegated Routing V1 endpoints to proxy peer requests to",
43-
Value: cli.NewStringSlice(),
44+
Name: "peer-endpoints",
45+
Value: cli.NewStringSlice(),
46+
EnvVars: []string{"SOMEGUY_PEER_ENDPOINTS"},
47+
Usage: "other Delegated Routing V1 endpoints to proxy peer requests to",
4448
},
4549
&cli.StringSliceFlag{
46-
Name: "ipns-endpoints",
47-
Usage: "other Delegated Routing V1 endpoints to proxy IPNS requests to",
48-
Value: cli.NewStringSlice(),
50+
Name: "ipns-endpoints",
51+
Value: cli.NewStringSlice(),
52+
EnvVars: []string{"SOMEGUY_IPNS_ENDPOINTS"},
53+
Usage: "other Delegated Routing V1 endpoints to proxy IPNS requests to",
4954
},
5055
},
5156
Action: func(ctx *cli.Context) error {
@@ -57,13 +62,13 @@ func main() {
5762
Flags: []cli.Flag{
5863
&cli.StringFlag{
5964
Name: "endpoint",
60-
Usage: "the Delegated Routing V1 endpoint to ask",
6165
Value: cidContactEndpoint,
66+
Usage: "the Delegated Routing V1 endpoint to ask",
6267
},
6368
&cli.BoolFlag{
6469
Name: "pretty",
65-
Usage: "output data in a prettier format that may convey less information",
6670
Value: false,
71+
Usage: "output data in a prettier format that may convey less information",
6772
},
6873
},
6974
Subcommands: []*cli.Command{

0 commit comments

Comments
 (0)