Refactor rest of files

This commit is contained in:
Florian Hoss 2023-06-21 17:19:21 +02:00
parent 3c82a97a75
commit c5f3da0ac5
19 changed files with 282 additions and 234 deletions

View file

@ -1,10 +1,14 @@
package main
import (
"fmt"
"log"
"net/http"
"gitlab.unjx.de/flohoss/godash/internal/controller"
"gitlab.unjx.de/flohoss/godash/internal/env"
"gitlab.unjx.de/flohoss/godash/internal/logging"
"gitlab.unjx.de/flohoss/godash/internal/router"
"go.uber.org/zap"
)
@ -14,4 +18,13 @@ func main() {
log.Fatal(err)
}
zap.ReplaceGlobals(logging.CreateLogger(env.LogLevel))
r := router.InitRouter()
c := controller.NewController(env)
router.SetupRoutes(r, c)
zap.L().Info("starting server", zap.String("url", fmt.Sprintf("http://localhost:%d", env.Port)))
if err := r.Start(fmt.Sprintf(":%d", env.Port)); err != http.ErrServerClosed {
zap.L().Fatal("cannot start server", zap.Error(err))
}
}

31
go.mod
View file

@ -3,29 +3,50 @@ module gitlab.unjx.de/flohoss/godash
go 1.20
require (
github.com/Masterminds/sprig/v3 v3.2.3
github.com/caarlos0/env/v8 v8.0.0
github.com/dariubs/percent v1.0.0
github.com/fsnotify/fsnotify v1.6.0
github.com/go-chi/chi/v5 v5.0.8
github.com/go-playground/validator/v10 v10.14.1
github.com/labstack/echo/v4 v4.10.2
github.com/r3labs/sse/v2 v2.10.0
github.com/shirou/gopsutil/v3 v3.23.5
github.com/stretchr/testify v1.8.3
github.com/stretchr/testify v1.8.4
github.com/unjx-de/go-folder v1.0.7
go.uber.org/zap v1.24.0
gopkg.in/yaml.v3 v3.0.1
)
require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/google/uuid v1.1.1 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
@ -33,6 +54,6 @@ require (
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/time v0.3.0 // indirect
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

94
go.sum
View file

@ -1,3 +1,9 @@
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g=
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA=
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/caarlos0/env/v8 v8.0.0 h1:POhxHhSpuxrLMIdvTGARuZqR4Jjm8AYmoi/JKlcScs0=
github.com/caarlos0/env/v8 v8.0.0/go.mod h1:7K4wMY9bH0esiXSSHlfHLX5xKGQMnkH5Fk4TDSSSzfo=
@ -6,8 +12,12 @@ github.com/dariubs/percent v1.0.0/go.mod h1:NDZpkezJ8QqyIW/510MywB5T2KdC8v/0oTlE
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0=
github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
@ -17,19 +27,44 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k=
github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/labstack/echo/v4 v4.10.2 h1:n1jAhnq/elIFTHr1EYpiYtyKgx4RW9ccVgkqByZaN2M=
github.com/labstack/echo/v4 v4.10.2/go.mod h1:OEyqf2//K1DFdE57vw2DRgWY0M7s65IVQO2FzvI4J5k=
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a h1:N9zuLhTvBSRt0gWSiJswwQ2HqDmtX/ZCDJURnKUt1Ik=
github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE=
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b h1:0LFwY6Q3gMACTjAbMZBjXAqTOzOwFaj2Ld6cjeQ7Rig=
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/r3labs/sse/v2 v2.10.0 h1:hFEkLLFY4LDifoHdiCN/LlGBAdVJYsANaLqNYa1l/v0=
github.com/r3labs/sse/v2 v2.10.0/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktEmkNJ7I=
github.com/shirou/gopsutil/v3 v3.23.5 h1:5SgDCeQ0KW0S4N0znjeM/eFHXXOKyv2dVNgRq/c9P6Y=
@ -38,19 +73,35 @@ github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFt
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM=
github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI=
github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms=
github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4=
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
github.com/unjx-de/go-folder v1.0.7 h1:OVKvqjcVB0ASidVshYndRtkmlqS1h6MIhSr0vqX3Q6A=
github.com/unjx-de/go-folder v1.0.7/go.mod h1:sbcRrRgLE49QI6CZqGBMdneRuNOOhoRU1gx9DYlyD2g=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
@ -61,26 +112,61 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/cenkalti/backoff.v1 v1.1.0 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo4Y=
gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UDAkHu8BrjI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View file

@ -1,22 +1,23 @@
package bookmarks
import (
"io"
"os"
"strings"
"github.com/fsnotify/fsnotify"
folderCreate "github.com/unjx-de/go-folder"
"go.uber.org/zap"
"gopkg.in/yaml.v3"
"io"
"os"
"strings"
)
const StorageDir = "storage/"
const IconsDir = StorageDir + "icons/"
const bookmarksFolder = "bookmarks/"
const bookmarksFolder = "internal/bookmarks/"
const configFile = "config.yaml"
func NewBookmarkService(logging *zap.SugaredLogger) *Config {
c := Config{log: logging}
func NewBookmarkService() *Config {
c := Config{}
c.createFolderStructure()
c.copyDefaultConfigIfNotExisting()
c.parseBookmarks()
@ -28,44 +29,44 @@ func (c *Config) createFolderStructure() {
folders := []string{StorageDir, IconsDir}
err := folderCreate.CreateFolders(folders, 0755)
if err != nil {
c.log.Fatal(err)
zap.L().Fatal("cannot create folder", zap.Error(err))
}
c.log.Debugw("folders created", "folders", folders)
zap.L().Debug("folders created", zap.Strings("folders", folders))
}
func (c *Config) copyDefaultConfigIfNotExisting() {
_, err := os.Open(StorageDir + configFile)
if err != nil {
c.log.Debug(configFile + " not existing, creating...")
zap.L().Debug(configFile + " not existing, creating...")
source, _ := os.Open(bookmarksFolder + configFile)
defer source.Close()
destination, err := os.Create(StorageDir + configFile)
if err != nil {
c.log.Error(err)
zap.L().Error(err.Error())
return
}
defer destination.Close()
_, err = io.Copy(destination, source)
if err != nil {
c.log.Error(err)
zap.L().Error(err.Error())
return
}
c.log.Debug(configFile + " created")
zap.L().Debug(configFile + " created")
} else {
c.log.Debug(configFile + " existing, skipping creation")
zap.L().Debug(configFile + " existing, skipping creation")
}
}
func (c *Config) readBookmarksFile() []byte {
file, err := os.Open(StorageDir + configFile)
if err != nil {
c.log.Error(err)
zap.L().Error(err.Error())
return nil
}
defer file.Close()
byteValue, err := io.ReadAll(file)
if err != nil {
c.log.Error(err)
zap.L().Error(err.Error())
return nil
}
return byteValue
@ -85,7 +86,7 @@ func (c *Config) parseBookmarks() {
byteValue := c.readBookmarksFile()
err := yaml.Unmarshal(byteValue, &c.Parsed)
if err != nil {
c.log.Error(err)
zap.L().Error(err.Error())
return
}
c.replaceIconString()
@ -94,7 +95,7 @@ func (c *Config) parseBookmarks() {
func (c *Config) watchBookmarks() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
c.log.Error(err)
zap.L().Error(err.Error())
}
defer watcher.Close()
done := make(chan bool)
@ -104,15 +105,15 @@ func (c *Config) watchBookmarks() {
select {
case _ = <-watcher.Events:
c.parseBookmarks()
c.log.Debug("bookmarks changed", "applications", len(c.Parsed.Applications), "links", len(c.Parsed.Links))
zap.L().Debug("bookmarks changed", zap.Int("applications", len(c.Parsed.Applications)), zap.Int("links", len(c.Parsed.Links)))
case err := <-watcher.Errors:
c.log.Error(err)
zap.L().Error(err.Error())
}
}
}()
if err := watcher.Add(StorageDir + configFile); err != nil {
c.log.Fatal()
zap.L().Fatal("cannot add watcher")
}
<-done
}

View file

@ -1,9 +1,6 @@
package bookmarks
import "go.uber.org/zap"
type Config struct {
log *zap.SugaredLogger
Parsed struct {
Links []struct {
Category string

View file

@ -0,0 +1,38 @@
package controller
import (
"github.com/r3labs/sse/v2"
"gitlab.unjx.de/flohoss/godash/internal/bookmarks"
"gitlab.unjx.de/flohoss/godash/internal/env"
"gitlab.unjx.de/flohoss/godash/internal/system"
"gitlab.unjx.de/flohoss/godash/internal/weather"
)
type Controller struct {
ENV *env.Config
SSE *sse.Server
Info Info
}
type Info struct {
Weather *weather.Weather
Bookmarks *bookmarks.Config
System *system.System
}
func NewController(env *env.Config) *Controller {
ctrl := Controller{
ENV: env,
SSE: sse.New(),
}
ctrl.SSE.AutoReplay = false
ctrl.SSE.CreateStream("system")
ctrl.SSE.CreateStream("weather")
ctrl.Info = Info{
Weather: weather.NewWeatherService(ctrl.SSE),
Bookmarks: bookmarks.NewBookmarkService(),
System: system.NewSystemService(ctrl.ENV.LiveSystem, ctrl.SSE),
}
return &ctrl
}

View file

@ -0,0 +1,10 @@
package router
import "github.com/labstack/echo/v4"
func longCacheLifetime(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=31536000")
return next(c)
}
}

52
internal/router/router.go Normal file
View file

@ -0,0 +1,52 @@
package router
import (
"net/http"
chiMiddleware "github.com/go-chi/chi/v5/middleware"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"gitlab.unjx.de/flohoss/godash/internal/controller"
)
func InitRouter() *echo.Echo {
e := echo.New()
e.HideBanner = true
e.HidePort = true
e.Pre(middleware.RemoveTrailingSlash())
e.Use(echo.WrapMiddleware(chiMiddleware.Heartbeat("/health")))
e.Use(middleware.Recover())
e.Use(middleware.Gzip())
e.Renderer = initTemplates()
return e
}
func SetupRoutes(e *echo.Echo, ctrl *controller.Controller) {
static := e.Group("/static", longCacheLifetime)
static.Static("/", "web/static")
storage := e.Group("/storage", longCacheLifetime)
storage.Static("/icons", "storage/icons")
e.GET("/", func(c echo.Context) error {
return c.Render(http.StatusOK, "index.html", map[string]interface{}{
"Title": ctrl.ENV.Title,
"Weather": ctrl.Info.Weather.CurrentWeather,
"Parsed": ctrl.Info.Bookmarks.Parsed,
"System": ctrl.Info.System,
})
})
e.GET("/sse", echo.WrapHandler(http.HandlerFunc(ctrl.SSE.ServeHTTP)))
e.GET("/robots.txt", func(ctx echo.Context) error {
return ctx.String(http.StatusOK, "User-agent: *\nDisallow: /")
})
e.RouteNotFound("*", func(ctx echo.Context) error {
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
})
}

View file

@ -0,0 +1,23 @@
package router
import (
"html/template"
"io"
"github.com/Masterminds/sprig/v3"
"github.com/labstack/echo/v4"
)
type Template struct {
templates *template.Template
}
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
return t.templates.ExecuteTemplate(w, "layout.html", data)
}
func initTemplates() *Template {
return &Template{
templates: template.Must(template.New("").Funcs(sprig.FuncMap()).ParseGlob("web/templates/*.html")),
}
}

View file

@ -8,10 +8,10 @@ import (
"go.uber.org/zap"
)
func NewSystemService(enabled bool, logging *zap.SugaredLogger, sse *sse.Server) *System {
func NewSystemService(enabled bool, sse *sse.Server) *System {
var s Config
if enabled {
s = Config{log: logging, sse: sse}
s = Config{sse: sse}
s.Initialize()
}
return &s.System
@ -35,5 +35,5 @@ func (c *Config) Initialize() {
c.System.Static.Ram = staticRam()
c.System.Static.Disk = staticDisk()
go c.UpdateLiveInformation()
c.log.Debugw("system updated", "cpu", c.System.Static.CPU.Name, "arch", c.System.Static.Host.Architecture)
zap.L().Debug("system updated", zap.String("cpu", c.System.Static.CPU.Name), zap.String("arch", c.System.Static.Host.Architecture))
}

View file

@ -2,12 +2,10 @@ package system
import (
"github.com/r3labs/sse/v2"
"go.uber.org/zap"
)
type Config struct {
sse *sse.Server
log *zap.SugaredLogger
System System
}

View file

@ -2,14 +2,12 @@ package weather
import (
"github.com/r3labs/sse/v2"
"go.uber.org/zap"
)
type Weather struct {
CurrentWeather OpenWeather
sse *sse.Server
config config
log *zap.SugaredLogger
}
type config struct {

View file

@ -8,13 +8,13 @@ import (
"net/http"
"time"
"github.com/caarlos0/env/v6"
"github.com/caarlos0/env/v8"
"github.com/r3labs/sse/v2"
"go.uber.org/zap"
)
func NewWeatherService(logging *zap.SugaredLogger, sse *sse.Server) *Weather {
var w = Weather{log: logging, sse: sse}
func NewWeatherService(sse *sse.Server) *Weather {
var w = Weather{sse: sse}
if err := env.Parse(&w.config); err != nil {
panic(err)
}
@ -58,15 +58,15 @@ func (w *Weather) updateWeather(interval time.Duration) {
w.config.Units,
w.config.Lang))
if err != nil || resp.StatusCode != 200 {
w.log.Error("weather cannot be updated, please check WEATHER_KEY")
zap.L().Error("weather cannot be updated, please check WEATHER_KEY")
} else {
body, _ := io.ReadAll(resp.Body)
err = json.Unmarshal(body, &weatherResponse)
if err != nil {
w.log.Error("weather cannot be processed")
zap.L().Error("weather cannot be processed")
} else {
w.copyWeatherValues(&weatherResponse)
w.log.Debugw("weather updated", "temp", w.CurrentWeather.Temp)
zap.L().Debug("weather updated", zap.Float64("temp", w.CurrentWeather.Temp))
}
resp.Body.Close()
json, _ := json.Marshal(w.CurrentWeather)

View file

@ -1,95 +0,0 @@
package main
import (
"godash/bookmarks"
"godash/system"
"godash/weather"
"context"
"fmt"
"html/template"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/Masterminds/sprig/v3"
"github.com/caarlos0/env/v6"
"github.com/labstack/echo/v4"
"github.com/r3labs/sse/v2"
"go.uber.org/zap"
)
type goDash struct {
router *echo.Echo
logger *zap.SugaredLogger
sse *sse.Server
config config
info info
}
type info struct {
weather *weather.Weather
bookmarks *bookmarks.Config
system *system.System
}
type config struct {
Title string `env:"TITLE" envDefault:"goDash"`
Port int `env:"PORT" envDefault:"4000"`
AllowedHosts []string `env:"ALLOWED_HOSTS" envDefault:"*" envSeparator:","`
LogLevel string `env:"LOG_LEVEL" envDefault:"info"`
LiveSystem bool `env:"LIVE_SYSTEM" envDefault:"true"`
}
func (g *goDash) createInfoServices() {
g.sse.AutoReplay = false
g.sse.CreateStream("system")
g.sse.CreateStream("weather")
g.info = info{
weather: weather.NewWeatherService(g.logger, g.sse),
bookmarks: bookmarks.NewBookmarkService(g.logger),
system: system.NewSystemService(g.config.LiveSystem, g.logger, g.sse),
}
}
func (g *goDash) startServer() {
if err := g.router.Start(fmt.Sprintf(":%d", g.config.Port)); err != nil && err != http.ErrServerClosed {
g.logger.Fatal("shutting down the server")
}
}
func (g *goDash) setupTemplateRender() {
g.router.Renderer = &TemplateRenderer{
templates: template.Must(template.New("").Funcs(sprig.FuncMap()).ParseGlob("templates/*.html")),
}
}
func main() {
g := goDash{router: echo.New(), sse: sse.New()}
if err := env.Parse(&g.config); err != nil {
panic(err)
}
g.setupTemplateRender()
g.setupLogger()
defer g.logger.Sync()
g.setupEchoLogging()
g.setupMiddlewares()
g.createInfoServices()
g.setupRouter()
go g.startServer()
g.logger.Infof("running on %s:%d", "http://localhost", g.config.Port)
quit := make(chan os.Signal, 1)
// https://docs.docker.com/engine/reference/commandline/stop/
signal.Notify(quit, syscall.SIGTERM)
<-quit
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
if err := g.router.Shutdown(ctx); err != nil {
g.logger.Fatal(err)
}
}

View file

@ -1,27 +0,0 @@
package main
import (
chiMiddleware "github.com/go-chi/chi/v5/middleware"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"net/http"
)
func longCacheLifetime(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=31536000")
return next(c)
}
}
func (g *goDash) setupMiddlewares() {
g.router.Pre(middleware.RemoveTrailingSlash())
g.router.Use(echo.WrapMiddleware(chiMiddleware.Heartbeat("/health")))
g.router.Use(middleware.Recover())
g.router.Use(middleware.GzipWithConfig(middleware.GzipConfig{Level: 1}))
g.router.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: g.config.AllowedHosts,
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept, echo.HeaderCacheControl},
AllowMethods: []string{echo.GET, http.MethodHead},
}))
}

View file

@ -1,22 +0,0 @@
package main
import (
"net/http"
"github.com/labstack/echo/v4"
)
func (g *goDash) setupRouter() {
g.router.GET("/", g.index)
g.router.GET("/robots.txt", robots)
g.router.GET("/sse", echo.WrapHandler(http.HandlerFunc(g.sse.ServeHTTP)))
static := g.router.Group("/static", longCacheLifetime)
static.Static("/", "static")
storage := g.router.Group("/storage", longCacheLifetime)
storage.Static("/icons", "storage/icons")
g.router.RouteNotFound("/*", redirectHome)
}

View file

@ -1,29 +0,0 @@
package main
import (
"net/http"
"github.com/gorilla/websocket"
"github.com/labstack/echo/v4"
)
var (
upgrader = websocket.Upgrader{}
)
func (g *goDash) index(c echo.Context) error {
return c.Render(http.StatusOK, "index.html", map[string]interface{}{
"Title": g.config.Title,
"Weather": g.info.weather.CurrentWeather,
"Parsed": g.info.bookmarks.Parsed,
"System": g.info.system,
})
}
func robots(c echo.Context) error {
return c.String(http.StatusOK, "User-agent: *\nDisallow: /")
}
func redirectHome(c echo.Context) error {
return c.Redirect(http.StatusMovedPermanently, "/")
}

View file

@ -1,16 +0,0 @@
package main
import (
"html/template"
"io"
"github.com/labstack/echo/v4"
)
type TemplateRenderer struct {
templates *template.Template
}
func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
return t.templates.ExecuteTemplate(w, "layout.html", data)
}