2026-07-17 21:20:39 +08:00
|
|
|
|
# coconut-leaf Backend
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
The backend service of coconut-leaf,
|
|
|
|
|
|
implemented with [Go](https://go.dev/) + [Gin](https://gin-gonic.com/),
|
|
|
|
|
|
migrated from the old Python Flask backend.
|
|
|
|
|
|
The data layer executes SQL directly (no ORM).
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
> [!NOTE]
|
|
|
|
|
|
> Currently only SQLite is fully implemented.
|
|
|
|
|
|
> MySQL interfaces are placeholders (all endpoints return "not implemented" errors).
|
|
|
|
|
|
|
|
|
|
|
|
## Requirements
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
|
|
|
|
|
- **Go >= 1.26**
|
2026-07-17 21:20:39 +08:00
|
|
|
|
- **C compiler (cgo)**: The SQLite driver [`mattn/go-sqlite3`](https://github.com/mattn/go-sqlite3) requires CGO feature.
|
|
|
|
|
|
- Windows: MSYS2's gcc is recommended.
|
|
|
|
|
|
- Linux / macOS: System-provided gcc / clang works.
|
|
|
|
|
|
- Ensure `CGO_ENABLED=1` before building (usually enabled by default when a C compiler is available).
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
## Build
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
In the `backend/` directory:
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
|
go build -o coconut-leaf
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
> [!NOTE]
|
2026-07-17 21:20:39 +08:00
|
|
|
|
> The first build compiles SQLite C source code; 1–3 minutes is normal.
|
|
|
|
|
|
>
|
|
|
|
|
|
> On Windows, executables built with MSYS2 depend on MSYS2 runtime libraries
|
|
|
|
|
|
> (I use MSYS2 UCRT64, so it may include `libgcc_s_*`, `libwinpthread-1.dll`, etc.).
|
|
|
|
|
|
> Either add the DLL directory to PATH or copy those DLLs next to the executable.
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
## Configuration
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
Uses TOML format, specified via `-config` parameter.
|
|
|
|
|
|
See the full template at [coconut-leaf.template.toml](../assets/coconut-leaf.template.toml) in the `assets` directory.
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
## Command-line Arguments
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
| Argument | Description |
|
2026-07-17 16:44:57 +08:00
|
|
|
|
| --- | --- |
|
2026-07-17 21:20:39 +08:00
|
|
|
|
| `-config <PATH>` | **Required**, path to the TOML configuration file |
|
|
|
|
|
|
| `-init` | Initialize the system: create tables and the first admin user |
|
|
|
|
|
|
| `-username <NAME>` | Used with `-init`, the initial admin username |
|
|
|
|
|
|
| `-password <PASS>` | Used with `-init`, the initial admin password |
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
`-username` / `-password` are required only when `-init` is specified and are validated
|
|
|
|
|
|
(username: `[0-9A-Za-z]+`, password: all visible ASCII characters, i.e., `[!-~]+`).
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
## Initialization and Runtime
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
### First Deployment
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
First deployment includes creating tables and the admin user, then running as usual:
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
|
./coconut-leaf --config coconut-leaf.toml --init --username admin --password "your-password"
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
### Normal Runtime
|
2026-07-17 16:44:57 +08:00
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
|
./coconut-leaf --config coconut-leaf.toml
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2026-07-17 21:20:39 +08:00
|
|
|
|
After starting, it listens on `web.port`.
|
|
|
|
|
|
Debug logs are written to stderr in the format `[<time>] [<level>] <message> [key=value ...]`.
|