Skip to content

Commit f0336b2

Browse files
committed
feat: show version on website
Signed-off-by: skidoodle <contact@albert.lol>
1 parent 2bcf339 commit f0336b2

File tree

6 files changed

+39
-4
lines changed

6 files changed

+39
-4
lines changed

.goreleaser.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ before:
44
hooks:
55
- go mod tidy
66

7+
snapshot:
8+
version_template: "{{ .Version }}"
9+
710
builds:
811
- env:
912
- CGO_ENABLED=0
@@ -13,7 +16,8 @@ builds:
1316
- amd64
1417
- arm64
1518
ldflags:
16-
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
19+
- -s -w
20+
- -X github.com/skidoodle/safebin/internal/app.Version={{.Version}}
1721
flags:
1822
- -trimpath
1923

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ COPY . .
99

1010
ARG TARGETOS
1111
ARG TARGETARCH
12+
ARG VERSION=dev
1213

1314
RUN --mount=type=cache,target=/root/.cache/go-build \
1415
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build \
15-
-ldflags="-s -w" \
16+
-ldflags="-s -w -X github.com/skidoodle/safebin/internal/app.Version=$VERSION" \
1617
-trimpath \
1718
-o /app/safebin .
1819

internal/app/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import (
1313
"go.etcd.io/bbolt"
1414
)
1515

16+
var (
17+
Version = "dev"
18+
)
19+
1620
const (
1721
DefaultHost = "0.0.0.0"
1822
DefaultPort = 8080

internal/app/server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ func (app *App) Routes() *http.ServeMux {
3939

4040
func (app *App) HandleHome(writer http.ResponseWriter, request *http.Request) {
4141
err := app.Tmpl.ExecuteTemplate(writer, "layout", map[string]any{
42-
"MaxMB": app.Conf.MaxMB,
43-
"Host": request.Host,
42+
"MaxMB": app.Conf.MaxMB,
43+
"Host": request.Host,
44+
"Version": Version,
4445
})
4546

4647
if err != nil {

web/layout.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ <h2 class="header-title">safebin</h2>
2929
<div class="dim cli-label">CLI Usage</div>
3030
<pre class="cli-pre">curl -F file=@yourfile {{.Host}}</pre>
3131
</section>
32+
<footer class="footer">
33+
<div class="dim">
34+
{{if eq .Version "dev"}}
35+
<a href="https://github.com/skidoodle/safebin" target="_blank" rel="noopener noreferrer">dev</a>
36+
{{else}}
37+
<a href="https://github.com/skidoodle/safebin/releases/tag/v{{.Version}}" target="_blank" rel="noopener noreferrer">v{{.Version}}</a>
38+
{{end}}
39+
</div>
40+
</footer>
3241
</div>
3342
<input type="file" id="file-input" class="hidden" />
3443
<script src="/static/app.js"></script>

web/style.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,26 @@ button {
237237
display: none !important;
238238
}
239239

240+
.footer {
241+
margin-top: 20px;
242+
text-align: center;
243+
opacity: 0.5;
244+
}
245+
246+
.footer a {
247+
color: inherit;
248+
text-decoration: none;
249+
}
250+
251+
.footer a:hover {
252+
text-decoration: underline;
253+
}
254+
240255
@media (max-width: 400px) {
241256
.github-btn span {
242257
display: none;
243258
}
259+
244260
.github-btn {
245261
padding: 6px;
246262
}

0 commit comments

Comments
 (0)