This commit is contained in:
41666 2025-03-27 10:19:25 -07:00
parent 7b8cdcfd7b
commit 143caaac2b
9 changed files with 115 additions and 10 deletions

52
.air.toml Normal file
View file

@ -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

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
.env
.storage
result
tmp

View file

@ -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

View file

@ -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)

View file

@ -1,3 +1,6 @@
watch:
air
run:
go run .
@ -15,7 +18,6 @@ fmt:
go fmt ./...
tidy:
go clean -modcache
go mod tidy
update-vendor-hash:
@ -23,3 +25,6 @@ update-vendor-hash:
test:
go test ./...
clean-repo:
rm -rf tmp result

10
main.go
View file

@ -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))

View file

@ -3,6 +3,6 @@
go
just
nil
just
air
];
}

View file

View file

@ -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"), ",")
)