From 230326db908ce4ffd30902277715693477f3c3b9 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 29 Feb 2024 11:59:57 +0100 Subject: [PATCH] feat: configure server with env variables --- README.md | 2 + docs/environment-variables.md | 100 ++++++++++++++++++++++++++++++++++ main.go | 39 +++++++------ 3 files changed, 124 insertions(+), 17 deletions(-) create mode 100644 docs/environment-variables.md diff --git a/README.md b/README.md index 6bc2443..0c10ee0 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ $ docker pull ghcr.io/ipfs/someguy:main-latest $ docker run --rm -it --net=host -e ghcr.io/ipfs/someguy:main-latest ``` +See [`/docs/environment-variables.md`](./docs/environment-variables.md). + ## Build ```bash diff --git a/docs/environment-variables.md b/docs/environment-variables.md new file mode 100644 index 0000000..ee0f160 --- /dev/null +++ b/docs/environment-variables.md @@ -0,0 +1,100 @@ +# Someguy Environment Variables + +`someguy` ships with some implicit defaults that can be adjusted via env variables below. + +- [Configuration](#configuration) + - [`SOMEGUY_PORT`](#someguy_port) + - [`SOMEGUY_ACCELERATED_DHT`](#someguy_accelerated_dht) + - [`SOMEGUY_PROVIDER_ENDPOINTS`](#someguy_provider_endpoints) + - [`SOMEGUY_PEER_ENDPOINTS`](#someguy_peer_endpoints) + - [`SOMEGUY_IPNS_ENDPOINTS`](#someguy_ipns_endpoints) +- [Logging](#logging) + - [`GOLOG_LOG_LEVEL`](#golog_log_level) + - [`GOLOG_LOG_FMT`](#golog_log_fmt) + - [`GOLOG_FILE`](#golog_file) + - [`GOLOG_TRACING_FILE`](#golog_tracing_file) + +## Configuration + +### `SOMEGUY_PORT` + +The port to listen on to. + +Default: `8080` + +### `SOMEGUY_ACCELERATED_DHT` + +Whether or not the Accelerated DHT is enabled or not. + +Default: `true` + +### `SOMEGUY_PROVIDER_ENDPOINTS` + +Comma-separated list of other Delegated Routing V1 endpoints to proxy provider requests to. + +Default: `https://cid.contact` + +### `SOMEGUY_PEER_ENDPOINTS` + +Comma-separated list of other Delegated Routing V1 endpoints to proxy peer requests to. + +Default: none + +### `SOMEGUY_IPNS_ENDPOINTS` + +Comma-separated list of other Delegated Routing V1 endpoints to proxy IPNS requests to. + +Default: none + +## Logging + +### `GOLOG_LOG_LEVEL` + +Specifies the log-level, both globally and on a per-subsystem basis. Level can +be one of: + +* `debug` +* `info` +* `warn` +* `error` +* `dpanic` +* `panic` +* `fatal` + +Per-subsystem levels can be specified with `subsystem=level`. One global level +and one or more per-subsystem levels can be specified by separating them with +commas. + +Default: `error` + +Example: + +```console +GOLOG_LOG_LEVEL="error,someguy=debug" someguy +``` + +### `GOLOG_LOG_FMT` + +Specifies the log message format. It supports the following values: + +- `color` -- human readable, colorized (ANSI) output +- `nocolor` -- human readable, plain-text output. +- `json` -- structured JSON. + +For example, to log structured JSON (for easier parsing): + +```bash +export GOLOG_LOG_FMT="json" +``` +The logging format defaults to `color` when the output is a terminal, and +`nocolor` otherwise. + +### `GOLOG_FILE` + +Sets the file to which the logs are saved. By default, they are printed to the standard error output. + +### `GOLOG_TRACING_FILE` + +Sets the file to which the tracing events are sent. By default, tracing is disabled. + +Warning: Enabling tracing will likely affect performance. diff --git a/main.go b/main.go index b694801..626c008 100644 --- a/main.go +++ b/main.go @@ -23,29 +23,34 @@ func main() { Name: "start", Flags: []cli.Flag{ &cli.IntFlag{ - Name: "port", - Usage: "port to serve requests on", - Value: 8080, + Name: "port", + Value: 8080, + EnvVars: []string{"SOMEGUY_PORT"}, + Usage: "port to serve requests on", }, &cli.BoolFlag{ - Name: "accelerated-dht", - Usage: "run the accelerated DHT client", - Value: true, + Name: "accelerated-dht", + Value: true, + EnvVars: []string{"SOMEGUY_ACCELERATED_DHT"}, + Usage: "run the accelerated DHT client", }, &cli.StringSliceFlag{ - Name: "provider-endpoints", - Usage: "other Delegated Routing V1 endpoints to proxy provider requests to", - Value: cli.NewStringSlice(cidContactEndpoint), + Name: "provider-endpoints", + Value: cli.NewStringSlice(cidContactEndpoint), + EnvVars: []string{"SOMEGUY_PROVIDER_ENDPOINTS"}, + Usage: "other Delegated Routing V1 endpoints to proxy provider requests to", }, &cli.StringSliceFlag{ - Name: "peer-endpoints", - Usage: "other Delegated Routing V1 endpoints to proxy peer requests to", - Value: cli.NewStringSlice(), + Name: "peer-endpoints", + Value: cli.NewStringSlice(), + EnvVars: []string{"SOMEGUY_PEER_ENDPOINTS"}, + Usage: "other Delegated Routing V1 endpoints to proxy peer requests to", }, &cli.StringSliceFlag{ - Name: "ipns-endpoints", - Usage: "other Delegated Routing V1 endpoints to proxy IPNS requests to", - Value: cli.NewStringSlice(), + Name: "ipns-endpoints", + Value: cli.NewStringSlice(), + EnvVars: []string{"SOMEGUY_IPNS_ENDPOINTS"}, + Usage: "other Delegated Routing V1 endpoints to proxy IPNS requests to", }, }, Action: func(ctx *cli.Context) error { @@ -57,13 +62,13 @@ func main() { Flags: []cli.Flag{ &cli.StringFlag{ Name: "endpoint", - Usage: "the Delegated Routing V1 endpoint to ask", Value: cidContactEndpoint, + Usage: "the Delegated Routing V1 endpoint to ask", }, &cli.BoolFlag{ Name: "pretty", - Usage: "output data in a prettier format that may convey less information", Value: false, + Usage: "output data in a prettier format that may convey less information", }, }, Subcommands: []*cli.Command{