diff --git a/.air.toml b/.air.toml new file mode 100644 index 0000000..2f2e011 --- /dev/null +++ b/.air.toml @@ -0,0 +1,52 @@ +root = "." +testdata_dir = "testdata" +tmp_dir = "tmp" + +[build] +args_bin = [] +bin = "./tmp/main" +cmd = "go build -o ./tmp/main ." +delay = 1000 +exclude_dir = ["assets", "tmp", "vendor", "testdata", "scripts"] +exclude_file = [] +exclude_regex = ["_test.go"] +exclude_unchanged = false +follow_symlink = false +full_bin = "" +include_dir = [] +include_ext = ["go", "tpl", "tmpl", "html", "css", "js", "svg", "png"] +include_file = [] +kill_delay = "0s" +log = "build-errors.log" +poll = false +poll_interval = 0 +post_cmd = [] +pre_cmd = [] +rerun = false +rerun_delay = 500 +send_interrupt = false +stop_on_error = false + +[color] +app = "" +build = "yellow" +main = "magenta" +runner = "green" +watcher = "cyan" + +[log] +main_only = false +silent = false +time = false + +[misc] +clean_on_exit = false + +[proxy] +app_port = 8169 +enabled = true +proxy_port = 8170 + +[screen] +clear_on_rebuild = false +keep_scroll = true diff --git a/.gitignore b/.gitignore index e44b9f1..3d51441 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .direnv .env .storage -result \ No newline at end of file +result +tmp \ No newline at end of file diff --git a/README.md b/README.md index e393cc5..be2dabe 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,45 @@ yeah 4 of em.. ## Developing -use `nix shell` or `nix-shell` or maybe just run `go run .` or somethin its ok +highly recommended to use nix. its actually optional, but there's caveats. -please run `just precommit` before committing thx, it fixes weird build issues +**Quickstart** + +```sh +## - Step one, get an environment! +nix develop +# or +nix-shell +# or +direnv allow + +## - Step two, setup .env +cp .env.example .env +# fill out .env (the file has instructions) + +## - Step three, run the thing!! +just +# or .. maybe this.. but it may be unpredictable +go run . + +## - Step four, clean up the code +just precommit +``` + +> _the caveat: using `go` alone is doable. certain things won't happen, like dependency tagging and env var loading, so.. consider `nix`.._ + +### just commands + +- **watch** - (default) runs air livereloader + - open https://localhost:8170 for live reloading, note: the console will output 8169. that works too, but doesn't reload browser on changes +- **run** - runs the app with go run +- **nix-run** - runs the app built via nix (slower) +- **run-container** - builds the app as a docker image, then runs it. (slowest) +- **fmt** - go fmt and prettier +- **tidy** - fix gomods +- **test** - runs normal tests +- **update-vendor-hash** - updates `default.nix` vendorHash field, it won't build without it. +- **precommit** - runs fmt, tidy, update-vendor-hash, and test, in that order. ## Deploying diff --git a/interactions/interactions_test.go b/interactions/interactions_test.go index f16347b..1abfcb6 100644 --- a/interactions/interactions_test.go +++ b/interactions/interactions_test.go @@ -56,6 +56,8 @@ func TestPostHandler(t *testing.T) { func TestPostHandlerIntegration(t *testing.T) { i, dsm, key := makeInteractions(t) app := roleypoly.CreateFiberApp() + + // Tests that everything works including auth middleware sessionMiddleware, sessionStore := session.NewWithStore() sessionStore.RegisterType(authmiddleware.Session{}) app.Use(sessionMiddleware) diff --git a/justfile b/justfile index 1bea0d0..6e7217e 100644 --- a/justfile +++ b/justfile @@ -1,3 +1,6 @@ +watch: + air + run: go run . @@ -15,11 +18,13 @@ fmt: go fmt ./... tidy: - go clean -modcache go mod tidy update-vendor-hash: scripts/update-vendor-hash.sh test: - go test ./... \ No newline at end of file + go test ./... + +clean-repo: + rm -rf tmp result \ No newline at end of file diff --git a/main.go b/main.go index b75ce5f..a1ac032 100644 --- a/main.go +++ b/main.go @@ -20,9 +20,13 @@ func main() { roleypoly.SetupStatic(app) roleypoly.SetupControllers( app, - dc, - utils.DiscordPublicKey, - utils.PublicBaseURL, + roleypoly.ControllerConfig{ + DiscordClient: dc, + PublicKey: utils.DiscordPublicKey, + PublicBaseURL: utils.PublicBaseURL, + SupportIDs: utils.SupportIDs, + SuperuserIDs: utils.SupueruserIDs, + }, ) log.Fatal(app.Listen(utils.ListenAddr)) diff --git a/shell.nix b/shell.nix index d55a473..944bef8 100644 --- a/shell.nix +++ b/shell.nix @@ -3,6 +3,6 @@ go just nil - just + air ]; } diff --git a/templates/tests/landing.html b/templates/tests/landing.html new file mode 100644 index 0000000..e69de29 diff --git a/utils/env.go b/utils/env.go index 7a3294c..2007562 100644 --- a/utils/env.go +++ b/utils/env.go @@ -1,6 +1,9 @@ package utils -import "os" +import ( + "os" + "strings" +) var ( DiscordBotToken = os.Getenv("DISCORD_BOT_TOKEN") @@ -9,4 +12,6 @@ var ( DiscordPublicKey = os.Getenv("DISCORD_PUBLIC_KEY") ListenAddr = Or(os.Getenv("LISTEN_ADDR"), ":8169") PublicBaseURL = os.Getenv("PUBLIC_BASE_URL") + SupportIDs = strings.Split(os.Getenv("SUPPORT_IDS"), ",") + SupueruserIDs = strings.Split(os.Getenv("SUPERUSER_IDS"), ",") )