Fixed lint issues and missing documentation
This commit is contained in:
1 parent
7fd321df97
commit
6e6dec68c0
34 files changed
+346
-156
No files matched your search
@@ -33,10 +33,10 @@ is kept.
|
||||
| Key | Type | Default | Notes |
|
||||
|---|---|---|---|
|
||||
| `logging.level` | string | `warn` | One of `debug`, `info`, `warn`, `error` |
|
||||
| `logging.file` | string | | Log file for `fetch service` (unless `--foreground`) |
|
||||
| `logging.file` | string | | Log file for `fetch service` (unless `--foreground`); other commands log to the terminal |
|
||||
| `sources.<source>.enabled` | bool | `false` | For every source |
|
||||
| `sources.<source>.interval` | duration | `10m` | For every source; e.g. `30s`, `1h` |
|
||||
| `sources.find_a_tender.api_root` | string | URL of the Find A Tender service API. Currently `https://www.find-tender.service.gov.uk/api/1.0` | |
|
||||
| `sources.find_a_tender.api_root` | string | `https://www.find-tender.service.gov.uk/api/1.0` | URL of the Find a Tender API |
|
||||
| `sources.fts_mock.api_root` | string | | URL of the mock FTS server (see `internal/mock`) |
|
||||
| `sources.sleeper.block_shutdown` | bool | `false` | Test source: if true, its sleep ignores shutdown |
|
||||
|
||||
@@ -73,14 +73,20 @@ per key:
|
||||
`section.key`. An embedded struct has its fields promoted, as Go does;
|
||||
every source embeds `JobSearchConfigSource` for `enabled` and `interval`.
|
||||
- `time.Duration` fields report `reflect.String` from `TypeOf`, accept either a
|
||||
`time.Duration` or a duration string in `SetValue`, and are written as
|
||||
strings (`"10m0s"`) by `Map`, `JSON` and `YAML`.
|
||||
`time.Duration` or a duration string in `SetValue`, and are given out as
|
||||
strings (`"10m0s"`) by `Map`, `Flatten` and `ValueOf`, and so by `JSON`,
|
||||
`YAML` and `String` too.
|
||||
- A section can reject values by implementing `validate(key, value) error` on
|
||||
its pointer type. `JobSearchConfigLogging` does this for `level`.
|
||||
|
||||
Each section type has the same small set of methods, each a one-line call into
|
||||
`section.go`: `Map`, `Flatten`, `TypeOf`, `ValueOf` and `SetValue`, plus
|
||||
`Keys` on some.
|
||||
Every section implements the `Section` interface defined in `section.go`:
|
||||
`Map`, `Flatten`, `TypeOf`, `ValueOf` and `SetValue`, each a one-line call into
|
||||
`section.go` (some sections also have `Keys`). The methods sit under a
|
||||
`// ---------- Section methods (see Section) ----------` banner in each
|
||||
section's file. `TestSections` walks `JobSearchConfig` and checks every
|
||||
section, including embedded ones, implements `Section` and that its
|
||||
`Flatten` keys match its `cfg` tag, so a new section is checked without being
|
||||
listed anywhere.
|
||||
|
||||
|
||||
## Adding a key or section
|
||||
@@ -90,11 +96,14 @@ else is needed for it to be loaded, printed, and read or written by the
|
||||
|
||||
To add a new section:
|
||||
1. Create a `conf_*.go` file with the section struct, a `JSCK*` constant for
|
||||
its key, and the standard methods (copy an existing section).
|
||||
its key, and an implementation of `Section` (copy an existing section's
|
||||
methods).
|
||||
2. Add the struct as a tagged field of its parent: `JobSearchConfig` in
|
||||
`config.go`, or `JobSearchConfigSources` in `conf_sources.go` for a source,
|
||||
etc. The field's `cfg` tag must match the `JSCK*` constant.
|
||||
|
||||
Nothing in `section.go` needs changing.
|
||||
|
||||
|
||||
## API
|
||||
- `Init(cfgFile, &conf)`: load the configuration, as described above.
|
||||
@@ -119,7 +128,7 @@ To add a new section:
|
||||
| `config.go` | `JobSearchConfig`, defaults, Viper loading, text output |
|
||||
| `load.go` | `Init`, `.env` and config file loading |
|
||||
| `modify.go` | `StoreValue` and `PurgeValue` |
|
||||
| `section.go` | Struct tag reflection shared by every section |
|
||||
| `section.go` | The `Section` interface and the struct tag reflection shared by every section |
|
||||
| `conf_logging.go` | `logging` section and log level helpers |
|
||||
| `conf_sources.go` | `sources` section and the shared source fields |
|
||||
| `conf_source_*.go` | One file per source section |
|
||||
|
||||
Reference in new issue
Block a user