Skip to content

Commit 48ed06e

Browse files
committed
Initial commit
0 parents  commit 48ed06e

File tree

15 files changed

+459
-0
lines changed

15 files changed

+459
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- master
6+
tags:
7+
- '*'
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
docker:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
steps:
20+
- name: Login to GitHub Container Registry
21+
uses: docker/login-action@v3
22+
with:
23+
registry: ghcr.io
24+
username: ${{ github.actor }}
25+
password: ${{ secrets.GITHUB_TOKEN }}
26+
- name: Extract metadata (tags, labels) for Docker
27+
id: meta
28+
uses: docker/metadata-action@v5
29+
with:
30+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
31+
tags: |
32+
# set latest tag for default branch
33+
type=raw,value=latest,enable={{is_default_branch}}
34+
type=semver,pattern={{version}}
35+
- name: Build container
36+
uses: docker/build-push-action@v5
37+
with:
38+
push: true
39+
tags: ${{ steps.meta.outputs.tags }}
40+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/verify-code.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: verify-code
2+
on:
3+
push:
4+
pull_request:
5+
permissions:
6+
contents: read
7+
# Optional: allow read access to pull request. Use with `only-new-issues` option.
8+
# pull-requests: read
9+
jobs:
10+
golangci:
11+
name: lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/setup-go@v5
15+
with:
16+
go-version: 1.24
17+
- uses: actions/checkout@v3
18+
- name: golangci-lint
19+
uses: golangci/golangci-lint-action@v3
20+
with:
21+
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
22+
version: v1.47.2
23+
24+
# Optional: working directory, useful for monorepos
25+
# working-directory: somedir
26+
27+
# Optional: golangci-lint command line arguments.
28+
# args: --issues-exit-code=0
29+
30+
# Optional: show only new issues if it's a pull request. The default value is `false`.
31+
# only-new-issues: true
32+
33+
# Optional: if set to true then the all caching functionality will be complete disabled,
34+
# takes precedence over all other caching options.
35+
# skip-cache: true
36+
37+
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
38+
# skip-pkg-cache: true
39+
40+
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
41+
# skip-build-cache: true
42+
test:
43+
name: go-test
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/setup-go@v5
47+
with:
48+
go-version: 1.24
49+
- uses: actions/checkout@v3
50+
- name: test
51+
run: go test -v ./...

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
kvitto-store.yaml
2+
kvitto-store.yml

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kvitto-store.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM golang:1.24.1 AS builder
2+
COPY . /app
3+
RUN cd /app && go mod verify && go build
4+
5+
FROM debian:bookworm
6+
COPY --from=builder /app/kvitto-store /usr/bin/kvitto-store
7+
8+
CMD ["/usr/bin/kvitto-store"]

configure.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"strings"
6+
7+
"github.com/spf13/viper"
8+
)
9+
10+
func configure() error {
11+
defaults()
12+
13+
viper.SetConfigType("yaml")
14+
viper.AddConfigPath(".")
15+
viper.AddConfigPath("/etc/it-sektionen")
16+
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
17+
viper.AutomaticEnv()
18+
19+
viper.SetConfigName("kvitto-store")
20+
21+
if err := viper.ReadInConfig(); err != nil {
22+
var configFileAlreadyExistsError viper.ConfigFileNotFoundError
23+
if errors.As(err, &configFileAlreadyExistsError) {
24+
// Write the default config to current directory if no file was found
25+
_ = viper.SafeWriteConfig()
26+
}
27+
28+
return err
29+
}
30+
31+
return nil
32+
}
33+
34+
func defaults() {
35+
// MQTT settings
36+
viper.SetDefault("mqtt.broker", "localhost:1883")
37+
viper.SetDefault("mqtt.client_id", "kvitto-store")
38+
viper.SetDefault("mqtt.timeout", "1m")
39+
40+
// Influx settings
41+
viper.SetDefault("influx.url", "http://localhost:8086")
42+
viper.SetDefault("influx.token", "suersecret")
43+
viper.SetDefault("influx.bucket", "kvitto")
44+
viper.SetDefault("influx.org", "smn")
45+
}

go.mod

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module kvitto-store
2+
3+
go 1.24.0
4+
5+
require (
6+
github.com/eclipse/paho.mqtt.golang v1.5.0
7+
github.com/influxdata/influxdb-client-go/v2 v2.14.0
8+
github.com/spf13/viper v1.20.1
9+
)
10+
11+
replace (
12+
github.com/chenzhuoyu/iasm => github.com/cloudwego/iasm v0.0.9
13+
)
14+
15+
require (
16+
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
17+
github.com/fsnotify/fsnotify v1.8.0 // indirect
18+
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
19+
github.com/google/uuid v1.3.1 // indirect
20+
github.com/gorilla/websocket v1.5.3 // indirect
21+
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
22+
github.com/oapi-codegen/runtime v1.0.0 // indirect
23+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
24+
github.com/sagikazarmark/locafero v0.9.0 // indirect
25+
github.com/sourcegraph/conc v0.3.0 // indirect
26+
github.com/spf13/afero v1.14.0 // indirect
27+
github.com/spf13/cast v1.7.1 // indirect
28+
github.com/spf13/pflag v1.0.6 // indirect
29+
github.com/subosito/gotenv v1.6.0 // indirect
30+
go.uber.org/multierr v1.11.0 // indirect
31+
golang.org/x/net v0.27.0 // indirect
32+
golang.org/x/sync v0.12.0 // indirect
33+
golang.org/x/sys v0.31.0 // indirect
34+
golang.org/x/text v0.23.0 // indirect
35+
gopkg.in/yaml.v3 v3.0.1 // indirect
36+
)

0 commit comments

Comments
 (0)