refactor: switch router to gin

This commit is contained in:
Nicolas Meienberger
2025-08-10 13:07:05 +02:00
parent e601d91955
commit 2c38a551cc
15 changed files with 277 additions and 131 deletions

29
go.mod
View File

@@ -3,25 +3,35 @@ module ironmount
go 1.24.5
require (
github.com/justinas/alice v1.2.0
github.com/gin-gonic/gin v1.10.1
github.com/go-playground/validator/v10 v10.27.0
github.com/rs/zerolog v1.34.0
github.com/spf13/viper v1.20.1
modernc.org/sqlite v1.38.2
)
require (
github.com/bytedance/sonic v1.14.0 // indirect
github.com/bytedance/sonic/loader v0.3.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.27.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/sagikazarmark/locafero v0.7.0 // indirect
@@ -29,15 +39,18 @@ require (
github.com/spf13/afero v1.12.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/spf13/viper v1.20.1 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/arch v0.20.0 // indirect
golang.org/x/crypto v0.41.0 // indirect
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/text v0.28.0 // indirect
google.golang.org/protobuf v1.36.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.66.3 // indirect
modernc.org/mathutil v1.7.1 // indirect

90
go.sum
View File

@@ -1,12 +1,27 @@
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=
github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA=
github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
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/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY=
github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
@@ -15,13 +30,24 @@ github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHO
github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/justinas/alice v1.2.0 h1:+MHSA/vccVCF4Uq37S42jwlkvI2Xzl7zTPCN5BnZNVo=
github.com/justinas/alice v1.2.0/go.mod h1:fN5HRH/reO/zrUflLfTN43t3vXvKzvZIENsNEe7i7qA=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
@@ -31,14 +57,22 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
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/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
@@ -56,35 +90,51 @@ github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
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.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
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.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=
github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c=
golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=
golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
google.golang.org/protobuf v1.36.7 h1:IgrO7UwFQGJdRNXH/sQux4R1Dj1WAKcLElzeeRaXV2A=
google.golang.org/protobuf v1.36.7/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/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=
modernc.org/cc/v4 v4.26.2 h1:991HMkLjJzYBIfha6ECZdjrIYz2/1ayr+FL8GN+CNzM=

View File

@@ -3,8 +3,10 @@ package core
import (
stdlog "log"
"os"
"strconv"
"time"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
@@ -24,3 +26,43 @@ func init() {
stdlog.SetFlags(0)
stdlog.SetOutput(console)
}
func colorStatus(code int) string {
switch {
case code >= 200 && code < 300:
// Green background
return "\033[42m" + strconv.Itoa(code) + "\033[0m"
case code >= 300 && code < 400:
// Cyan background
return "\033[46m" + strconv.Itoa(code) + "\033[0m"
case code >= 400 && code < 500:
// Yellow background
return "\033[43m" + strconv.Itoa(code) + "\033[0m"
default:
// Red background
return "\033[41m" + strconv.Itoa(code) + "\033[0m"
}
}
// GinLogger is a middleware for Gin that logs HTTP requests
// using zerolog.
func GinLogger() gin.HandlerFunc {
return func(c *gin.Context) {
c.Next()
code := c.Writer.Status()
method := c.Request.Method
path := c.Request.URL.Path
// logPath check if the path should be logged normally or with debug
switch {
case code >= 200 && code < 300:
log.Info().Str("method", method).Str("path", path).Msgf("Request status=%s", colorStatus(code))
case code >= 300 && code < 400:
log.Warn().Str("method", method).Str("path", path).Msgf("Request status=%s", colorStatus(code))
case code >= 400:
log.Error().Str("method", method).Str("path", path).Msgf("Request status=%s", colorStatus(code))
}
}
}

View File

@@ -1,13 +1,15 @@
package driver
import (
"encoding/json"
"net/http"
"github.com/gin-gonic/gin"
)
func Activate(w http.ResponseWriter, r *http.Request) {
resp := map[string]any{
"Implements": []string{"VolumeDriver"},
}
_ = json.NewEncoder(w).Encode(resp)
func Activate(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"Implements": []string{
"VolumeDriver",
},
})
}

View File

@@ -0,0 +1,11 @@
package driver
import "github.com/gin-gonic/gin"
func Capabilities(c *gin.Context) {
c.JSON(200, gin.H{
"Capabilities": map[string]bool{
"Scope": true, // Indicates that the driver supports scope (local/global)
},
})
}

View File

@@ -1,7 +1,6 @@
package driver
import (
"encoding/json"
"ironmount/internal/constants"
"ironmount/internal/core"
"ironmount/internal/db"
@@ -9,34 +8,39 @@ import (
"os"
"path/filepath"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
)
func Create(w http.ResponseWriter, r *http.Request) {
var req struct {
Name string
Opts map[string]string `json:"Opts,omitempty"`
func Create(c *gin.Context) {
var body CreateRequest
if err := c.BindJSON(&body); err != nil {
log.Error().Err(err).Msg("Failed to bind JSON for Create request")
c.JSON(http.StatusBadRequest, gin.H{"Err": err.Error()})
return
}
_ = json.NewDecoder(r.Body).Decode(&req)
cfg := core.LoadConfig()
volPathHost := filepath.Join(cfg.VolumeRootHost, req.Name)
volPathLocal := filepath.Join(constants.VolumeRootLocal, req.Name)
volPathHost := filepath.Join(cfg.VolumeRootHost, body.Name)
volPathLocal := filepath.Join(constants.VolumeRootLocal, body.Name)
log.Info().Str("path", volPathLocal).Msg("Creating volume directory")
if err := os.MkdirAll(volPathLocal, 0755); err != nil {
log.Error().Err(err).Str("path", volPathLocal).Msg("Failed to create volume directory")
_ = json.NewEncoder(w).Encode(map[string]string{"Err": err.Error()})
c.JSON(http.StatusInternalServerError, gin.H{"Err": err.Error()})
return
}
db.CreateVolume(req.Name, volPathHost)
db.CreateVolume(body.Name, volPathHost)
response := map[string]string{
"Name": req.Name,
"Name": body.Name,
"Mountpoint": volPathHost,
"Err": "",
}
_ = json.NewEncoder(w).Encode(response)
c.JSON(http.StatusOK, response)
}

View File

@@ -1,28 +1,30 @@
package driver
import (
"encoding/json"
"ironmount/internal/db"
"net/http"
"github.com/rs/zerolog/hlog"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
)
func Get(w http.ResponseWriter, r *http.Request) {
var req struct {
Name string
}
_ = json.NewDecoder(r.Body).Decode(&req)
func Get(c *gin.Context) {
var body GetRequest
vol, err := db.GetVolumeByName(req.Name)
if err := c.BindJSON(&body); err != nil {
log.Error().Err(err).Msg("Failed to bind JSON for Get request")
c.JSON(http.StatusBadRequest, gin.H{"Err": err.Error()})
return
}
vol, err := db.GetVolumeByName(body.Name)
if err != nil {
hlog.FromRequest(r).Error().Err(err).Msg("Error retrieving volume")
log.Warn().Err(err).Str("name", body.Name).Msg("Failed to get volume by name")
response := map[string]string{
"Err": err.Error(),
}
_ = json.NewEncoder(w).Encode(response)
c.JSON(http.StatusNotFound, response)
return
}
@@ -36,5 +38,5 @@ func Get(w http.ResponseWriter, r *http.Request) {
"Err": "",
}
_ = json.NewEncoder(w).Encode(response)
c.JSON(http.StatusOK, response)
}

View File

@@ -1,17 +1,17 @@
package driver
import (
"net/http"
"github.com/gin-gonic/gin"
)
func SetupHandlers(mux *http.ServeMux) {
mux.HandleFunc("/Plugin.Activate", Activate)
mux.HandleFunc("/VolumeDriver.Create", Create)
mux.HandleFunc("/VolumeDriver.Remove", Remove)
mux.HandleFunc("/VolumeDriver.Mount", Mount)
mux.HandleFunc("/VolumeDriver.Unmount", Unmount)
mux.HandleFunc("/VolumeDriver.Path", Path)
mux.HandleFunc("/VolumeDriver.Get", Get)
mux.HandleFunc("/VolumeDriver.List", List)
func SetupHandlers(router *gin.Engine) {
router.POST("/Plugin.Activate", Activate)
router.POST("/VolumeDriver.Create", Create)
router.POST("/VolumeDriver.Remove", Remove)
router.POST("/VolumeDriver.Mount", Mount)
router.POST("/VolumeDriver.Unmount", Unmount)
router.POST("/VolumeDriver.Path", Path)
router.POST("/VolumeDriver.Get", Get)
router.POST("/VolumeDriver.List", List)
router.POST("/VolumeDriver.Capabilities", Capabilities)
}

View File

@@ -1,25 +1,27 @@
package driver
import (
"encoding/json"
"ironmount/internal/db"
"net/http"
"github.com/rs/zerolog/hlog"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
)
func List(w http.ResponseWriter, r *http.Request) {
func List(c *gin.Context) {
volumes, err := db.ListVolumes()
if err != nil {
hlog.FromRequest(r).Error().Err(err).Msg("Error listing volumes")
json.NewEncoder(w).Encode(map[string]any{
log.Error().Err(err).Msg("Failed to list volumes")
c.JSON(http.StatusInternalServerError, gin.H{
"Volumes": nil,
"Err": err.Error(),
})
return
}
json.NewEncoder(w).Encode(map[string]any{
c.JSON(http.StatusOK, gin.H{
"Volumes": volumes,
"Err": "",
})

View File

@@ -1,37 +1,35 @@
package driver
import (
"encoding/json"
"ironmount/internal/db"
"net/http"
"github.com/rs/zerolog/hlog"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
)
func Mount(w http.ResponseWriter, r *http.Request) {
func Mount(c *gin.Context) {
var req MountRequest
err := json.NewDecoder(r.Body).Decode(&req)
if err := c.BindJSON(&req); err != nil {
log.Error().Err(err).Msg("Invalid request body")
if err != nil {
hlog.FromRequest(r).Error().Err(err).Msg("Invalid request body")
http.Error(w, "Invalid request body", http.StatusBadRequest)
c.JSON(http.StatusBadRequest, gin.H{"Err": "Invalid request body"})
return
}
vol, err := db.GetVolumeByName(req.Name)
if err != nil {
log.Error().Err(err).Str("volume", req.Name).Msg("Failed to get volume")
_ = json.NewEncoder(w).Encode(map[string]string{
"Err": err.Error(),
})
c.JSON(http.StatusNotFound, gin.H{"Err": err.Error()})
return
}
log.Info().Str("volume", vol.Name).Str("path", vol.Path).Msg("Mounting volume")
_ = json.NewEncoder(w).Encode(map[string]string{
c.JSON(http.StatusOK, gin.H{
"Name": vol.Name,
"Mountpoint": vol.Path,
"Err": "",
})

View File

@@ -1,27 +1,31 @@
package driver
import (
"encoding/json"
"ironmount/internal/db"
"net/http"
"github.com/rs/zerolog/hlog"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
)
func Path(w http.ResponseWriter, r *http.Request) {
func Path(c *gin.Context) {
var req PathRequest
_ = json.NewDecoder(r.Body).Decode(&req)
vol, err := db.GetVolumeByName(req.Name)
if err != nil {
hlog.FromRequest(r).Error().Err(err).Msg("Error retrieving volume")
_ = json.NewEncoder(w).Encode(map[string]string{
"Err": err.Error(),
})
if err := c.BindJSON(&req); err != nil {
log.Error().Err(err).Msg("Invalid request body for Path")
c.JSON(http.StatusBadRequest, gin.H{"Err": "Invalid request body"})
return
}
_ = json.NewEncoder(w).Encode(map[string]string{
vol, err := db.GetVolumeByName(req.Name)
if err != nil {
log.Error().Err(err).Str("volume", req.Name).Msg("Failed to get volume by name")
c.JSON(http.StatusNotFound, gin.H{"Err": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{
"Mountpoint": vol.Path,
"Err": "",
})

View File

@@ -1,27 +1,30 @@
package driver
import (
"encoding/json"
"ironmount/internal/constants"
"ironmount/internal/db"
"net/http"
"os"
"path/filepath"
"github.com/rs/zerolog/hlog"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
)
func Remove(w http.ResponseWriter, r *http.Request) {
func Remove(c *gin.Context) {
var req RemoveRequest
_ = json.NewDecoder(r.Body).Decode(&req)
if err := c.BindJSON(&req); err != nil {
log.Error().Err(err).Msg("Invalid request body for Remove")
c.JSON(http.StatusBadRequest, gin.H{"Err": "Invalid request body"})
return
}
vol, err := db.GetVolumeByName(req.Name)
if err != nil {
hlog.FromRequest(r).Error().Err(err).Msg("Error retrieving volume")
_ = json.NewEncoder(w).Encode(map[string]string{
"Err": err.Error(),
})
log.Error().Err(err).Str("volume", req.Name).Msg("Failed to get volume by name")
c.JSON(http.StatusNotFound, gin.H{"Err": err.Error()})
return
}
@@ -31,5 +34,7 @@ func Remove(w http.ResponseWriter, r *http.Request) {
log.Info().Str("path", volPathLocal).Msg("Removing volume directory")
os.RemoveAll(volPathLocal)
_ = json.NewEncoder(w).Encode(map[string]string{"Err": ""})
c.JSON(http.StatusOK, gin.H{
"Err": "",
})
}

View File

@@ -5,6 +5,10 @@ type CreateRequest struct {
Name string
}
type GetRequest struct {
Name string
}
// RemoveRequest is the JSON request for Remove
type RemoveRequest struct {
Name string

View File

@@ -1,10 +1,13 @@
package driver
import (
"encoding/json"
"net/http"
"github.com/gin-gonic/gin"
)
func Unmount(w http.ResponseWriter, r *http.Request) {
_ = json.NewEncoder(w).Encode(map[string]string{"Err": ""})
func Unmount(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"Err": "",
})
}

48
main.go
View File

@@ -2,15 +2,15 @@ package main
import (
"ironmount/internal/constants"
"ironmount/internal/core"
"ironmount/internal/db"
"ironmount/internal/driver"
"net"
"net/http"
"os"
"time"
"github.com/justinas/alice"
"github.com/rs/zerolog/hlog"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
)
@@ -41,30 +41,36 @@ func main() {
log.Fatal().Err(err).Msg("Failed to remove existing socket")
}
mux := http.NewServeMux()
driver.SetupHandlers(mux)
gin.SetMode(gin.ReleaseMode)
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not Found", http.StatusNotFound)
})
router := gin.New()
router.Use(core.GinLogger())
router.Use(gin.Recovery())
listener, err := net.Listen("unix", socketPath)
driver.SetupHandlers(router)
unixListener, err := net.Listen("unix", socketPath)
if err != nil {
log.Fatal().Err(err).Msg("Failed to listen on socket")
}
chain := alice.New()
chain = chain.Append(hlog.NewHandler(log.Logger))
chain = chain.Append(hlog.AccessHandler(func(r *http.Request, status, size int, duration time.Duration) {
hlog.FromRequest(r).Info().
Str("method", r.Method).
Str("url", r.URL.Path).
Int("status", status).
Msg("")
}))
tcpListener, err := net.Listen("tcp", ":8080")
if err != nil {
log.Fatal().Err(err).Msg("Failed to listen on TCP port 8080")
}
log.Info().Str("socket", socketPath).Msg("Irounmount plugin started, listening on")
if err := http.Serve(listener, chain.Then(mux)); err != nil {
log.Fatal().Err(err).Msg("Server stopped")
unixServer := &http.Server{Handler: router}
tcpServer := &http.Server{Handler: router}
go func() {
log.Info().Msg("Listening on TCP :8080")
if err := tcpServer.Serve(tcpListener); err != nil && err != http.ErrServerClosed {
log.Fatal().Err(err).Msg("TCP server error")
}
}()
log.Info().Msg("Listening on UNIX " + socketPath)
if err := unixServer.Serve(unixListener); err != nil && err != http.ErrServerClosed {
log.Fatal().Err(err).Msg("Unix server error")
}
}