Skip to content

Commit 7fd2017

Browse files
committed
feat: add cli arguments to select port
1 parent d99ad6a commit 7fd2017

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

flake.nix

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
./static
8686
];
8787
};
88-
vendorHash = "sha256-nw5TouuxauSa520hidHom/iN6VxrGN/7By9spsJ5h6Y=";
88+
vendorHash = "sha256-ODDE+a414UoPVfa9HCSZlYf/YdCRq0sH5FQoUk4jqEM=";
8989
tags = [ "production" ];
9090
nativeBuildInputs = with pkgs; [
9191
templ
@@ -133,7 +133,7 @@
133133
name = "healthcheck";
134134
runtimeInputs = [ pkgs.curl ];
135135
text = ''
136-
test "$(curl --fail localhost:8080/health)" = "OK"
136+
test "$(curl --fail localhost/health)" = "OK"
137137
'';
138138
};
139139
in
@@ -142,7 +142,11 @@
142142
"CMD"
143143
"${lib.getExe healthcheck}"
144144
];
145-
Entrypoint = [ "app" ];
145+
Entrypoint = [
146+
"app"
147+
"--port"
148+
"80"
149+
];
146150
};
147151
};
148152

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ require (
88
github.com/a-h/templ v0.3.833
99
github.com/alecthomas/chroma/v2 v2.15.0
1010
github.com/charmbracelet/log v0.4.0
11+
github.com/pschou/go-params v0.0.0-20240104134853-225c817afb69
1112
github.com/yuin/goldmark v1.7.8
1213
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
1314
github.com/yuin/goldmark-meta v1.1.0
1415
gopkg.in/yaml.v3 v3.0.1
1516
)
1617

18+
require github.com/xhit/go-str2duration v1.2.0 // indirect
19+
1720
require (
1821
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
1922
github.com/charmbracelet/lipgloss v1.0.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc
4545
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
4646
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4747
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
48+
github.com/pschou/go-params v0.0.0-20240104134853-225c817afb69 h1:IG1MpLiUP9a+mRCJd70MTHtbWWDNU+xKl2BDvcIlS/Q=
49+
github.com/pschou/go-params v0.0.0-20240104134853-225c817afb69/go.mod h1:kqNkpjmn8DxDO8Tt7NxX3u5gGUtf+41EXepNOsMlJGE=
4850
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
4951
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
5052
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
@@ -54,6 +56,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
5456
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
5557
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
5658
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
59+
github.com/xhit/go-str2duration v1.2.0 h1:BcV5u025cITWxEQKGWr1URRzrcXtu7uk8+luz3Yuhwc=
60+
github.com/xhit/go-str2duration v1.2.0/go.mod h1:3cPSlfZlUHVlneIVfePFWcJZsuwf+P1v2SRTV4cUmp4=
5761
github.com/yuin/goldmark v1.4.15/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
5862
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
5963
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=

main.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,30 @@ import (
77
"app/pkg/routes/health"
88
"app/pkg/routes/resume"
99
"app/pkg/routes/root"
10+
"fmt"
11+
"os"
1012

1113
"github.com/charmbracelet/log"
14+
"github.com/pschou/go-params"
1215
)
1316

1417
var (
15-
rev string = "foo"
18+
rev string = "foo"
19+
defaultPort int = 8080
1620
)
1721

1822
func main() {
19-
log.Info("Current revision: " + rev)
20-
serv := app.Server{Port: 8080, Rev: rev}
23+
params.Usage = func() {
24+
fmt.Fprintf(os.Stderr, "drawbu.dev, build rev: %s\n\n"+
25+
"Usage: %s [options...]\n\n", rev, os.Args[0])
26+
params.PrintDefaults()
27+
}
28+
var port = params.Int("port", defaultPort, "Web server's listening port", "Number")
29+
params.Parse()
30+
31+
log.Info("Starting server", "port", *port, "rev", rev)
32+
33+
serv := app.Server{Port: int16(*port), Rev: rev}
2134

2235
serv.AddRoute("GET /", root.Handler)
2336
serv.AddRoute("GET /health", health.Handler)

pkg/routes/blog/article.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func fileToMarkdown(file fs.File, buf *bytes.Buffer) (mdParser.Context, error) {
9696
if err != nil {
9797
return nil, fmt.Errorf("Error getting file info: %s", err)
9898
}
99-
log.Info("Opening new article", "name", info.Name)
99+
log.Info("Opening new article", "name", info.Name())
100100

101101
content := make([]byte, info.Size())
102102
if _, err = file.Read(content); err != nil {

0 commit comments

Comments
 (0)