refactor: enhance NewClient to support environment variable fallback and add tests
This commit is contained in:
@@ -7,7 +7,11 @@ Go client library and CLI for the [Mail-in-a-Box](https://mailinabox.email/) adm
|
||||
```go
|
||||
import miab "gitea.koszewscy.waw.pl/koszewscy/mailinabox-go"
|
||||
|
||||
c := miab.NewClient("box.example.com", "admin@example.com", "password")
|
||||
// Explicit credentials:
|
||||
c, err := miab.NewClient("box.example.com", "admin@example.com", "password")
|
||||
|
||||
// From environment variables (MIAB_* or MAILINABOX_* style):
|
||||
c, err := miab.NewClient("", "", "")
|
||||
|
||||
c.SetRecord("foo.example.com", "TXT", "v=spf1 ~all")
|
||||
c.AddRecord("foo.example.com", "A", "1.2.3.4")
|
||||
@@ -18,18 +22,30 @@ records, _ := c.ListRecords("TXT")
|
||||
|
||||
## CLI
|
||||
|
||||
Install:
|
||||
Install from registry:
|
||||
|
||||
```sh
|
||||
go install gitea.koszewscy.waw.pl/koszewscy/mailinabox-go/cmd/miab@latest
|
||||
```
|
||||
|
||||
Credentials via environment variables:
|
||||
Build locally:
|
||||
|
||||
```sh
|
||||
go build -o miab ./cmd/miab
|
||||
```
|
||||
|
||||
Credentials via environment variables (either style is accepted):
|
||||
|
||||
```sh
|
||||
# MIAB style
|
||||
export MIAB_HOST=box.example.com
|
||||
export MIAB_USERNAME=admin@example.com
|
||||
export MIAB_PASSWORD=password
|
||||
|
||||
# Mail-in-a-Box style
|
||||
export MAILINABOX_BASE_URL=https://box.example.com
|
||||
export MAILINABOX_EMAIL=admin@example.com
|
||||
export MAILINABOX_PASSWORD=password
|
||||
```
|
||||
|
||||
Commands:
|
||||
|
||||
Reference in New Issue
Block a user