aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-08-13 18:40:49 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-08-13 18:40:49 +0200
commit72ec551e6cb422531e543e3fb431324aed5ac025 (patch)
tree5919c6a20f64868ce7bad68c5094d4612accdb27
parent5f660b309bc695277c67223520499fcc13f3c59f (diff)
downloadlens-72ec551e6cb422531e543e3fb431324aed5ac025.tar.gz
lens-72ec551e6cb422531e543e3fb431324aed5ac025.tar.bz2
lens-72ec551e6cb422531e543e3fb431324aed5ac025.zip
feat: Add better tooling for running the project
* Add watch option for hot reload(ish). * Read from `.env` file. This make local development a bit easier since now can easily run the application with custom configuration.
-rw-r--r--Makefile26
-rw-r--r--README.md55
-rw-r--r--cmd/server/main.go8
3 files changed, 80 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index c1deac1..743c0fd 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,19 @@ GO_TEST=go test -v -timeout 100ms -shuffle on -parallel `nproc`
GO_BUILD=go build -v -ldflags '-w -s'
GO_RUN=go run -v
+# Development setup
+DB_TYPE?=sqlite
+DB_CON?=main.db
+LOG_LEVEL?=error
+SCHEDULER_COUNT?=`nproc`
+CACHE_PATH?=$(HOME)/cache
+AES_KEY?=`openssl rand -rand /dev/urandom 32 | base64`
+
+ifneq (,$(wildcard ./.env))
+ include .env
+ export
+endif
+
all: build
build: sass tmpl
@@ -19,9 +32,12 @@ compress_into_oblivion: build
run: sass
$(GO_RUN) $(SERVER) \
- --log-level error \
- --aes-key=6368616e676520746869732070617373 \
- --cache-path=${HOME}/.thumb
+ --db-type=$(DB_TYPE) \
+ --db-con="$(DB_CON)" \
+ --log-level=$(LOG_LEVEL) \
+ --scheduler-count=$(SCHEDULER_COUNT) \
+ --cache-path="$(CACHE_PATH)" \
+ --aes-key="$(AES_KEY)"
sass:
@mkdir -p static
@@ -75,3 +91,7 @@ gci:
alignment:
betteralign -apply ./...
+
+watch:
+ find . \( ! -name "*.qtpl.go" -a \( -name "*.go" -o -name "*.qtpl" -o -name "main.scss" \) \) | \
+ entr -sr 'make run'
diff --git a/README.md b/README.md
index a008d7f..256cfb3 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,59 @@
# Lens
A read only file explorer with media capabilities.
-
-# Dev requirements
+
+# Dev
+
+To run the project you simply need to run:
+
+```bash
+make run
+```
+
+It should run using sqlite with a randon AES key. But if you don't set a
+`AES_KEY` a new one will generated every time the project is realead and you
+will be logged out.
+
+You can also create a `.env` file which will be read by make to populate the
+environment variables, e.g.:
+
+```ini
+# .env
+DB_TYPE=psql
+DB_CON=host=localhost user=admin password=admin dbname=lens port=5432
+LOG_LEVEL=error
+SCHEDULER_COUNT=10
+CACHE_PATH=/home/myhome/.thumb
+AES_KEY=X4Eu3OT/WqUtUJhGLUtQ4xRahwhWYaSs+k2a03Kz1A8=
+```
+
+Obs.: don't quote the value, that will be done automatically.
+
+Throughout the development you can also run `make watch` for a hot reload
+experience. It will feedback loop a bit faster.
+
+## Build and install
+
+To build you simply run:
+```
+make
+```
+
+And a `./bin/lens` will be created.
+
+To install run:
+
+```
+make install
+```
+
+Or you can pass a custom target folder.
+
+```
+PREFIX=~/.local/ make install
+```
+
+# Requirements
## qtc
diff --git a/cmd/server/main.go b/cmd/server/main.go
index a3d5124..035d00a 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -2,7 +2,7 @@ package main
import (
"context"
- "encoding/hex"
+ "encoding/base64"
"errors"
"net/http"
"os"
@@ -66,7 +66,7 @@ func main() {
*schedulerCount = 1
}
- hexKey, err := hex.DecodeString(*key)
+ baseKey, err := base64.StdEncoding.DecodeString(*key)
if err != nil {
panic("failed to decode key database: " + err.Error())
}
@@ -84,7 +84,7 @@ func main() {
// middleware
var (
- authMiddleware = ext.NewAuthMiddleware(hexKey, logger.WithField("context", "auth"))
+ authMiddleware = ext.NewAuthMiddleware(baseKey, logger.WithField("context", "auth"))
logMiddleware = ext.NewLogMiddleare(logger.WithField("context", "http"))
initialMiddleware = ext.NewInitialSetupMiddleware(userRepository)
)
@@ -99,7 +99,7 @@ func main() {
// controller
var (
- userController = service.NewAuthController(userRepository, userRepository, hexKey)
+ userController = service.NewAuthController(userRepository, userRepository, baseKey)
fileSystemController = service.NewFileSystemController(fileSystemRepository, userRepository)
)