Skip to content

Commit f2cbee1

Browse files
authored
Use Kong for CLI management and config retrieval
1 parent da2ec98 commit f2cbee1

File tree

9 files changed

+137
-120
lines changed

9 files changed

+137
-120
lines changed

Diff for: README.md

+37-27
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ Environment="LIB_PATH=<absolute path to the library>"
5959

6060
then, start the service with `service coreander start`. You can manage it with the usual commands `start`, `stop` and `status`. Refer to your service manager documentation for more information.
6161

62-
Coreander requires a `LIB_PATH` environment variable to be set, which tells the application where your documents are located.
62+
Coreander requires the absolute path where your documents are located as an argument. You can also pass it through the `LIB_PATH` environment variable.
6363

6464
On first run, Coreander will index the documents in your library, creating a database with those entries located at `$home/coreander/index`. Depending on your system's performance and the size of your library this may take a while. Also, the database can grow fairly big, so make sure you have enough free space on disk.
6565

66-
Every time is run, the application scans the library folder only for documents not yet indexed and adds them to the index. You can force to index all documents wether they were previously indexed or not by setting the environment variable `FORCE_INDEXING` to `true`.
66+
Every time is run, the application scans the library folder only for documents not yet indexed and adds them to the index. You can force to index all documents wether they were previously indexed or not by passing the `--force-indexing` flag or setting the environment variable `FORCE_INDEXING` to `true`.
6767

68-
Even if the application is still indexing entries, you can access its web interface right away. Just open a web browser and go to `localhost:3000` (replace `localhost` with the hostname / IP address of the machine where the server is running if you want to access it from another system). It is possible to change the listening port just executing the application with the `PORT` environment variable (e. g. `PORT=4000 coreander`)
68+
Even if the application is still indexing entries, you can access its web interface right away. Just open a web browser and go to `localhost:3000` (replace `localhost` with the hostname / IP address of the machine where the server is running if you want to access it from another system). It is possible to change the listening port just executing the application with the `-p` or `--port` flags, or the `PORT` environment variable (e. g. `coreander -p 4000` or `PORT=4000 coreander`)
6969

7070
### Setting up an Internet-facing server
7171

@@ -88,12 +88,14 @@ Some features rely on having an SMTP email service set up, and won't be availabl
8888
* Send document to email.
8989
* Recover user password.
9090

91-
You can use any email service that allow sending emails using the SMTP protocol, like [GMX](https://gmx.com/mail). The following environment variables need to be defined:
91+
You can use any email service that allow sending emails using the SMTP protocol, like [GMX](https://gmx.com/mail). The following flags or environment variables need to be defined:
9292

93-
* `SMTP_SERVER`: The URL of the SMTP server to be used, for example `mail.gmx.com`.
94-
* `SMTP_PORT`: The port number used by the email service, defaults to `587`.
95-
* `SMTP_USER`: The user name.
96-
* `SMTP_PASSWORD`: User's password.
93+
|Flag|Environment variable|Description|
94+
|----|--------------------|-----------|
95+
|`--smtp-server` | `SMTP_SERVER` | The URL of the SMTP server to be used, for example `mail.gmx.com`.|
96+
|`--smtp-port` | `SMTP_PORT` | The port number used by the email service, defaults to `587`. |
97+
|`--smtp-user` | `SMTP_USER` | The user name. |
98+
|`--smtp-password`| `SMTP_PASSWORD`| User's password. |
9799

98100
#### Send to email
99101

@@ -103,7 +105,7 @@ Coreander can send documents through email. This way, you can take advantage of
103105

104106
Coreander distinguish between two kinds of users: regular users and administrator users, with the latter being the only ones with the ability to create new users and upload and delete documents.
105107

106-
By default, Coreander allow unrestricted access to its contents, except management areas which require an administrator user. To allow access only to registered users in the whole application, pass the `REQUIRE_AUTH=true` environment variable.
108+
By default, Coreander allow unrestricted access to its contents, except management areas which require an administrator user. To allow access only to registered users in the whole application, pass the `-a` or `--require-auth` flags, or the `REQUIRE_AUTH=true` environment variable.
107109

108110
On first run, Coreander creates an admin user with the following credentials:
109111

@@ -114,23 +116,31 @@ On first run, Coreander creates an admin user with the following credentials:
114116

115117
### Settings
116118

117-
* `LIB_PATH`: Absolute path to the folder containing the documents.
118-
* `PORT`: Port number in which the webserver listens for requests. Defaults to 3000.
119-
* `BATCH_SIZE`: Number of documents persisted by the indexer in one write operation. Defaults to 100.
120-
* `COVER_MAX_WIDTH`: Maximum horizontal size for documents cover thumbnails in pixels. Defaults to 600.
121-
* `FORCE_INDEXING`: Whether to force indexing already indexed documents or not. Defaults to false.
122-
* `SMTP_SERVER`: Address of the send mail server.
123-
* `SMTP_PORT`: Port number of the send mail server. Defaults to 587.
124-
* `SMTP_USER`: User to authenticate against the SMTP server.
125-
* `SMTP_PASSWORD`: User's password to authenticate against the SMTP server.
126-
* `JWT_SECRET`: String to use to sign JWTs.
127-
* `REQUIRE_AUTH`: Require authentication to access the application if true. Defaults to false.
128-
* `MIN_PASSWORD_LENGTH`: Minimum length acceptable for passwords. Defaults to 5.
129-
* `WORDS_PER_MINUTE`: Defines a default words per minute reading speed that will be used for not logged-in users. Defaults to 250.
130-
* `SESSION_TIMEOUT`: Specifies the maximum time a user session may last, in hours. Floating-point values are allowed. Defaults to 24 hours.
131-
* `RECOVERY_TIMEOUT`: Specifies the maximum time a user recovery link may last, in hours. Floating-point values are allowed. Defaults to 2 hours.
132-
* `UPLOAD_DOCUMENT_MAX_SIZE`: Maximum document size allowed to be uploaded to the library, in megabytes. Set this to 0 to unlimit upload size. Defaults to 20 megabytes.
133-
* `FQDN`: Domain name of the server. If Coreander is listening to a non-standard HTTP / HTTPS port, include it using a colon (e. g. example.com:3000). Defaults to `localhost`.
119+
Run `coreander -h` or `coreander --help` to see help.
120+
121+
In case both a flag and its equivalent environment variable are passed, flag takes precendence.
122+
123+
|Flag|Environment variable|Description|
124+
|----|--------------------|-----------|
125+
|`--lib-path` |`LIB_PATH` | Absolute path to the folder containing the documents.
126+
|`-p` or `--port` |`PORT` | Port number in which the webserver listens for requests. Defaults to 3000.
127+
|`-b` or `--batch-size` |`BATCH_SIZE` | Number of documents persisted by the indexer in one write operation. Defaults to 100.
128+
|`--cover-max-width` |`COVER_MAX_WIDTH` | Maximum horizontal size for documents cover thumbnails in pixels. Defaults to 600.
129+
|`-f` or `--force-indexing` |`FORCE_INDEXING` | Whether to force indexing already indexed documents or not. Defaults to false.
130+
|`--smtp-server` |`SMTP_SERVER` | Address of the send mail server.
131+
|`--smtp-port` |`SMTP_PORT` | Port number of the send mail server. Defaults to 587.
132+
|`--smtp-user` |`SMTP_USER` | User to authenticate against the SMTP server.
133+
|`--smtp-password` |`SMTP_PASSWORD` | User's password to authenticate against the SMTP server.
134+
|`-s` or `--jwt-secret` |`JWT_SECRET` | String to use to sign JWTs.
135+
|`-a` or `--require-auth` |`REQUIRE_AUTH` | Require authentication to access the application if true. Defaults to false.
136+
|`--min-password-length` |`MIN_PASSWORD_LENGTH` | Minimum length acceptable for passwords. Defaults to 5.
137+
|`--words-per-minute` |`WORDS_PER_MINUTE` | Defines a default words per minute reading speed that will be used for not logged-in users. Defaults to 250.
138+
|`--session-timeout` |`SESSION_TIMEOUT` | Specifies the maximum time a user session may last, in hours. Floating-point values are allowed. Defaults to 24 hours.
139+
|`--recovery-timeout` |`RECOVERY_TIMEOUT` | Specifies the maximum time a user recovery link may last, in hours. Floating-point values are allowed. Defaults to 2 hours.
140+
|`-u` or `--upload-document-max-size` |`UPLOAD_DOCUMENT_MAX_SIZE`| Maximum document size allowed to be uploaded to the library, in megabytes. Set this to 0 to unlimit upload size. Defaults to 20 megabytes.
141+
|`-d` or `--fqdn` |`FQDN` | Domain name of the server. If Coreander is listening to a non-standard HTTP / HTTPS port, include it using a colon (e. g. example.com:3000). Defaults to `localhost`.
142+
|`-v` or `--version` | | Show version number.
143+
134144

135145
## Screenshots
136146

@@ -139,4 +149,4 @@ On first run, Coreander creates an admin user with the following credentials:
139149
![Document detail in dark mode](doc-detail.png)
140150
*Document detail in dark mode*
141151
![Reading interface](reading.png)
142-
*Reading interface*
152+
*Reading interface*

Diff for: cli_input.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import "github.com/alecthomas/kong"
4+
5+
// CLIInput stores all configuration flags and arguments thant can be passed to the application
6+
type CLIInput struct {
7+
Version kong.VersionFlag `short:"v" name:"version" help:"Get version number."`
8+
// LibPath holds the absolute path to the folder containing the documents
9+
LibPath string `arg:"" env:"LIB_PATH" help:"Absolute path to the folder containing the documents." type:"path"`
10+
// FQDN stores the domain name of the server. If the server is listening on a non-standard HTTP / HTTPS port, include it using a colon (e. g. example.com:3000)
11+
FQDN string `env:"FQDN" short:"d" default:"localhost" name:"fqdn" help:"Domain name of the server. If the server is listening on a non-standard HTTP / HTTPS port, include it using a colon (e. g. example:3000)"`
12+
// Port defines the port number in which the webserver listens for requests
13+
Port int `env:"PORT" short:"p" default:"3000" help:"Port number in which the webserver listens for requests"`
14+
// BatchSize indicates the number of documents persisted by the indexer in one operation
15+
BatchSize int `env:"BATCH_SIZE" short:"b" default:"100" name:"batch-size" help:"Number of documents persisted by the indexer in one operation"`
16+
// CoverMaxWidth sets the maximum horizontal size for documents cover thumbnails in pixels
17+
CoverMaxWidth int `env:"COVER_MAX_WIDTH" default:"600" name:"cover-max-width" help:"Maximum horizontal size for documents cover thumbnails in pixels"`
18+
// ForceIndexing signals whether to force indexing already indexed documents or not
19+
ForceIndexing bool `env:"FORCE_INDEXING" short:"f" default:"false" name:"force-indexing" help:"Force indexing already indexed documents"`
20+
// SmtpServer points to the address of the send mail server
21+
SmtpServer string `env:"SMTP_SERVER" name:"smtp-server" help:"Address of the send mail server"`
22+
// SmtpPort defines the port in which the mail server listens for requests
23+
SmtpPort int `env:"SMTP_PORT" default:"587" name:"smtp-port" help:"Port in which the mail server listens for requests"`
24+
// SmtpUser holds the user to authenticate against the SMTP server
25+
SmtpUser string `env:"SMTP_USER" name:"smtp-user" help:"User to authenticate against the SMTP server"`
26+
// SmtpUser holds the password to authenticate against the SMTP server
27+
SmtpPassword string `env:"SMTP_PASSWORD" name:"smtp-password" help:"Password to authenticate against the SMTP server"`
28+
// JwtSecret stores the string to use to sign JWTs
29+
JwtSecret string `env:"JWT_SECRET" short:"s" name:"jwt-secret" help:"String to use to sign JWTs"`
30+
// RequireAuth is a switch to enable the application to require authentication to access any route if true
31+
RequireAuth bool `env:"REQUIRE_AUTH" short:"a" default:"false" name:"require-auth" help:"Require authentication to access any route"`
32+
// MinPasswordLength is the minimum length acceptable for passwords
33+
MinPasswordLength int `env:"MIN_PASSWORD_LENGTH" default:"5" name:"min-password-length" help:"Minimum length acceptable for passwords"`
34+
// WordsPerMinute defines a default words per minute reading speed that will be used for not logged-in users
35+
WordsPerMinute float64 `env:"WORDS_PER_MINUTE" default:"250" name:"words-per-minute" help:"Default words per minute reading speed that will be used for not logged-in users"`
36+
// SessionTimeout specifies the maximum time a user session may last in hours
37+
SessionTimeout float64 `env:"SESSION_TIMEOUT" default:"24" name:"session-timeout" help:"Maximum time a user session may last in hours"`
38+
// RecoveryTimeout specifies the maximum time a user recovery link may last in hours
39+
RecoveryTimeout float64 `env:"RECOVERY_TIMEOUT" default:"2" name:"recovery-timeout" help:"Maximum time a user recovery link may last in hours"`
40+
// UploadDocumentMaxSize is the maximum document size allowed to be uploaded to the library, in megabytes.
41+
// Set this to 0 to unlimit upload size. Defaults to 20 megabytes.
42+
UploadDocumentMaxSize int `env:"UPLOAD_DOCUMENT_MAX_SIZE" short:"u" default:"20" name:"upload-document-max-size" help:"Maximum document size allowed to be uploaded to the library, in megabytes. Set this to 0 to unlimit upload size."`
43+
}

Diff for: config.go

-40
This file was deleted.

Diff for: go.mod

+1-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.23
55
toolchain go1.23.0
66

77
require (
8+
github.com/alecthomas/kong v1.6.1
89
github.com/blevesearch/bleve/v2 v2.4.4
910
github.com/bmatcuk/doublestar/v4 v4.7.1
1011
github.com/glebarez/sqlite v1.11.0
@@ -14,7 +15,6 @@ require (
1415
github.com/golang-jwt/jwt/v4 v4.5.1
1516
github.com/google/uuid v1.6.0
1617
github.com/hhrutter/tiff v1.0.1
17-
github.com/ilyakaznacheev/cleanenv v1.5.0
1818
github.com/kovidgoyal/imaging v1.6.3
1919
github.com/magefile/mage v1.15.0
2020
github.com/microcosm-cc/bluemonday v1.0.27
@@ -60,7 +60,6 @@ require (
6060
)
6161

6262
require (
63-
github.com/BurntSushi/toml v1.4.0 // indirect
6463
github.com/PuerkitoBio/goquery v1.10.1
6564
github.com/RoaringBitmap/roaring v1.9.4 // indirect
6665
github.com/andybalholm/brotli v1.1.1 // indirect
@@ -87,7 +86,6 @@ require (
8786
github.com/golang/snappy v0.0.4 // indirect
8887
github.com/gorilla/css v1.0.1 // indirect
8988
github.com/gosimple/slug v1.15.0
90-
github.com/joho/godotenv v1.5.1 // indirect
9189
github.com/json-iterator/go v1.1.12 // indirect
9290
github.com/klauspost/compress v1.17.11 // indirect
9391
github.com/mattn/go-colorable v0.1.13 // indirect
@@ -108,6 +106,4 @@ require (
108106
golang.org/x/sys v0.29.0 // indirect
109107
google.golang.org/protobuf v1.36.2 // indirect
110108
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
111-
gopkg.in/yaml.v3 v3.0.1 // indirect
112-
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect
113109
)

0 commit comments

Comments
 (0)