Skip to content

Commit 7b34b5c

Browse files
committed
Raspberry Pi information 🍌
Signed-off-by: Tobias Schäfer <github@blackox.org>
0 parents  commit 7b34b5c

25 files changed

Lines changed: 1023 additions & 0 deletions

‎.github/workflows/ci.yml‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
name: CI
3+
4+
on: # yamllint disable-line rule:truthy
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
types:
10+
- opened
11+
- synchronize
12+
- reopened
13+
14+
jobs:
15+
format:
16+
name: Check formatting
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 1
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version-file: go.mod
26+
- name: Install dependencies
27+
run: go mod download
28+
- name: Run formatter check
29+
run: gofmt -l .
30+
lint:
31+
name: Run linters
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 1
37+
- name: Set up Go
38+
uses: actions/setup-go@v5
39+
with:
40+
go-version-file: go.mod
41+
- name: Install dependencies
42+
run: go mod download
43+
- name: Install golangci-lint
44+
run: |
45+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | \
46+
sh -s -- -b $(go env GOPATH)/bin v2.1.5
47+
- name: Run linters
48+
run: golangci-lint run
49+
test:
50+
name: Run tests
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v4
54+
with:
55+
fetch-depth: 1
56+
- name: Set up Go
57+
uses: actions/setup-go@v5
58+
with:
59+
go-version-file: go.mod
60+
- name: Install dependencies
61+
run: go mod download
62+
- name: Run tests
63+
run: go test -v ./...
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: Release
3+
4+
on: # yamllint disable-line rule:truthy
5+
push:
6+
tags:
7+
- '*'
8+
9+
jobs:
10+
build:
11+
name: Build and release binaries
12+
runs-on: ubuntu-latest
13+
permissions:
14+
packages: write
15+
contents: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 1
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version-file: go.mod
24+
- name: Install dependencies
25+
run: go mod download
26+
- name: Install golangci-lint
27+
run: |
28+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | \
29+
sh -s -- -b $(go env GOPATH)/bin v2.1.5
30+
- name: Build binaries
31+
run: make all
32+
- name: Create SHA256 checksums
33+
run: make checksum
34+
- name: Upload binaries and checksums
35+
uses: alexellis/upload-assets@0.4.1
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
with:
39+
asset_paths: '["bin/*"]'

‎.gitignore‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/go
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=go
3+
4+
### Go ###
5+
# If you prefer the allow list template instead of the deny list, see community template:
6+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
7+
#
8+
# Binaries for programs and plugins
9+
*.exe
10+
*.exe~
11+
*.dll
12+
*.so
13+
*.dylib
14+
15+
# Test binary, built with `go test -c`
16+
*.test
17+
18+
# Output of the go coverage tool, specifically when used with LiteIDE
19+
*.out
20+
21+
# Dependency directories (remove the comment below to include it)
22+
# vendor/
23+
24+
# Go workspace file
25+
go.work
26+
27+
# Build binaries
28+
bin
29+
30+
# End of https://www.toptal.com/developers/gitignore/api/go

‎.golangci.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
version: 2
3+
linters:
4+
settings:
5+
errcheck:
6+
exclude-functions:
7+
- (*encoding/json.Encoder).Encode
8+
formatters:
9+
enable:
10+
- gofmt

‎.yamllint‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
extends: default
3+
rules:
4+
indentation:
5+
indent-sequences: consistent
6+
line-length:
7+
max: 120
8+
9+
# vim:ft=yaml

‎LICENSE‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Tobias Schäfer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+

‎Makefile‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Version := $(shell git describe --tags --dirty 2> /dev/null)
2+
GitCommit := $(shell git rev-parse HEAD)
3+
LDFLAGS := "-s -w -X github.com/tschaefer/rpinfo/version.Version=$(Version) -X github.com/tschaefer/rpinfo/version.GitCommit=$(GitCommit)"
4+
5+
.PHONY: all
6+
all: fmt lint dist
7+
8+
.PHONY: fmt
9+
fmt:
10+
test -z $(shell gofmt -l .) || (echo "[WARN] Fix format issues" && exit 1)
11+
12+
.PHONY: lint
13+
lint:
14+
test -z $(shell golangci-lint run >/dev/null || echo 1) || (echo "[WARN] Fix lint issues" && exit 1)
15+
16+
.PHONY: dist
17+
dist:
18+
mkdir -p bin
19+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o bin/rpinfo-arm64 -ldflags $(LDFLAGS) .
20+
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -o bin/rpinfo-armv5 -ldflags $(LDFLAGS) .
21+
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -o bin/rpinfo-armv6 -ldflags $(LDFLAGS) .
22+
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -o bin/rpinfo-armv7 -ldflags $(LDFLAGS) .
23+
24+
.PHONY: checksum
25+
checksum:
26+
cd bin && \
27+
for f in rpinfo-arm64 rpinfo-armv5 rpinfo-armv6 rpinfo-armv7; do \
28+
sha256sum $$f > $$f.sha256; \
29+
done && \
30+
cd ..
31+
32+
.PHONY: clean
33+
clean:
34+
rm -rf bin

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# rpinfo
2+
3+
Publish Raspberry Pi information via Rest API.

‎cmd/root.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright (c) 2025 Tobias Schäfer. All rights reserved.
3+
Licensed under the MIT license, see LICENSE in the project root for details.
4+
*/
5+
package cmd
6+
7+
import (
8+
"os"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var rootCmd = &cobra.Command{
14+
Use: "rpinfo",
15+
Short: "Publish Raspberry Pi information via REST API",
16+
Long: "Publish Raspberry Pi information via REST API",
17+
}
18+
19+
func Execute() {
20+
err := rootCmd.Execute()
21+
if err != nil {
22+
os.Exit(1)
23+
}
24+
}
25+
26+
func init() {
27+
}

‎cmd/server.go‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright (c) 2025 Tobias Schäfer. All rights reserved.
3+
Licensed under the MIT license, see LICENSE in the project root for details.
4+
*/
5+
package cmd
6+
7+
import (
8+
"github.com/spf13/cobra"
9+
"github.com/tschaefer/rpinfo/server"
10+
)
11+
12+
var serverCmd = &cobra.Command{
13+
Use: "server",
14+
Short: "Start the Rest API server",
15+
Long: "Start the Rest API server",
16+
RunE: RunServerCmd,
17+
}
18+
19+
func init() {
20+
serverCmd.Flags().StringP("port", "p", "8080", "Port to run the server on")
21+
serverCmd.Flags().StringP("host", "H", "localhost", "Host to run the server on")
22+
serverCmd.Flags().BoolP("auth", "a", false, "Enable authentication")
23+
serverCmd.Flags().StringP("token", "t", "", "Bearer Token for authentication")
24+
25+
rootCmd.AddCommand(serverCmd)
26+
}
27+
28+
func RunServerCmd(cmd *cobra.Command, args []string) error {
29+
port, _ := cmd.Flags().GetString("port")
30+
host, _ := cmd.Flags().GetString("host")
31+
auth, _ := cmd.Flags().GetBool("auth")
32+
token, _ := cmd.Flags().GetString("token")
33+
34+
server.Run(port, host, auth, token)
35+
36+
return nil
37+
}

0 commit comments

Comments
 (0)