From 7bc4ce8c961468312c2e68e4e77703ad30f4b2ed Mon Sep 17 00:00:00 2001 From: ostiwe Date: Tue, 4 Nov 2025 13:44:18 +0300 Subject: [PATCH 1/9] refactor!: Use gin router instead chi router - Removed chi dependencies - Updated router registration logic --- go.mod | 51 ++++-- go.sum | 210 ++++++++++++++++++++---- main.go | 51 +++--- pkg/http/errors.go | 15 +- router/controller/auth/controller.go | 63 ------- router/controller/auth/plain.go | 62 +++++++ router/controller/controller.go | 17 +- router/controller/ping/controller.go | 29 ++-- router/controller/service/controller.go | 107 ------------ router/controller/service/get.go | 60 +++++++ router/controller/service/public_get.go | 51 ++++++ router/midlleware/user.go | 29 ++-- router/server.go | 48 ++++-- 13 files changed, 499 insertions(+), 294 deletions(-) delete mode 100644 router/controller/auth/controller.go create mode 100644 router/controller/auth/plain.go delete mode 100644 router/controller/service/controller.go create mode 100644 router/controller/service/get.go create mode 100644 router/controller/service/public_get.go diff --git a/go.mod b/go.mod index 7a36ff9..d43fa4c 100644 --- a/go.mod +++ b/go.mod @@ -4,32 +4,39 @@ go 1.25.0 require ( github.com/alexflint/go-arg v1.6.0 + github.com/appleboy/gin-jwt/v3 v3.1.0 + github.com/gin-gonic/gin v1.11.0 github.com/go-andiamo/chioas v1.16.4 - github.com/go-chi/chi/v5 v5.2.2 - github.com/go-chi/jwtauth/v5 v5.3.3 - github.com/go-chi/render v1.0.3 github.com/go-co-op/gocron/v2 v2.17.0 github.com/golang-jwt/jwt/v5 v5.3.0 github.com/google/uuid v1.6.0 github.com/joho/godotenv v1.5.1 - github.com/lestrrat-go/jwx/v2 v2.1.6 github.com/pressly/goose/v3 v3.24.3 github.com/rabbitmq/amqp091-go v1.10.0 github.com/samber/lo v1.52.0 github.com/sirupsen/logrus v1.9.3 go.uber.org/mock v0.6.0 - golang.org/x/crypto v0.41.0 + golang.org/x/crypto v0.43.0 gorm.io/driver/postgres v1.6.0 gorm.io/gorm v1.30.1 ) require ( - github.com/ajg/form v1.5.1 // indirect github.com/alexflint/go-scalar v1.2.0 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect + github.com/bytedance/gopkg v0.1.3 // indirect + github.com/bytedance/sonic v1.14.1 // indirect + github.com/bytedance/sonic/loader v0.3.0 // indirect + github.com/cloudwego/base64x v0.1.6 // indirect + github.com/gabriel-vasile/mimetype v1.4.10 // indirect + github.com/gin-contrib/sse v1.1.0 // indirect github.com/go-andiamo/splitter v1.2.5 // indirect github.com/go-andiamo/urit v1.2.1 // indirect + github.com/go-chi/chi/v5 v5.2.2 // 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.28.0 // indirect github.com/goccy/go-json v0.10.5 // indirect + github.com/goccy/go-yaml v1.18.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/pgx/v5 v5.7.5 // indirect @@ -37,20 +44,32 @@ require ( github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/jonboulle/clockwork v0.5.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.3.0 // indirect github.com/kr/pretty v0.3.1 // indirect - github.com/lestrrat-go/blackmagic v1.0.4 // indirect - github.com/lestrrat-go/httpcc v1.0.1 // indirect - github.com/lestrrat-go/httprc v1.0.6 // indirect - github.com/lestrrat-go/iter v1.0.2 // indirect - github.com/lestrrat-go/option v1.0.1 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mfridman/interpolate v0.0.2 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect + github.com/quic-go/qpack v0.5.1 // indirect + github.com/quic-go/quic-go v0.55.0 // indirect + github.com/redis/rueidis v1.0.66 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect - github.com/segmentio/asm v1.2.0 // indirect github.com/sethvargo/go-retry v0.3.0 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.3.0 // indirect + github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect go.uber.org/multierr v1.11.0 // indirect + golang.org/x/arch v0.22.0 // indirect golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b // indirect - golang.org/x/sync v0.16.0 // indirect - golang.org/x/sys v0.35.0 // indirect - golang.org/x/text v0.28.0 // indirect + golang.org/x/mod v0.29.0 // indirect + golang.org/x/net v0.46.0 // indirect + golang.org/x/sync v0.17.0 // indirect + golang.org/x/sys v0.37.0 // indirect + golang.org/x/text v0.30.0 // indirect + golang.org/x/tools v0.38.0 // indirect + google.golang.org/protobuf v1.36.10 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 7621243..19b1b9d 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,61 @@ -github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= -github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= +dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8= +dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= +github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/alexflint/go-arg v1.6.0 h1:wPP9TwTPO54fUVQl4nZoxbFfKCcy5E6HBCumj1XVRSo= github.com/alexflint/go-arg v1.6.0/go.mod h1:A7vTJzvjoaSTypg4biM5uYNTkJ27SkNTArtYXnlqVO8= github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw= github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o= +github.com/appleboy/gin-jwt/v3 v3.1.0 h1:Q2DQ2MksmojwrYLsvIBTZ17zpWfeR8aHo8W9yu+hLtA= +github.com/appleboy/gin-jwt/v3 v3.1.0/go.mod h1:ANNEPdDkdOp6jXAbicMFX7N4mIIx70m9A3asDmXdbYo= +github.com/appleboy/gofight/v2 v2.1.2 h1:VOy3jow4vIK8BRQJoC/I9muxyYlJ2yb9ht2hZoS3rf4= +github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhplt43+Wczp3rw= +github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= +github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= +github.com/bytedance/sonic v1.14.1 h1:FBMC0zVz5XUmE4z9wF4Jey0An5FueFvOsTKKKtwIl7w= +github.com/bytedance/sonic v1.14.1/go.mod h1:gi6uhQLMbTdeP0muCnrjHLeCUPyb70ujhnNlhOylAFc= +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/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M= +github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU= +github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI= +github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M= +github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE= +github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk= +github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= +github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= +github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A= +github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw= +github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA= +github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 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/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40= +github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= +github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/docker/docker v28.3.3+incompatible h1:Dypm25kh4rmk49v1eiVbsAtpAsYURjYkaKubwuBdxEI= +github.com/docker/docker v28.3.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pMmjSD94= +github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE= +github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= +github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= 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/ebitengine/purego v0.8.4 h1:CF7LEKg5FFOsASUj0+QwaXf8Ht6TlFxg09+S9wz0omw= +github.com/ebitengine/purego v0.8.4/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/gabriel-vasile/mimetype v1.4.10 h1:zyueNbySn/z8mJZHLt6IPw0KoZsiQNszIpU+bX4+ZK0= +github.com/gabriel-vasile/mimetype v1.4.10/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s= +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.11.0 h1:OW/6PLjyusp2PPXtyxKHU0RbX6I/l28FTdDlae5ueWk= +github.com/gin-gonic/gin v1.11.0/go.mod h1:+iq/FyxlGzII0KHiBGjuNn4UNENUlKbGlNmc+W50Dls= github.com/go-andiamo/chioas v1.16.4 h1:aHtA3KLmfQfHRsGxjYPNjrD8cMR2uTncbjvcxY64B3Q= github.com/go-andiamo/chioas v1.16.4/go.mod h1:5ZZYYuGwlF/amxErKFUu3eXz6hZ5GEYu5vCk+Guw+uc= github.com/go-andiamo/splitter v1.2.5 h1:P3NovWMY2V14TJJSolXBvlOmGSZo3Uz+LtTl2bsV/eY= @@ -20,16 +64,33 @@ github.com/go-andiamo/urit v1.2.1 h1:5JHJb+TuzuGvXw9Y/LK/lQltCL2gpgHkCznI2vv9ZeY github.com/go-andiamo/urit v1.2.1/go.mod h1:9kgXBxUPHFZvXwlOPN1GimDuHl+JCfQuetN5nxBNlpQ= github.com/go-chi/chi/v5 v5.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618= github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops= -github.com/go-chi/jwtauth/v5 v5.3.3 h1:50Uzmacu35/ZP9ER2Ht6SazwPsnLQ9LRJy6zTZJpHEo= -github.com/go-chi/jwtauth/v5 v5.3.3/go.mod h1:O4QvPRuZLZghl9WvfVaON+ARfGzpD2PBX/QY5vUz7aQ= -github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4= -github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0= github.com/go-co-op/gocron/v2 v2.17.0 h1:e/oj6fcAM8vOOKZxv2Cgfmjo+s8AXC46po5ZPtaSea4= github.com/go-co-op/gocron/v2 v2.17.0/go.mod h1:Zii6he+Zfgy5W9B+JKk/KwejFOW0kZTFvHtwIpR4aBI= +github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= +github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +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= +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= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.28.0 h1:Q7ibns33JjyW48gHkuFT91qX48KG0ktULL6FgHdG688= +github.com/go-playground/validator/v10 v10.28.0/go.mod h1:GoI6I1SjPBh9p7ykNE/yj3fFYbyDOpwMn5KXd+m2hUU= 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/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw= +github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo= github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= +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/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= @@ -48,35 +109,76 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbdFz6I= github.com/jonboulle/clockwork v0.5.0/go.mod h1:3mZlmanh0g2NDKO5TWZVJAfofYk64M7XN3SzBPjZF60= +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/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= +github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= +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/lestrrat-go/blackmagic v1.0.4 h1:IwQibdnf8l2KoO+qC3uT4OaTWsW7tuRQXy9TRN9QanA= -github.com/lestrrat-go/blackmagic v1.0.4/go.mod h1:6AWFyKNNj0zEXQYfTMPfZrAXUWUfTIZ5ECEUEJaijtw= -github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE= -github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E= -github.com/lestrrat-go/httprc v1.0.6 h1:qgmgIRhpvBqexMJjA/PmwSvhNk679oqD1RbovdCGW8k= -github.com/lestrrat-go/httprc v1.0.6/go.mod h1:mwwz3JMTPBjHUkkDv/IGJ39aALInZLrhBp0X7KGUZlo= -github.com/lestrrat-go/iter v1.0.2 h1:gMXo1q4c2pHmC3dn8LzRhJfP1ceCbgSiT9lUydIzltI= -github.com/lestrrat-go/iter v1.0.2/go.mod h1:Momfcq3AnRlRjI5b5O8/G5/BvpzrhoFTZcn06fEOPt4= -github.com/lestrrat-go/jwx/v2 v2.1.6 h1:hxM1gfDILk/l5ylers6BX/Eq1m/pnxe9NBwW6lVfecA= -github.com/lestrrat-go/jwx/v2 v2.1.6/go.mod h1:Y722kU5r/8mV7fYDifjug0r8FK8mZdw0K0GpJw/l8pU= -github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU= -github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I= +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/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/magiconair/properties v1.8.10 h1:s31yESBquKXCV9a/ScB3ESkOjUYYv+X0rg8SYxI99mE= +github.com/magiconair/properties v1.8.10/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= 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/mdelapenya/tlscert v0.2.0 h1:7H81W6Z/4weDvZBNOfQte5GpIMo0lGYEeWbkGp5LJHI= +github.com/mdelapenya/tlscert v0.2.0/go.mod h1:O4njj3ELLnJjGdkN7M/vIVCpZ+Cf0L6muqOG4tLSl8o= github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY= github.com/mfridman/interpolate v0.0.2/go.mod h1:p+7uk6oE07mpE/Ik1b8EckO0O4ZXiGAfshKBWLUM9Xg= +github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= +github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= +github.com/moby/go-archive v0.1.0 h1:Kk/5rdW/g+H8NHdJW2gsXyZ7UnzvJNOy6VKJqueWdcQ= +github.com/moby/go-archive v0.1.0/go.mod h1:G9B+YoujNohJmrIYFBpSd54GTUB4lt9S+xVQvsJyFuo= +github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= +github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= +github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU= +github.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko= +github.com/moby/sys/user v0.4.0 h1:jhcMKit7SA80hivmFJcbB1vqmw//wU61Zdui2eQXuMs= +github.com/moby/sys/user v0.4.0/go.mod h1:bG+tYYYJgaMtRKgEmuueC0hJEAZWwtIbZTB+85uoHjs= +github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g= +github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= +github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= +github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= +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/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= +github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= 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/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8= +github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040= +github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M= +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/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +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/pressly/goose/v3 v3.24.3 h1:DSWWNwwggVUsYZ0X2VitiAa9sKuqtBfe+Jr9zFGwWlM= github.com/pressly/goose/v3 v3.24.3/go.mod h1:v9zYL4xdViLHCUUJh/mhjnm6JrK7Eul8AS93IxiZM4E= +github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI= +github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg= +github.com/quic-go/quic-go v0.55.0 h1:zccPQIqYCXDt5NmcEabyYvOnomjs8Tlwl7tISjJh9Mk= +github.com/quic-go/quic-go v0.55.0/go.mod h1:DR51ilwU1uE164KuWXhinFcKWGlEjzys2l8zUl5Ss1U= github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw= github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o= +github.com/redis/rueidis v1.0.66 h1:7rvyrl0vL/cAEkE97+L5v3MJ3Vg8IKz+KIxUTfT+yJk= +github.com/redis/rueidis v1.0.66/go.mod h1:Lkhr2QTgcoYBhxARU7kJRO8SyVlgUuEkcJO1Y8MCluA= 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/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= @@ -86,37 +188,83 @@ github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0t github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/samber/lo v1.52.0 h1:Rvi+3BFHES3A8meP33VPAxiBZX/Aws5RxrschYGjomw= github.com/samber/lo v1.52.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0= -github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys= -github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs= github.com/sethvargo/go-retry v0.3.0 h1:EEt31A35QhrcRZtrYFDTBg91cqZVnFL2navjDrah2SE= github.com/sethvargo/go-retry v0.3.0/go.mod h1:mNX17F0C/HguQMyMyJxcnU471gOZGxCLyYaFyAZraas= +github.com/shirou/gopsutil/v4 v4.25.6 h1:kLysI2JsKorfaFPcYmcJqbzROzsBWEOAtw6A7dIfqXs= +github.com/shirou/gopsutil/v4 v4.25.6/go.mod h1:PfybzyydfZcN+JMMjkF6Zb8Mq1A/VcogFFg7hj50W9c= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 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.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 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.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/testcontainers/testcontainers-go v0.39.0 h1:uCUJ5tA+fcxbFAB0uP3pIK3EJ2IjjDUHFSZ1H1UxAts= +github.com/testcontainers/testcontainers-go v0.39.0/go.mod h1:qmHpkG7H5uPf/EvOORKvS6EuDkBUPE3zpVGaH9NL7f8= +github.com/testcontainers/testcontainers-go/modules/redis v0.39.0 h1:p54qELdCx4Gftkxzf44k9RJRRhaO/S5ehP9zo8SUTLM= +github.com/testcontainers/testcontainers-go/modules/redis v0.39.0/go.mod h1:P1mTbHruHqAU2I26y0RADz1BitF59FLbQr7ceqN9bt4= +github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U= +github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +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= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= +go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw= +go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ= +go.opentelemetry.io/otel v1.37.0/go.mod h1:ehE/umFRLnuLa/vSccNq9oS1ErUlkkK71gMcN34UG8I= +go.opentelemetry.io/otel/metric v1.37.0 h1:mvwbQS5m0tbmqML4NqK+e3aDiO02vsf/WgbsdpcPoZE= +go.opentelemetry.io/otel/metric v1.37.0/go.mod h1:04wGrZurHYKOc+RKeye86GwKiTb9FKm1WHtO+4EVr2E= +go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4= +go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -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/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI= +golang.org/x/arch v0.22.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A= +golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04= +golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0= golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b h1:DXr+pvt3nC887026GRP39Ej11UATqWDmWuS99x26cD0= golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b/go.mod h1:4QTo5u+SEIbbKW1RacMZq1YEfOBqeXa19JeshGi+zc4= -golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= -golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA= +golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w= +golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4= +golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210= +golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= +golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/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.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng= -golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= +golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k= +golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM= +golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ= +golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs= +google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= +google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/main.go b/main.go index c7465e9..7376355 100644 --- a/main.go +++ b/main.go @@ -1,17 +1,12 @@ package main import ( - "fmt" - "net/http" - "git.ostiwe.com/ostiwe-com/status/migration" appLog "git.ostiwe.com/ostiwe-com/status/modules/log" "git.ostiwe.com/ostiwe-com/status/pkg/args" - "git.ostiwe.com/ostiwe-com/status/router" "git.ostiwe.com/ostiwe-com/status/server" _ "git.ostiwe.com/ostiwe-com/status/settings" "github.com/alexflint/go-arg" - "github.com/go-chi/chi/v5" ) var appArgs args.AppArgs @@ -34,29 +29,29 @@ func main() { return } - if appArgs.ServerDocumentation != nil { - appLog.Global.Get(appLog.SYSTEM).Info("Collect documentation") - - docs := router.Documentate() - if !appArgs.ServerDocumentation.Plain { - chiRouter := chi.NewRouter() - - err := docs.SetupRoutes(chiRouter, docs) - if err != nil { - appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Setup docs routes error: %v", err)) - return - } - - appLog.Global.Get(appLog.SYSTEM).Info(fmt.Sprintf("Start documentation server on port: %s", appArgs.ServerDocumentation.Port)) - err = http.ListenAndServe(fmt.Sprintf(":%s", appArgs.ServerDocumentation.Port), chiRouter) - if err != nil { - appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error: %v", err)) - } - - return - } - - } + // TODO: Rewrite to use gin router, instead of chi router + // if appArgs.ServerDocumentation != nil { + // appLog.Global.Get(appLog.SYSTEM).Info("Collect documentation") + // + // docs := router.Documentate() + // if !appArgs.ServerDocumentation.Plain { + // chiRouter := chi.NewRouter() + // + // err := docs.SetupRoutes(chiRouter, docs) + // if err != nil { + // appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Setup docs routes error: %v", err)) + // return + // } + // + // appLog.Global.Get(appLog.SYSTEM).Info(fmt.Sprintf("Start documentation server on port: %s", appArgs.ServerDocumentation.Port)) + // err = http.ListenAndServe(fmt.Sprintf(":%s", appArgs.ServerDocumentation.Port), chiRouter) + // if err != nil { + // appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error: %v", err)) + // } + // + // return + // } + // } appLog.Global.Get(appLog.SYSTEM).Info("Exit from application") } diff --git a/pkg/http/errors.go b/pkg/http/errors.go index f2b22e3..e5ba4c0 100644 --- a/pkg/http/errors.go +++ b/pkg/http/errors.go @@ -4,7 +4,7 @@ import ( "encoding/json" "net/http" - "github.com/go-chi/chi/v5/middleware" + "github.com/gin-gonic/gin" ) type ResponseErr struct { @@ -23,7 +23,7 @@ type ResponseErrBuilder interface { WithStatusCode(int) ResponseErrBuilder WithTrace(string) ResponseErrBuilder Ready() ResponseErrReadyToSend - Send(http.ResponseWriter, *http.Request) error + Send(ctx *gin.Context) error } type responseErrBuilder struct { @@ -92,11 +92,12 @@ func (r responseErrBuilder) Ready() ResponseErrReadyToSend { } } -func (r responseErrBuilder) Send(response http.ResponseWriter, request *http.Request) error { +func (r responseErrBuilder) Send(ginCtx *gin.Context) error { if r.ready == nil { r.ready = &ResponseErr{ Message: r.message, - Trace: middleware.GetReqID(request.Context()), + // TODO get traceID from gin context + Trace: "", Details: r.details, } } @@ -110,10 +111,10 @@ func (r responseErrBuilder) Send(response http.ResponseWriter, request *http.Req r.status = http.StatusInternalServerError } - response.Header().Set("Content-Type", "application/json") - response.WriteHeader(r.status) + ginCtx.Writer.Header().Set("Content-Type", "application/json") + ginCtx.Writer.WriteHeader(r.status) - _, err = response.Write(format) + _, err = ginCtx.Writer.Write(format) return err } diff --git a/router/controller/auth/controller.go b/router/controller/auth/controller.go deleted file mode 100644 index f775447..0000000 --- a/router/controller/auth/controller.go +++ /dev/null @@ -1,63 +0,0 @@ -package auth - -import ( - "net/http" - - "git.ostiwe.com/ostiwe-com/status/dto" - "git.ostiwe.com/ostiwe-com/status/modules/auth" - httpApp "git.ostiwe.com/ostiwe-com/status/pkg/http" - "git.ostiwe.com/ostiwe-com/status/router/controller" - "github.com/go-andiamo/chioas" - "github.com/go-chi/chi/v5" - "github.com/go-chi/render" -) - -type Controller struct { - authModule auth.Module -} - -func (*Controller) New() controller.Controller { - return &Controller{ - authModule: auth.New(), - } -} - -func (c *Controller) plainLogin(w http.ResponseWriter, r *http.Request) { - var payload dto.LoginRequest - - if err := render.Bind(r, &payload); err != nil { - sendErr := httpApp.NewResponseErrBuilder().WithStatusCode(http.StatusBadRequest).WithMessage(err.Error()).Send(w, r) - if sendErr != nil { - w.WriteHeader(http.StatusInternalServerError) - return - } - - return - } - - jwtString, err := c.authModule.Proceed(r.Context(), payload.Login, payload.Password) - if err != nil { - sendErr := httpApp.NewResponseErrBuilder().WithStatusCode(http.StatusBadRequest).WithMessage(err.Error()).Send(w, r) - if sendErr != nil { - w.WriteHeader(http.StatusInternalServerError) - return - } - - return - } - - response := dto.LoginResponse{ - AccessToken: *jwtString, - } - - render.JSON(w, r, response) - w.WriteHeader(http.StatusOK) -} - -func (c *Controller) Group(r chi.Router) { - r.Post("/auth/plain", c.plainLogin) -} - -func (c *Controller) Documentate() (*chioas.Paths, *chioas.Components) { - return nil, nil -} diff --git a/router/controller/auth/plain.go b/router/controller/auth/plain.go new file mode 100644 index 0000000..f3acde0 --- /dev/null +++ b/router/controller/auth/plain.go @@ -0,0 +1,62 @@ +package auth + +import ( + "net/http" + + "git.ostiwe.com/ostiwe-com/status/dto" + "git.ostiwe.com/ostiwe-com/status/modules/auth" + httpApp "git.ostiwe.com/ostiwe-com/status/pkg/http" + "git.ostiwe.com/ostiwe-com/status/router/controller" + "github.com/gin-gonic/gin" +) + +type PlainAuthController struct { + authModule auth.Module +} + +func (c *PlainAuthController) Handler() gin.HandlerFunc { + return func(ginCtx *gin.Context) { + var payload dto.LoginRequest + + if err := ginCtx.ShouldBindJSON(&payload); err != nil { + sendErr := httpApp.NewResponseErrBuilder().WithStatusCode(http.StatusBadRequest).WithMessage(err.Error()).Send(ginCtx) + if sendErr != nil { + ginCtx.Writer.WriteHeader(http.StatusInternalServerError) + return + } + + return + } + + jwtString, err := c.authModule.Proceed(ginCtx.Request.Context(), payload.Login, payload.Password) + if err != nil { + sendErr := httpApp.NewResponseErrBuilder().WithStatusCode(http.StatusBadRequest).WithMessage(err.Error()).Send(ginCtx) + if sendErr != nil { + ginCtx.Writer.WriteHeader(http.StatusInternalServerError) + return + } + + return + } + + response := dto.LoginResponse{ + AccessToken: *jwtString, + } + + ginCtx.JSON(http.StatusOK, response) + } +} + +func (c *PlainAuthController) Method() string { + return http.MethodPost +} + +func (c *PlainAuthController) Path() string { + return "/api/v1/auth" +} + +func (*PlainAuthController) New() controller.Controller { + return &PlainAuthController{ + authModule: auth.New(), + } +} diff --git a/router/controller/controller.go b/router/controller/controller.go index de9b44d..6e26ecd 100644 --- a/router/controller/controller.go +++ b/router/controller/controller.go @@ -1,12 +1,23 @@ package controller import ( + "github.com/gin-gonic/gin" "github.com/go-andiamo/chioas" - "github.com/go-chi/chi/v5" ) +// SecuredController - means, controller has middlewares +// Maybe should rename it later +type SecuredController interface { + Middlewares() []gin.HandlerFunc +} + +type DocumentateController interface { + Documentate() (*chioas.Paths, *chioas.Components) +} + type Controller interface { New() Controller - Group(r chi.Router) - Documentate() (*chioas.Paths, *chioas.Components) + Handler() gin.HandlerFunc + Method() string + Path() string } diff --git a/router/controller/ping/controller.go b/router/controller/ping/controller.go index cf2df68..ff7a0a8 100644 --- a/router/controller/ping/controller.go +++ b/router/controller/ping/controller.go @@ -5,27 +5,32 @@ import ( "git.ostiwe.com/ostiwe-com/status/modules/log" "git.ostiwe.com/ostiwe-com/status/router/controller" + "github.com/gin-gonic/gin" "github.com/go-andiamo/chioas" - "github.com/go-chi/chi/v5" ) type Controller struct { } +func (c *Controller) Method() string { + return http.MethodGet +} + +func (c *Controller) Path() string { + return "/api/v1/ping" +} + func (*Controller) New() controller.Controller { return &Controller{} } -func (c *Controller) Group(r chi.Router) { - - r.Get("/ping", c.PingHandler) -} - -func (c *Controller) PingHandler(w http.ResponseWriter, _ *http.Request) { - _, err := w.Write([]byte("pong")) - if err != nil { - log.Global.Get(log.SERVER).Error(err) - return +func (c *Controller) Handler() gin.HandlerFunc { + return func(ginCtx *gin.Context) { + _, err := ginCtx.Writer.Write([]byte("pong")) + if err != nil { + log.Global.Get(log.SERVER).Error(err) + return + } } } @@ -34,7 +39,7 @@ func (c *Controller) Documentate() (*chioas.Paths, *chioas.Components) { "/ping": chioas.Path{ Methods: map[string]chioas.Method{ http.MethodGet: { - Handler: c.PingHandler, + Handler: c.Handler(), Responses: chioas.Responses{ http.StatusOK: { ContentType: "plain/text", diff --git a/router/controller/service/controller.go b/router/controller/service/controller.go deleted file mode 100644 index 617b2a1..0000000 --- a/router/controller/service/controller.go +++ /dev/null @@ -1,107 +0,0 @@ -package service - -import ( - "net/http" - - "git.ostiwe.com/ostiwe-com/status/modules/jwt" - "git.ostiwe.com/ostiwe-com/status/modules/log" - http2 "git.ostiwe.com/ostiwe-com/status/pkg/http" - "git.ostiwe.com/ostiwe-com/status/repository" - "git.ostiwe.com/ostiwe-com/status/router/controller" - "git.ostiwe.com/ostiwe-com/status/router/midlleware" - "git.ostiwe.com/ostiwe-com/status/transform" - "github.com/go-andiamo/chioas" - "github.com/go-chi/chi/v5" - "github.com/go-chi/jwtauth/v5" -) - -type Controller struct { - serviceRepository repository.Service -} - -func (c *Controller) New() controller.Controller { - return &Controller{ - serviceRepository: repository.NewServiceRepository(), - } -} - -func (c *Controller) Group(r chi.Router) { - c.public(r) - c.internal(r) -} - -func (c *Controller) public(r chi.Router) { - r.Get("/api/public/service", c.GetAllServicesPublic) -} - -func (c *Controller) internal(r chi.Router) { - r.Group(func(r chi.Router) { - r.Use( - jwtauth.Verifier(jwt.TokenAuth), - jwtauth.Authenticator(jwt.TokenAuth), - midlleware.SetUserFromJWT, - ) - - r.Get("/api/v1/service", c.GetAllServices) - }) - -} - -func (c *Controller) GetAllServicesPublic(w http.ResponseWriter, r *http.Request) { - items, err := c.serviceRepository.All(r.Context(), -1, 0, true) - if err != nil { - log.Global.Get(log.SERVER).Error(err) - - writeErr := http2.NewResponseErrBuilder(). - WithMessage("Fetch service error"). - WithStatusCode(http.StatusInternalServerError). - Send(w, r) - if writeErr != nil { - log.Global.Get(log.SERVER).Error(writeErr) - } - - return - } - - err = http2.JSON(w, transform.PublicServices(items...), http.StatusOK) - if err != nil { - log.Global.Get(log.SERVER).Error(err) - } -} - -func (c *Controller) GetAllServices(w http.ResponseWriter, r *http.Request) { - limit, offset, errReady := http2.ExtractLimitOffset(r) - if errReady != nil { - err := errReady.Send(w) - if err != nil { - log.Global.Get(log.SERVER).Error(err) - return - } - - return - } - - items, err := c.serviceRepository.All(r.Context(), limit, offset, false) - if err != nil { - log.Global.Get(log.SERVER).Error(err) - - writeErr := http2.NewResponseErrBuilder(). - WithMessage("Fetch service error"). - WithStatusCode(http.StatusInternalServerError). - Send(w, r) - if writeErr != nil { - log.Global.Get(log.SERVER).Error(writeErr) - } - - return - } - - err = http2.JSON(w, items, http.StatusOK) - if err != nil { - log.Global.Get(log.SERVER).Error(err) - } -} - -func (c *Controller) Documentate() (*chioas.Paths, *chioas.Components) { - return nil, nil -} diff --git a/router/controller/service/get.go b/router/controller/service/get.go new file mode 100644 index 0000000..e0d7080 --- /dev/null +++ b/router/controller/service/get.go @@ -0,0 +1,60 @@ +package service + +import ( + "net/http" + + "git.ostiwe.com/ostiwe-com/status/modules/jwt" + "git.ostiwe.com/ostiwe-com/status/modules/log" + http2 "git.ostiwe.com/ostiwe-com/status/pkg/http" + "git.ostiwe.com/ostiwe-com/status/repository" + "git.ostiwe.com/ostiwe-com/status/router/controller" + "git.ostiwe.com/ostiwe-com/status/router/midlleware" + "git.ostiwe.com/ostiwe-com/status/transform" + "github.com/gin-gonic/gin" +) + +type GetServices struct { + serviceRepository repository.Service +} + +func (g *GetServices) New() controller.Controller { + return &GetServices{ + serviceRepository: repository.NewServiceRepository(), + } +} + +func (g *GetServices) Handler() gin.HandlerFunc { + return func(c *gin.Context) { + items, err := g.serviceRepository.All(c.Request.Context(), -1, 0, true) + if err != nil { + log.Global.Get(log.SERVER).Error(err) + + writeErr := http2.NewResponseErrBuilder(). + WithMessage("Fetch service error"). + WithStatusCode(http.StatusInternalServerError). + Send(c) + if writeErr != nil { + log.Global.Get(log.SERVER).Error(writeErr) + } + + return + } + + c.JSON(http.StatusOK, transform.PublicServices(items...)) + } +} + +func (g *GetServices) Method() string { + return http.MethodGet +} + +func (g *GetServices) Path() string { + return "/api/v1/services" +} + +func (g *GetServices) Middlewares() []gin.HandlerFunc { + return []gin.HandlerFunc{ + jwt.AuthMiddleware.MiddlewareFunc(), + midlleware.SetUserFromJWT(), + } +} diff --git a/router/controller/service/public_get.go b/router/controller/service/public_get.go new file mode 100644 index 0000000..cdc54e5 --- /dev/null +++ b/router/controller/service/public_get.go @@ -0,0 +1,51 @@ +package service + +import ( + "net/http" + + "git.ostiwe.com/ostiwe-com/status/modules/log" + http2 "git.ostiwe.com/ostiwe-com/status/pkg/http" + "git.ostiwe.com/ostiwe-com/status/repository" + "git.ostiwe.com/ostiwe-com/status/router/controller" + "git.ostiwe.com/ostiwe-com/status/transform" + "github.com/gin-gonic/gin" +) + +type PublicGetServicesController struct { + serviceRepository repository.Service +} + +func (p *PublicGetServicesController) New() controller.Controller { + return &PublicGetServicesController{ + serviceRepository: repository.NewServiceRepository(), + } +} + +func (p *PublicGetServicesController) Handler() gin.HandlerFunc { + return func(c *gin.Context) { + items, err := p.serviceRepository.All(c.Request.Context(), -1, 0, true) + if err != nil { + log.Global.Get(log.SERVER).Error(err) + + writeErr := http2.NewResponseErrBuilder(). + WithMessage("Fetch service error"). + WithStatusCode(http.StatusInternalServerError). + Send(c) + if writeErr != nil { + log.Global.Get(log.SERVER).Error(writeErr) + } + + return + } + + c.JSON(http.StatusOK, transform.PublicServices(items...)) + } +} + +func (p *PublicGetServicesController) Method() string { + return http.MethodGet +} + +func (p *PublicGetServicesController) Path() string { + return "/api/v1/public/services" +} diff --git a/router/midlleware/user.go b/router/midlleware/user.go index 8cf692f..ba3bea3 100644 --- a/router/midlleware/user.go +++ b/router/midlleware/user.go @@ -4,30 +4,39 @@ import ( "context" "net/http" + "git.ostiwe.com/ostiwe-com/status/modules/jwt" "git.ostiwe.com/ostiwe-com/status/repository" - "github.com/go-chi/jwtauth/v5" + "github.com/gin-gonic/gin" ) -func SetUserFromJWT(next http.Handler) http.Handler { - fn := func(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - token, _, err := jwtauth.FromContext(ctx) +func SetUserFromJWT() gin.HandlerFunc { + return func(c *gin.Context) { + ctx := c.Request.Context() + token, err := jwt.AuthMiddleware.ParseToken(c) if err != nil { - w.WriteHeader(http.StatusUnauthorized) + c.Writer.WriteHeader(http.StatusUnauthorized) return } userRepo := repository.NewUserRepository() - user, err := userRepo.FindByLogin(ctx, token.Subject()) + subject, err := token.Claims.GetSubject() + if err != nil { + c.Writer.WriteHeader(http.StatusUnauthorized) + return + } + + user, err := userRepo.FindByLogin(ctx, subject) if err != nil || user == nil { - w.WriteHeader(http.StatusUnauthorized) + c.Writer.WriteHeader(http.StatusUnauthorized) return } ctx = context.WithValue(ctx, "user", user) - next.ServeHTTP(w, r.WithContext(ctx)) + + c.Request = c.Request.WithContext(ctx) + + c.Next() } - return http.HandlerFunc(fn) } diff --git a/router/server.go b/router/server.go index c29b7ce..7884efe 100644 --- a/router/server.go +++ b/router/server.go @@ -11,39 +11,48 @@ import ( "git.ostiwe.com/ostiwe-com/status/router/controller/ping" "git.ostiwe.com/ostiwe-com/status/router/controller/service" "git.ostiwe.com/ostiwe-com/status/version" + "github.com/gin-gonic/gin" "github.com/go-andiamo/chioas" - "github.com/go-chi/chi/v5" - "github.com/go-chi/chi/v5/middleware" ) func getControllers() []controller.Controller { return []controller.Controller{ new(ping.Controller).New(), - new(service.Controller).New(), - new(auth.Controller).New(), + new(service.GetServices).New(), + new(auth.PlainAuthController).New(), } } -func InitRoutes() *chi.Mux { +func InitRoutes() *gin.Engine { log.Global.Get(log.SERVER).Info("Setting up routers") startTime := time.Now() - httpLogger := middleware.RequestLogger(&middleware.DefaultLogFormatter{Logger: log.Global.Get(log.SERVER), NoColor: false}) - - r := chi.NewRouter() - r.Use(httpLogger) + r := gin.New() r.Use( - middleware.RequestID, - middleware.RealIP, - middleware.StripSlashes, - middleware.Recoverer, - middleware.CleanPath, - middleware.Timeout(15*time.Second), + gin.Recovery(), + gin.LoggerWithConfig(gin.LoggerConfig{ + Output: log.Global.Get(log.SERVER).Out, + }), ) ctrlList := getControllers() for _, ctrl := range ctrlList { - r.Group(ctrl.Group) + secured, ok := ctrl.(controller.SecuredController) + if ok { + r.Handle( + ctrl.Method(), + ctrl.Path(), + append(secured.Middlewares(), ctrl.Handler())..., + ) + + continue + } + + r.Handle( + ctrl.Method(), + ctrl.Path(), + ctrl.Handler(), + ) } log.Global.Get(log.SERVER).Info(fmt.Sprintf("Initialized %d routers", len(ctrlList))) @@ -77,7 +86,12 @@ func Documentate() chioas.Definition { } for _, ctrl := range ctrlList { - documentatePaths, components := ctrl.Documentate() + documentated, ok := ctrl.(controller.DocumentateController) + if !ok { + continue + } + + documentatePaths, components := documentated.Documentate() if documentatePaths != nil { for path, pathDoc := range *documentatePaths { From 7be0c7c6d3c0a5620b6c3d20f882c82eb0dfc67e Mon Sep 17 00:00:00 2001 From: ostiwe Date: Tue, 4 Nov 2025 13:46:19 +0300 Subject: [PATCH 2/9] refactor!: Update JWT logic - Change algo from ed25519 to rsa256 - Use gin-jwt lib for JWT middleware --- .env | 4 +-- _example/keys/jwt_private.pem | 28 ++++++++++++++++++++ _example/keys/jwt_private_key.pem | 3 --- _example/keys/jwt_public.pem | 9 +++++++ _example/keys/jwt_public_key.pem | 3 --- modules/jwt/jwt.go | 44 ++++++++++++++++--------------- 6 files changed, 62 insertions(+), 29 deletions(-) create mode 100644 _example/keys/jwt_private.pem delete mode 100644 _example/keys/jwt_private_key.pem create mode 100644 _example/keys/jwt_public.pem delete mode 100644 _example/keys/jwt_public_key.pem diff --git a/.env b/.env index 494244b..8442022 100644 --- a/.env +++ b/.env @@ -20,6 +20,6 @@ RABBIT_PASSWORD=user RABBIT_HOST=localhost RABBIT_PORT=5672 -JWT_SIGN_PUBLIC_KEY_PATH=_example/keys/jwt_public_key.pem -JWT_SIGN_PRIVATE_KEY_PATH=_example/keys/jwt_private_key.pem +JWT_SIGN_PUBLIC_KEY_PATH=_example/keys/jwt_public.pem +JWT_SIGN_PRIVATE_KEY_PATH=_example/keys/jwt_private.pem JWT_TRUSTED_HOSTS= \ No newline at end of file diff --git a/_example/keys/jwt_private.pem b/_example/keys/jwt_private.pem new file mode 100644 index 0000000..eb4693d --- /dev/null +++ b/_example/keys/jwt_private.pem @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC5Pp5QB2glt2gs +l2A7I9h2ManWeoe/83TOethZGyC9ujZTgA3kO8M3bs7reEYuwEQvMijx3Qvf/ORp +cMag+VmNPKBWCpdzY3PANdQP546JqUjIVCNyPr2+z6N+ColSqAiuB159F7g6Lfei +5TR25Eu2tadvBX+oMCLrziIPwOuac4ZybyvEs5uPGN/uyQbN3d2bxa/07YkdMqDh +alVQZJ95r9vJj6wycxn1cslbGDXYDyXx7aC1x/8dLcewYb79WoBdTFHaa+2Kpv2q +e2LRgrAIk1JuHKNar5PjMoegsQ10WUeKl92afEL1MxSFliQbNyND91yNMTGkM+e2 +ERUyZHZpAgMBAAECggEAAgUaZ5O/GVsvv/26E0cDqR1HRXMSWB/c3BQHmCglMiBt +z3kH3b9flHMJP1TRShj3XV7iBqojAyMgL/ymc9KoPPOmaW3F40CYPmYv3OkI2zws +8p9FQC2KNuKPfTQ69Vtm9dPXfkx0CjFeYAi5CttYLoK6U8n274Pv24ukwDB5uTZI +wXcAsWeiB7UD4gdIU5JwFr1Awx7oWgxT979XC+X/jIKDHfpRSmF+VDz8Mkoi4gLK +YIqq3hXeMm9DKHuqxjH193G3oh06/yYZlS2durVWaQsu98WbkhZKIlV9Mgl+aPm/ +NgjG3QmcbTaPTrf+wrepiAr31NSTkOn5G07mFCMeMQKBgQDvxkRmuQ25F+8QfsFg +C0hIW7UF8V7y5bsIguzD+RymsfO8LaIcXPbZA+XRLvmzAxJuG4TTBd9Hk9VueEQF +dTXVjpjSSx2zWb1UkGA2TE2aQO+yhJ6gbhZ/OOJb3Kxp5imXRq/EgT6f5APnY31E +ysnALFSx+9BuAOo4gwvao+/30QKBgQDFx7P1wMuoCrFpr0mplqa4bXuM6H6cUonn +a9vPrVRwbRSx8xc+iMRoFjOR2BWsMxhAm2t6WleT1DrOXKxjHQmyf6VGknGydxdX +al4yLjkeD8nzfDR/EhVDMN+4ld990WNAZZWm+rX4Y4mISt8o8Z0Tq8N9R3s4g4aT +eFYBXHTTGQKBgCyVdz6Khky2cJNmnlpXfrdFpiFWwkr0AJUSkyfVeEheqm2BJrWT +a6rqmJ8O1ws8NP8YSthaLSxIBtWlszA4nSv6edwQb5NbymKg/eLayUs3a9qL4lr+ +XVyGnUBrhfui+nTQhfpJ9fURFtC9pRtXgbAkDhOSOS1bKjIb2+ZpuUMhAoGBALGZ +jK4nvDlfsMR4VStmTrvaBFIaDGePbqpTHoW03dg++5B3++15nvTgytoyMfP5xdNu +POsX6QCkWVIpwdsWnjidiup+Yn6hlmI27/Mbssqd3vk4FWPt9w3o+1yjqJcwyXFw +Rxw0kedEaqHqqc34eNbLLLZ409uBr/0I2CJMxdMxAoGAYVED4ltIlK8Z9fKaoNuG +eC6FBEDsN2RnXZg2qyE2yEw9DwWun6e42CO/mDXfRB2jOFxSVXP27w+6G9dsN+QG +U9Gv+AZY1Kr29qvHHheA6RhyeGMSrsfBj7U2TmUzj2xwvjoENsxBj1rDoCgIK8hB +o/nsWmEy9tf6xs8KTjztHZw= +-----END PRIVATE KEY----- diff --git a/_example/keys/jwt_private_key.pem b/_example/keys/jwt_private_key.pem deleted file mode 100644 index 385ed01..0000000 --- a/_example/keys/jwt_private_key.pem +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PRIVATE KEY----- -MC4CAQAwBQYDK2VwBCIEIErwGenQ53CBtItiMuRBUgrn5/l1uYW6RiAoE+9IFqtj ------END PRIVATE KEY----- diff --git a/_example/keys/jwt_public.pem b/_example/keys/jwt_public.pem new file mode 100644 index 0000000..43cc7e5 --- /dev/null +++ b/_example/keys/jwt_public.pem @@ -0,0 +1,9 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuT6eUAdoJbdoLJdgOyPY +djGp1nqHv/N0znrYWRsgvbo2U4AN5DvDN27O63hGLsBELzIo8d0L3/zkaXDGoPlZ +jTygVgqXc2NzwDXUD+eOialIyFQjcj69vs+jfgqJUqgIrgdefRe4Oi33ouU0duRL +trWnbwV/qDAi684iD8DrmnOGcm8rxLObjxjf7skGzd3dm8Wv9O2JHTKg4WpVUGSf +ea/byY+sMnMZ9XLJWxg12A8l8e2gtcf/HS3HsGG+/VqAXUxR2mvtiqb9qnti0YKw +CJNSbhyjWq+T4zKHoLENdFlHipfdmnxC9TMUhZYkGzcjQ/dcjTExpDPnthEVMmR2 +aQIDAQAB +-----END PUBLIC KEY----- diff --git a/_example/keys/jwt_public_key.pem b/_example/keys/jwt_public_key.pem deleted file mode 100644 index 8974694..0000000 --- a/_example/keys/jwt_public_key.pem +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PUBLIC KEY----- -MCowBQYDK2VwAyEANttz9RhiE7FXL4A/PX3GfgxhWxSwKy5zhxrNHXifszs= ------END PUBLIC KEY----- diff --git a/modules/jwt/jwt.go b/modules/jwt/jwt.go index eafe250..39df32c 100644 --- a/modules/jwt/jwt.go +++ b/modules/jwt/jwt.go @@ -1,24 +1,24 @@ package jwt import ( - "crypto/ed25519" + "crypto/rsa" + "net/http" "os" "strings" "time" "git.ostiwe.com/ostiwe-com/status/model" "git.ostiwe.com/ostiwe-com/status/settings" - "github.com/go-chi/jwtauth/v5" + ginJwt "github.com/appleboy/gin-jwt/v3" "github.com/golang-jwt/jwt/v5" - "github.com/lestrrat-go/jwx/v2/jwa" ) var ( - signKey *ed25519.PrivateKey - publicSignKey *ed25519.PublicKey - signMethod jwt.SigningMethod + signKey *rsa.PrivateKey + publicSignKey *rsa.PublicKey + signMethod jwt.SigningMethod = jwt.SigningMethodRS256 - TokenAuth *jwtauth.JWTAuth + AuthMiddleware *ginJwt.GinJWTMiddleware ) func init() { @@ -32,6 +32,8 @@ func init() { jwtPrivateKeyPath = settings.WorkingDir + "/" + jwtPrivateKeyPath } + var err error + publicFile, err := os.ReadFile(jwtPublicKeyPath) if err != nil { panic(err) @@ -42,31 +44,31 @@ func init() { panic(err) } - privateKey, err := jwt.ParseEdPrivateKeyFromPEM(privateFile) + signKey, err = jwt.ParseRSAPrivateKeyFromPEM(privateFile) if err != nil { panic(err) } - publicKey, err := jwt.ParseEdPublicKeyFromPEM(publicFile) + publicSignKey, err = jwt.ParseRSAPublicKeyFromPEM(publicFile) if err != nil { panic(err) } - pk, ok := privateKey.(ed25519.PrivateKey) - if !ok { - panic("invalid ed25519 private key") + AuthMiddleware = &ginJwt.GinJWTMiddleware{ + SigningAlgorithm: signMethod.Alg(), + PrivKeyBytes: privateFile, + PubKeyBytes: publicFile, + Timeout: time.Hour * 6, + MaxRefresh: time.Hour * 24 * 7, + SecureCookie: true, + CookieHTTPOnly: true, + CookieSameSite: http.SameSiteStrictMode, + SendCookie: true, } - k, ok := publicKey.(ed25519.PublicKey) - if !ok { - panic("invalid ed25519 public key") + if err = AuthMiddleware.MiddlewareInit(); err != nil { + panic(err) } - - signKey = &pk - publicSignKey = &k - signMethod = jwt.SigningMethodEdDSA - - TokenAuth = jwtauth.New(string(jwa.EdDSA), signKey, publicSignKey) } func CreateByUser(user *model.User) (string, error) { From 3fc545f067d82aa9476d9d089f22df5ac2c2acb2 Mon Sep 17 00:00:00 2001 From: ostiwe Date: Tue, 4 Nov 2025 13:48:03 +0300 Subject: [PATCH 3/9] feat: Update dependencies --- go.mod | 14 ++++++++------ go.sum | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index d43fa4c..04a3fbd 100644 --- a/go.mod +++ b/go.mod @@ -4,21 +4,21 @@ go 1.25.0 require ( github.com/alexflint/go-arg v1.6.0 - github.com/appleboy/gin-jwt/v3 v3.1.0 + github.com/appleboy/gin-jwt/v3 v3.2.0 github.com/gin-gonic/gin v1.11.0 - github.com/go-andiamo/chioas v1.16.4 + github.com/go-andiamo/chioas v1.19.0 github.com/go-co-op/gocron/v2 v2.17.0 github.com/golang-jwt/jwt/v5 v5.3.0 github.com/google/uuid v1.6.0 github.com/joho/godotenv v1.5.1 - github.com/pressly/goose/v3 v3.24.3 + github.com/pressly/goose/v3 v3.26.0 github.com/rabbitmq/amqp091-go v1.10.0 github.com/samber/lo v1.52.0 github.com/sirupsen/logrus v1.9.3 go.uber.org/mock v0.6.0 golang.org/x/crypto v0.43.0 gorm.io/driver/postgres v1.6.0 - gorm.io/gorm v1.30.1 + gorm.io/gorm v1.31.1 ) require ( @@ -31,7 +31,7 @@ require ( github.com/gin-contrib/sse v1.1.0 // indirect github.com/go-andiamo/splitter v1.2.5 // indirect github.com/go-andiamo/urit v1.2.1 // indirect - github.com/go-chi/chi/v5 v5.2.2 // indirect + github.com/go-chi/chi/v5 v5.2.3 // 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.28.0 // indirect @@ -62,8 +62,9 @@ require ( github.com/ugorji/go/codec v1.3.0 // indirect github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect go.uber.org/multierr v1.11.0 // indirect + go.yaml.in/yaml/v2 v2.4.3 // indirect golang.org/x/arch v0.22.0 // indirect - golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b // indirect + golang.org/x/exp v0.0.0-20251009144603-d2f985daa21b // indirect golang.org/x/mod v0.29.0 // indirect golang.org/x/net v0.46.0 // indirect golang.org/x/sync v0.17.0 // indirect @@ -72,4 +73,5 @@ require ( golang.org/x/tools v0.38.0 // indirect google.golang.org/protobuf v1.36.10 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + sigs.k8s.io/yaml v1.6.0 // indirect ) diff --git a/go.sum b/go.sum index 19b1b9d..7dc0990 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+W github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o= github.com/appleboy/gin-jwt/v3 v3.1.0 h1:Q2DQ2MksmojwrYLsvIBTZ17zpWfeR8aHo8W9yu+hLtA= github.com/appleboy/gin-jwt/v3 v3.1.0/go.mod h1:ANNEPdDkdOp6jXAbicMFX7N4mIIx70m9A3asDmXdbYo= +github.com/appleboy/gin-jwt/v3 v3.2.0 h1:Ifa8Zsm2cZ93u/HIAhcTmftTK8rIaaoAoH77lcajWD0= +github.com/appleboy/gin-jwt/v3 v3.2.0/go.mod h1:ANNEPdDkdOp6jXAbicMFX7N4mIIx70m9A3asDmXdbYo= github.com/appleboy/gofight/v2 v2.1.2 h1:VOy3jow4vIK8BRQJoC/I9muxyYlJ2yb9ht2hZoS3rf4= github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhplt43+Wczp3rw= github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= @@ -58,12 +60,16 @@ github.com/gin-gonic/gin v1.11.0 h1:OW/6PLjyusp2PPXtyxKHU0RbX6I/l28FTdDlae5ueWk= github.com/gin-gonic/gin v1.11.0/go.mod h1:+iq/FyxlGzII0KHiBGjuNn4UNENUlKbGlNmc+W50Dls= github.com/go-andiamo/chioas v1.16.4 h1:aHtA3KLmfQfHRsGxjYPNjrD8cMR2uTncbjvcxY64B3Q= github.com/go-andiamo/chioas v1.16.4/go.mod h1:5ZZYYuGwlF/amxErKFUu3eXz6hZ5GEYu5vCk+Guw+uc= +github.com/go-andiamo/chioas v1.19.0 h1:LEMU0Wv86uB1Y2RSiCKkdswCFp0FSHyYi49E+DMC6z8= +github.com/go-andiamo/chioas v1.19.0/go.mod h1:J7ffP8Qm9rvODPy3ghAsdCNIQbyIH4AFuuMdceeT6YU= github.com/go-andiamo/splitter v1.2.5 h1:P3NovWMY2V14TJJSolXBvlOmGSZo3Uz+LtTl2bsV/eY= github.com/go-andiamo/splitter v1.2.5/go.mod h1:8WHU24t9hcMKU5FXDQb1hysSEC/GPuivIp0uKY1J8gw= github.com/go-andiamo/urit v1.2.1 h1:5JHJb+TuzuGvXw9Y/LK/lQltCL2gpgHkCznI2vv9ZeY= github.com/go-andiamo/urit v1.2.1/go.mod h1:9kgXBxUPHFZvXwlOPN1GimDuHl+JCfQuetN5nxBNlpQ= github.com/go-chi/chi/v5 v5.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618= github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops= +github.com/go-chi/chi/v5 v5.2.3 h1:WQIt9uxdsAbgIYgid+BpYc+liqQZGMHRaUwp0JUcvdE= +github.com/go-chi/chi/v5 v5.2.3/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops= github.com/go-co-op/gocron/v2 v2.17.0 h1:e/oj6fcAM8vOOKZxv2Cgfmjo+s8AXC46po5ZPtaSea4= github.com/go-co-op/gocron/v2 v2.17.0/go.mod h1:Zii6he+Zfgy5W9B+JKk/KwejFOW0kZTFvHtwIpR4aBI= github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= @@ -171,6 +177,8 @@ github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/pressly/goose/v3 v3.24.3 h1:DSWWNwwggVUsYZ0X2VitiAa9sKuqtBfe+Jr9zFGwWlM= github.com/pressly/goose/v3 v3.24.3/go.mod h1:v9zYL4xdViLHCUUJh/mhjnm6JrK7Eul8AS93IxiZM4E= +github.com/pressly/goose/v3 v3.26.0 h1:KJakav68jdH0WDvoAcj8+n61WqOIaPGgH0bJWS6jpmM= +github.com/pressly/goose/v3 v3.26.0/go.mod h1:4hC1KrritdCxtuFsqgs1R4AU5bWtTAf+cnWvfhf2DNY= github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI= github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg= github.com/quic-go/quic-go v0.55.0 h1:zccPQIqYCXDt5NmcEabyYvOnomjs8Tlwl7tISjJh9Mk= @@ -243,12 +251,16 @@ go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0= +go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8= golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI= golang.org/x/arch v0.22.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A= golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04= golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0= golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b h1:DXr+pvt3nC887026GRP39Ej11UATqWDmWuS99x26cD0= golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b/go.mod h1:4QTo5u+SEIbbKW1RacMZq1YEfOBqeXa19JeshGi+zc4= +golang.org/x/exp v0.0.0-20251009144603-d2f985daa21b h1:18qgiDvlvH7kk8Ioa8Ov+K6xCi0GMvmGfGW0sgd/SYA= +golang.org/x/exp v0.0.0-20251009144603-d2f985daa21b/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70= golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA= golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w= golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4= @@ -275,11 +287,18 @@ gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4= gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo= gorm.io/gorm v1.30.1 h1:lSHg33jJTBxs2mgJRfRZeLDG+WZaHYCk3Wtfl6Ngzo4= gorm.io/gorm v1.30.1/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= +gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg= +gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs= modernc.org/libc v1.65.0 h1:e183gLDnAp9VJh6gWKdTy0CThL9Pt7MfcR/0bgb7Y1Y= modernc.org/libc v1.65.0/go.mod h1:7m9VzGq7APssBTydds2zBcxGREwvIGpuUBaKTXdm2Qs= +modernc.org/libc v1.66.3 h1:cfCbjTUcdsKyyZZfEUKfoHcP3S0Wkvz3jgSzByEWVCQ= modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg= modernc.org/memory v1.10.0 h1:fzumd51yQ1DxcOxSO+S6X7+QTuVU+n8/Aj7swYjFfC4= modernc.org/memory v1.10.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw= +modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI= modernc.org/sqlite v1.37.0 h1:s1TMe7T3Q3ovQiK2Ouz4Jwh7dw4ZDqbebSDTlSJdfjI= modernc.org/sqlite v1.37.0/go.mod h1:5YiWv+YviqGMuGw4V+PNplcyaJ5v+vQd7TQOgkACoJM= +modernc.org/sqlite v1.38.2 h1:Aclu7+tgjgcQVShZqim41Bbw9Cho0y/7WzYptXqkEek= +sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs= +sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4= From 5a8b53b49db0519a3939d5b2db81b352a3174b36 Mon Sep 17 00:00:00 2001 From: ostiwe Date: Tue, 4 Nov 2025 19:15:28 +0300 Subject: [PATCH 4/9] feat: Add documentation generation and serve functionality - Implement documentation generation - Replace chi router with gin for documentation server - Fix issues with docs command execution --- go.mod | 4 + go.sum | 8 ++ html/redoc.html | 24 +++++ main.go | 142 ++++++++++++++++++++++----- modules/jwt/jwt.go | 2 +- pkg/args/args.go | 22 +++-- router/controller/controller.go | 5 +- router/controller/ping/controller.go | 41 +++----- router/server.go | 56 ++++------- settings/settings.go | 2 + 10 files changed, 206 insertions(+), 100 deletions(-) create mode 100644 html/redoc.html diff --git a/go.mod b/go.mod index 04a3fbd..1e178de 100644 --- a/go.mod +++ b/go.mod @@ -58,6 +58,9 @@ require ( github.com/redis/rueidis v1.0.66 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect github.com/sethvargo/go-retry v0.3.0 // indirect + github.com/swaggest/jsonschema-go v0.3.74 // indirect + github.com/swaggest/openapi-go v0.2.60 // indirect + github.com/swaggest/refl v1.3.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.3.0 // indirect github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect @@ -72,6 +75,7 @@ require ( golang.org/x/text v0.30.0 // indirect golang.org/x/tools v0.38.0 // indirect google.golang.org/protobuf v1.36.10 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect sigs.k8s.io/yaml v1.6.0 // indirect ) diff --git a/go.sum b/go.sum index 7dc0990..36687f5 100644 --- a/go.sum +++ b/go.sum @@ -213,6 +213,12 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/swaggest/jsonschema-go v0.3.74 h1:hkAZBK3RxNWU013kPqj0Q/GHGzYCCm9WcUTnfg2yPp0= +github.com/swaggest/jsonschema-go v0.3.74/go.mod h1:qp+Ym2DIXHlHzch3HKz50gPf2wJhKOrAB/VYqLS2oJU= +github.com/swaggest/openapi-go v0.2.60 h1:kglHH/WIfqAglfuWL4tu0LPakqNYySzklUWx06SjSKo= +github.com/swaggest/openapi-go v0.2.60/go.mod h1:jmFOuYdsWGtHU0BOuILlHZQJxLqHiAE6en+baE+QQUk= +github.com/swaggest/refl v1.3.1 h1:XGplEkYftR7p9cz1lsiwXMM2yzmOymTE9vneVVpaOh4= +github.com/swaggest/refl v1.3.1/go.mod h1:4uUVFVfPJ0NSX9FPwMPspeHos9wPFlCMGoPRllUbpvA= github.com/testcontainers/testcontainers-go v0.39.0 h1:uCUJ5tA+fcxbFAB0uP3pIK3EJ2IjjDUHFSZ1H1UxAts= github.com/testcontainers/testcontainers-go v0.39.0/go.mod h1:qmHpkG7H5uPf/EvOORKvS6EuDkBUPE3zpVGaH9NL7f8= github.com/testcontainers/testcontainers-go/modules/redis v0.39.0 h1:p54qELdCx4Gftkxzf44k9RJRRhaO/S5ehP9zo8SUTLM= @@ -280,6 +286,8 @@ google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 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= diff --git a/html/redoc.html b/html/redoc.html new file mode 100644 index 0000000..d455089 --- /dev/null +++ b/html/redoc.html @@ -0,0 +1,24 @@ + + + + Documentation of OstiweStatus API + + + + + + +
+ + + + \ No newline at end of file diff --git a/main.go b/main.go index 7376355..86da5c5 100644 --- a/main.go +++ b/main.go @@ -1,20 +1,34 @@ package main import ( + "embed" + "fmt" + "net/http" + "os" + "git.ostiwe.com/ostiwe-com/status/migration" appLog "git.ostiwe.com/ostiwe-com/status/modules/log" "git.ostiwe.com/ostiwe-com/status/pkg/args" + "git.ostiwe.com/ostiwe-com/status/router" "git.ostiwe.com/ostiwe-com/status/server" - _ "git.ostiwe.com/ostiwe-com/status/settings" + "git.ostiwe.com/ostiwe-com/status/settings" "github.com/alexflint/go-arg" + "github.com/gin-gonic/gin" ) +//go:embed html +var htmlFolder embed.FS + var appArgs args.AppArgs func main() { arg.MustParse(&appArgs) + defer appLog.Global.Get(appLog.SYSTEM).Debug("Exit from application") + if appArgs.Migration != nil && appArgs.Migration.Create != nil { + settings.Init() + if err := migration.CreateMigration(appArgs.Migration.Create.Name); err != nil { panic(err) } @@ -23,35 +37,111 @@ func main() { } if appArgs.Server != nil { - migration.RunMigration() + settings.Init() + migration.RunMigration() server.Run(appArgs.Server) + return } - // TODO: Rewrite to use gin router, instead of chi router - // if appArgs.ServerDocumentation != nil { - // appLog.Global.Get(appLog.SYSTEM).Info("Collect documentation") - // - // docs := router.Documentate() - // if !appArgs.ServerDocumentation.Plain { - // chiRouter := chi.NewRouter() - // - // err := docs.SetupRoutes(chiRouter, docs) - // if err != nil { - // appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Setup docs routes error: %v", err)) - // return - // } - // - // appLog.Global.Get(appLog.SYSTEM).Info(fmt.Sprintf("Start documentation server on port: %s", appArgs.ServerDocumentation.Port)) - // err = http.ListenAndServe(fmt.Sprintf(":%s", appArgs.ServerDocumentation.Port), chiRouter) - // if err != nil { - // appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error: %v", err)) - // } - // - // return - // } - // } + // TODO: Decompose document generation logic into separate methods + // Current code block handles both generation and serving logic - should be separated + if appArgs.Docs == nil { + return + } - appLog.Global.Get(appLog.SYSTEM).Info("Exit from application") + if appArgs.Docs.Generate != nil { + documentate, err := router.Documentate() + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + + return + } + + var file []byte + + switch appArgs.Docs.Generate.Format { + case "json": + file, err = documentate.MarshalJSON() + case "yaml": + file, err = documentate.MarshalYAML() + } + + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + + return + } + + if appArgs.Docs.Generate.Out == "stdout" { + _, err = os.Stdout.Write(file) + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + + return + } + + return + } + + err = os.WriteFile(appArgs.Docs.Generate.Out, file, os.ModeAppend) + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + + return + } + + return + } + + if appArgs.Docs.Serve != nil { + documentate, err := router.Documentate() + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + + return + } + docsJson, err := documentate.MarshalJSON() + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + + return + } + + html, err := htmlFolder.ReadFile("html/redoc.html") + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + + return + } + + g := gin.New() + g.Handle("GET", "/static-doc", func(c *gin.Context) { + c.Writer.Header().Add("Content-type", "application/json") + _, err = c.Writer.Write(docsJson) + if err != nil { + c.Writer.WriteHeader(http.StatusInternalServerError) + + return + } + }) + g.Handle("GET", "/docs/index.html", func(c *gin.Context) { + c.Writer.Header().Add("Content-Type", "text/html") + _, err = c.Writer.Write(html) + if err != nil { + c.Writer.WriteHeader(http.StatusInternalServerError) + + return + } + }) + + if err = g.Run(fmt.Sprintf(":%s", appArgs.Docs.Serve.Port)); err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + + return + } + + return + } } diff --git a/modules/jwt/jwt.go b/modules/jwt/jwt.go index 39df32c..d8511e3 100644 --- a/modules/jwt/jwt.go +++ b/modules/jwt/jwt.go @@ -21,7 +21,7 @@ var ( AuthMiddleware *ginJwt.GinJWTMiddleware ) -func init() { +func Init() { jwtPublicKeyPath := os.Getenv("JWT_SIGN_PUBLIC_KEY_PATH") if !strings.HasPrefix(jwtPublicKeyPath, "/") { jwtPublicKeyPath = settings.WorkingDir + "/" + jwtPublicKeyPath diff --git a/pkg/args/args.go b/pkg/args/args.go index 051093a..6ea16fa 100644 --- a/pkg/args/args.go +++ b/pkg/args/args.go @@ -3,7 +3,7 @@ package args import "git.ostiwe.com/ostiwe-com/status/version" type ServerCmd struct { - Port string `arg:"-p,--port" help:"Port to listen on" default:"8080"` + Port string `arg:"-p,--port,env:APP_PORT" help:"Port to listen on" default:"8080"` } type MigrationCreate struct { @@ -15,15 +15,23 @@ type Migration struct { } type ServerDocumentationCmd struct { - Port string `arg:"-p,--port" help:"Port to listen on" default:"8081"` - Plain bool `arg:"--plain" help:"Enable plain text output" default:"true"` - PlainFormat string `arg:"--plain-format" help:"Set format for output (json, yaml)" default:"yaml"` + Port string `arg:"-p,--port,env:APP_PORT_DOCS" help:"Port to listen on" default:"8081"` +} + +type GenerateDocumentationCmd struct { + Format string `arg:"--format,-f" help:"Set output format (json, yaml)" default:"yaml"` + Out string `arg:"--out,-o" help:"Output file name (or stdout)" default:"stdout"` +} + +type DocsCmd struct { + Serve *ServerDocumentationCmd `arg:"subcommand:serve" help:"Generate and serve the documentation server"` + Generate *GenerateDocumentationCmd `arg:"subcommand:generate" help:"Generate documentation to file"` } type AppArgs struct { - Server *ServerCmd `arg:"subcommand:server" help:"Start the api server"` - ServerDocumentation *ServerDocumentationCmd `arg:"subcommand:server-docs" help:"Generate documentation for api server and start documentation server"` - Migration *Migration `arg:"subcommand:migration" help:"Migration utils"` + Server *ServerCmd `arg:"subcommand:server" help:"Start the api server"` + Docs *DocsCmd `arg:"subcommand:docs" help:"Generate documentation to file or run documentation server"` + Migration *Migration `arg:"subcommand:migration" help:"Migration utils"` } func (AppArgs) Version() string { diff --git a/router/controller/controller.go b/router/controller/controller.go index 6e26ecd..9edb0cd 100644 --- a/router/controller/controller.go +++ b/router/controller/controller.go @@ -2,7 +2,8 @@ package controller import ( "github.com/gin-gonic/gin" - "github.com/go-andiamo/chioas" + "github.com/swaggest/openapi-go" + "github.com/swaggest/openapi-go/openapi3" ) // SecuredController - means, controller has middlewares @@ -12,7 +13,7 @@ type SecuredController interface { } type DocumentateController interface { - Documentate() (*chioas.Paths, *chioas.Components) + Documentate(r *openapi3.Reflector) openapi.OperationContext } type Controller interface { diff --git a/router/controller/ping/controller.go b/router/controller/ping/controller.go index ff7a0a8..084c712 100644 --- a/router/controller/ping/controller.go +++ b/router/controller/ping/controller.go @@ -6,7 +6,8 @@ import ( "git.ostiwe.com/ostiwe-com/status/modules/log" "git.ostiwe.com/ostiwe-com/status/router/controller" "github.com/gin-gonic/gin" - "github.com/go-andiamo/chioas" + "github.com/swaggest/openapi-go" + "github.com/swaggest/openapi-go/openapi3" ) type Controller struct { @@ -34,29 +35,19 @@ func (c *Controller) Handler() gin.HandlerFunc { } } -func (c *Controller) Documentate() (*chioas.Paths, *chioas.Components) { - return &chioas.Paths{ - "/ping": chioas.Path{ - Methods: map[string]chioas.Method{ - http.MethodGet: { - Handler: c.Handler(), - Responses: chioas.Responses{ - http.StatusOK: { - ContentType: "plain/text", - Schema: chioas.Schema{Type: "string"}, - Examples: chioas.Examples{ - { +func (c *Controller) Documentate(r *openapi3.Reflector) openapi.OperationContext { + op, err := r.NewOperationContext(c.Method(), c.Path()) + if err != nil { + return nil + } - Name: "200 OK", - Value: "pong", - }, - }, - }, - }, - }, - }, - Tag: "service", - Comment: "Route for check service is alive", - }, - }, nil + op.SetDescription("Route for check service is alive") + op.SetSummary("Server ping") + + op.AddRespStructure("pong", func(cu *openapi.ContentUnit) { + cu.ContentType = "plain/text" + cu.HTTPStatus = http.StatusOK + }) + + return op } diff --git a/router/server.go b/router/server.go index 7884efe..8a657a2 100644 --- a/router/server.go +++ b/router/server.go @@ -2,9 +2,9 @@ package router import ( "fmt" - "maps" "time" + "git.ostiwe.com/ostiwe-com/status/modules/jwt" "git.ostiwe.com/ostiwe-com/status/modules/log" "git.ostiwe.com/ostiwe-com/status/router/controller" "git.ostiwe.com/ostiwe-com/status/router/controller/auth" @@ -12,7 +12,7 @@ import ( "git.ostiwe.com/ostiwe-com/status/router/controller/service" "git.ostiwe.com/ostiwe-com/status/version" "github.com/gin-gonic/gin" - "github.com/go-andiamo/chioas" + "github.com/swaggest/openapi-go/openapi3" ) func getControllers() []controller.Controller { @@ -27,6 +27,8 @@ func InitRoutes() *gin.Engine { log.Global.Get(log.SERVER).Info("Setting up routers") startTime := time.Now() + jwt.Init() + r := gin.New() r.Use( gin.Recovery(), @@ -61,27 +63,16 @@ func InitRoutes() *gin.Engine { return r } -func Documentate() chioas.Definition { +func Documentate() (*openapi3.Spec, error) { ctrlList := getControllers() - apiDoc := chioas.Definition{ - AutoHeadMethods: true, - DocOptions: chioas.DocOptions{ - ServeDocs: true, - HideHeadMethods: true, - }, - Info: chioas.Info{ - Version: version.AppVersion(), - Title: "Status page API Documentation", - }, - Paths: make(chioas.Paths), - Components: &chioas.Components{ - Schemas: make(chioas.Schemas, 0), - Requests: make(chioas.CommonRequests), - Responses: make(chioas.CommonResponses), - Examples: make(chioas.Examples, 0), - Parameters: make(chioas.CommonParameters), - SecuritySchemes: make(chioas.SecuritySchemes, 0), - Extensions: make(chioas.Extensions), + + reflector := &openapi3.Reflector{ + Spec: &openapi3.Spec{ + Openapi: "3.0.3", + Info: openapi3.Info{ + Title: "OstiweStatus API", + Version: version.AppVersion(), + }, }, } @@ -91,25 +82,12 @@ func Documentate() chioas.Definition { continue } - documentatePaths, components := documentated.Documentate() - - if documentatePaths != nil { - for path, pathDoc := range *documentatePaths { - apiDoc.Paths[path] = pathDoc - } + err := reflector.AddOperation(documentated.Documentate(reflector)) + if err != nil { + return nil, err } - if components != nil { - apiDoc.Components.Schemas = append(apiDoc.Components.Schemas, components.Schemas...) - apiDoc.Components.Examples = append(apiDoc.Components.Examples, components.Examples...) - apiDoc.Components.SecuritySchemes = append(apiDoc.Components.SecuritySchemes, components.SecuritySchemes...) - - maps.Copy(apiDoc.Components.Requests, components.Requests) - maps.Copy(apiDoc.Components.Responses, components.Responses) - maps.Copy(apiDoc.Components.Parameters, components.Parameters) - maps.Copy(apiDoc.Components.Extensions, components.Extensions) - } } - return apiDoc + return reflector.Spec, nil } diff --git a/settings/settings.go b/settings/settings.go index ad15572..5817528 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -17,7 +17,9 @@ var ( func init() { appLog.SetGlobalManager(appLog.NewManager()) appLog.Global.Put(appLog.SYSTEM, logrus.New()) +} +func Init() { var err error WorkingDir, err = os.Getwd() From 8ca762cb1ffe094b5e5cd805751d40af9ba44f30 Mon Sep 17 00:00:00 2001 From: ostiwe Date: Tue, 4 Nov 2025 19:15:49 +0300 Subject: [PATCH 5/9] refactor: Remove rabbitmq from docker-compose --- docker-compose.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index bb3771a..88258d8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,14 +12,6 @@ services: ports: - "5444:5432" - rabbitmq: - image: rabbitmq:4.1.2-management - environment: - RABBITMQ_DEFAULT_USER: user - RABBITMQ_DEFAULT_PASS: user - ports: - - "5672:5672" - - "15672:15672" volumes: database_postgres: \ No newline at end of file From 180a5c2a9069cfea1923beca1e3a82fae0e4df8c Mon Sep 17 00:00:00 2001 From: ostiwe Date: Tue, 4 Nov 2025 19:52:26 +0300 Subject: [PATCH 6/9] refactor: Fix linter errors --- main.go | 202 ++++++++++++------------ modules/scheduler/scheduler.go | 7 +- router/controller/auth/plain.go | 12 +- router/controller/service/common.go | 30 ++++ router/controller/service/get.go | 20 +-- router/controller/service/public_get.go | 20 +-- router/server.go | 5 +- service/check.go | 12 +- 8 files changed, 161 insertions(+), 147 deletions(-) create mode 100644 router/controller/service/common.go diff --git a/main.go b/main.go index 86da5c5..cfe77a5 100644 --- a/main.go +++ b/main.go @@ -23,125 +23,125 @@ var appArgs args.AppArgs func main() { arg.MustParse(&appArgs) - defer appLog.Global.Get(appLog.SYSTEM).Debug("Exit from application") if appArgs.Migration != nil && appArgs.Migration.Create != nil { - settings.Init() - - if err := migration.CreateMigration(appArgs.Migration.Create.Name); err != nil { - panic(err) - } - + runMigrationCreateCommand() return } if appArgs.Server != nil { - settings.Init() - - migration.RunMigration() - server.Run(appArgs.Server) - + runServerCommand() return } - // TODO: Decompose document generation logic into separate methods - // Current code block handles both generation and serving logic - should be separated - if appArgs.Docs == nil { + if appArgs.Docs != nil { + runDocumentationCommand() return } +} +func runMigrationCreateCommand() { + settings.Init() + if err := migration.CreateMigration(appArgs.Migration.Create.Name); err != nil { + panic(err) + } +} + +func runServerCommand() { + settings.Init() + migration.RunMigration() + server.Run(appArgs.Server) +} + +func runDocumentationCommand() { if appArgs.Docs.Generate != nil { - documentate, err := router.Documentate() - if err != nil { - appLog.Global.Get(appLog.SYSTEM).Error(err) - - return - } - - var file []byte - - switch appArgs.Docs.Generate.Format { - case "json": - file, err = documentate.MarshalJSON() - case "yaml": - file, err = documentate.MarshalYAML() - } - - if err != nil { - appLog.Global.Get(appLog.SYSTEM).Error(err) - - return - } - - if appArgs.Docs.Generate.Out == "stdout" { - _, err = os.Stdout.Write(file) - if err != nil { - appLog.Global.Get(appLog.SYSTEM).Error(err) - - return - } - - return - } - - err = os.WriteFile(appArgs.Docs.Generate.Out, file, os.ModeAppend) - if err != nil { - appLog.Global.Get(appLog.SYSTEM).Error(err) - - return - } - + runDocsGenerationCommand() return } if appArgs.Docs.Serve != nil { - documentate, err := router.Documentate() - if err != nil { - appLog.Global.Get(appLog.SYSTEM).Error(err) - - return - } - docsJson, err := documentate.MarshalJSON() - if err != nil { - appLog.Global.Get(appLog.SYSTEM).Error(err) - - return - } - - html, err := htmlFolder.ReadFile("html/redoc.html") - if err != nil { - appLog.Global.Get(appLog.SYSTEM).Error(err) - - return - } - - g := gin.New() - g.Handle("GET", "/static-doc", func(c *gin.Context) { - c.Writer.Header().Add("Content-type", "application/json") - _, err = c.Writer.Write(docsJson) - if err != nil { - c.Writer.WriteHeader(http.StatusInternalServerError) - - return - } - }) - g.Handle("GET", "/docs/index.html", func(c *gin.Context) { - c.Writer.Header().Add("Content-Type", "text/html") - _, err = c.Writer.Write(html) - if err != nil { - c.Writer.WriteHeader(http.StatusInternalServerError) - - return - } - }) - - if err = g.Run(fmt.Sprintf(":%s", appArgs.Docs.Serve.Port)); err != nil { - appLog.Global.Get(appLog.SYSTEM).Error(err) - - return - } - + runDocsServingCommand() + return + } +} + +func runDocsGenerationCommand() { + documentate, err := router.Documentate() + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + return + } + + var file []byte + switch appArgs.Docs.Generate.Format { + case "json": + file, err = documentate.MarshalJSON() + case "yaml": + file, err = documentate.MarshalYAML() + } + + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + return + } + + if appArgs.Docs.Generate.Out == "stdout" { + _, err = os.Stdout.Write(file) + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + return + } + return + } + + err = os.WriteFile(appArgs.Docs.Generate.Out, file, os.ModeAppend) + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + return + } +} + +func runDocsServingCommand() { + documentate, err := router.Documentate() + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + return + } + + docsJson, err := documentate.MarshalJSON() + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + return + } + + html, err := htmlFolder.ReadFile("html/redoc.html") + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) + return + } + + g := gin.New() + g.Handle("GET", "/static-doc", func(c *gin.Context) { + c.Writer.Header().Add("Content-type", "application/json") + _, err = c.Writer.Write(docsJson) + if err != nil { + c.Writer.WriteHeader(http.StatusInternalServerError) + return + } + }) + + g.Handle("GET", "/docs/index.html", func(c *gin.Context) { + c.Writer.Header().Add("Content-Type", "text/html") + _, err = c.Writer.Write(html) + if err != nil { + c.Writer.WriteHeader(http.StatusInternalServerError) + return + } + }) + + if err = g.Run(fmt.Sprintf(":%s", appArgs.Docs.Serve.Port)); err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(err) return } } diff --git a/modules/scheduler/scheduler.go b/modules/scheduler/scheduler.go index f362e25..99a3d73 100644 --- a/modules/scheduler/scheduler.go +++ b/modules/scheduler/scheduler.go @@ -44,7 +44,12 @@ func NewAppScheduler() (AppScheduler, error) { }, nil } -func (s *appScheduler) NewServiceJob(serviceID uint64, jd gocron.JobDefinition, t gocron.Task, opt ...gocron.JobOption) (gocron.Job, error) { +func (s *appScheduler) NewServiceJob( + serviceID uint64, + jd gocron.JobDefinition, + t gocron.Task, + opt ...gocron.JobOption, +) (gocron.Job, error) { job, err := s.scheduler.NewJob(jd, t, opt...) if err != nil { return nil, err diff --git a/router/controller/auth/plain.go b/router/controller/auth/plain.go index f3acde0..4b0c1ef 100644 --- a/router/controller/auth/plain.go +++ b/router/controller/auth/plain.go @@ -19,7 +19,11 @@ func (c *PlainAuthController) Handler() gin.HandlerFunc { var payload dto.LoginRequest if err := ginCtx.ShouldBindJSON(&payload); err != nil { - sendErr := httpApp.NewResponseErrBuilder().WithStatusCode(http.StatusBadRequest).WithMessage(err.Error()).Send(ginCtx) + sendErr := httpApp. + NewResponseErrBuilder(). + WithStatusCode(http.StatusBadRequest). + WithMessage(err.Error()). + Send(ginCtx) if sendErr != nil { ginCtx.Writer.WriteHeader(http.StatusInternalServerError) return @@ -30,7 +34,11 @@ func (c *PlainAuthController) Handler() gin.HandlerFunc { jwtString, err := c.authModule.Proceed(ginCtx.Request.Context(), payload.Login, payload.Password) if err != nil { - sendErr := httpApp.NewResponseErrBuilder().WithStatusCode(http.StatusBadRequest).WithMessage(err.Error()).Send(ginCtx) + sendErr := httpApp. + NewResponseErrBuilder(). + WithStatusCode(http.StatusBadRequest). + WithMessage(err.Error()). + Send(ginCtx) if sendErr != nil { ginCtx.Writer.WriteHeader(http.StatusInternalServerError) return diff --git a/router/controller/service/common.go b/router/controller/service/common.go new file mode 100644 index 0000000..6975af1 --- /dev/null +++ b/router/controller/service/common.go @@ -0,0 +1,30 @@ +package service + +import ( + "net/http" + + "git.ostiwe.com/ostiwe-com/status/modules/log" + http2 "git.ostiwe.com/ostiwe-com/status/pkg/http" + "git.ostiwe.com/ostiwe-com/status/repository" + "git.ostiwe.com/ostiwe-com/status/transform" + "github.com/gin-gonic/gin" +) + +func processGetServicesHandler(c *gin.Context, publicOnly bool, serviceRepository repository.Service) { + items, err := serviceRepository.All(c.Request.Context(), -1, 0, publicOnly) + if err != nil { + log.Global.Get(log.SERVER).Error(err) + + writeErr := http2.NewResponseErrBuilder(). + WithMessage("Fetch service error"). + WithStatusCode(http.StatusInternalServerError). + Send(c) + if writeErr != nil { + log.Global.Get(log.SERVER).Error(writeErr) + } + + return + } + + c.JSON(http.StatusOK, transform.PublicServices(items...)) +} diff --git a/router/controller/service/get.go b/router/controller/service/get.go index e0d7080..57a5180 100644 --- a/router/controller/service/get.go +++ b/router/controller/service/get.go @@ -4,12 +4,9 @@ import ( "net/http" "git.ostiwe.com/ostiwe-com/status/modules/jwt" - "git.ostiwe.com/ostiwe-com/status/modules/log" - http2 "git.ostiwe.com/ostiwe-com/status/pkg/http" "git.ostiwe.com/ostiwe-com/status/repository" "git.ostiwe.com/ostiwe-com/status/router/controller" "git.ostiwe.com/ostiwe-com/status/router/midlleware" - "git.ostiwe.com/ostiwe-com/status/transform" "github.com/gin-gonic/gin" ) @@ -25,22 +22,7 @@ func (g *GetServices) New() controller.Controller { func (g *GetServices) Handler() gin.HandlerFunc { return func(c *gin.Context) { - items, err := g.serviceRepository.All(c.Request.Context(), -1, 0, true) - if err != nil { - log.Global.Get(log.SERVER).Error(err) - - writeErr := http2.NewResponseErrBuilder(). - WithMessage("Fetch service error"). - WithStatusCode(http.StatusInternalServerError). - Send(c) - if writeErr != nil { - log.Global.Get(log.SERVER).Error(writeErr) - } - - return - } - - c.JSON(http.StatusOK, transform.PublicServices(items...)) + processGetServicesHandler(c, false, g.serviceRepository) } } diff --git a/router/controller/service/public_get.go b/router/controller/service/public_get.go index cdc54e5..3f83ea8 100644 --- a/router/controller/service/public_get.go +++ b/router/controller/service/public_get.go @@ -3,11 +3,8 @@ package service import ( "net/http" - "git.ostiwe.com/ostiwe-com/status/modules/log" - http2 "git.ostiwe.com/ostiwe-com/status/pkg/http" "git.ostiwe.com/ostiwe-com/status/repository" "git.ostiwe.com/ostiwe-com/status/router/controller" - "git.ostiwe.com/ostiwe-com/status/transform" "github.com/gin-gonic/gin" ) @@ -23,22 +20,7 @@ func (p *PublicGetServicesController) New() controller.Controller { func (p *PublicGetServicesController) Handler() gin.HandlerFunc { return func(c *gin.Context) { - items, err := p.serviceRepository.All(c.Request.Context(), -1, 0, true) - if err != nil { - log.Global.Get(log.SERVER).Error(err) - - writeErr := http2.NewResponseErrBuilder(). - WithMessage("Fetch service error"). - WithStatusCode(http.StatusInternalServerError). - Send(c) - if writeErr != nil { - log.Global.Get(log.SERVER).Error(writeErr) - } - - return - } - - c.JSON(http.StatusOK, transform.PublicServices(items...)) + processGetServicesHandler(c, true, p.serviceRepository) } } diff --git a/router/server.go b/router/server.go index 8a657a2..aee3f4f 100644 --- a/router/server.go +++ b/router/server.go @@ -58,7 +58,10 @@ func InitRoutes() *gin.Engine { } log.Global.Get(log.SERVER).Info(fmt.Sprintf("Initialized %d routers", len(ctrlList))) - log.Global.Get(log.SERVER).Info(fmt.Sprintf("Setting up routers is done for %dms, start server", time.Since(startTime).Milliseconds())) + log.Global.Get(log.SERVER).Info(fmt.Sprintf( + "Setting up routers is done for %dms, start server", + time.Since(startTime).Milliseconds(), + )) return r } diff --git a/service/check.go b/service/check.go index f93eae7..28583e3 100644 --- a/service/check.go +++ b/service/check.go @@ -17,8 +17,7 @@ import ( ) var ( - httpObserveFailed = errors.New("http observe fail") - httpObserveMaxTries = errors.New("http observe max tries") + errHttpObserveFailed = errors.New("http observe fail") GlobalCheckService Check ) @@ -111,7 +110,12 @@ func (c *check) Observe(ctx context.Context, srv *model.Service) error { return nil } -func (c *check) RegisterStatus(ctx context.Context, serviceID uint64, status model.StatusCode, meta ResponseMeta) error { +func (c *check) RegisterStatus( + ctx context.Context, + serviceID uint64, + status model.StatusCode, + meta ResponseMeta, +) error { return c.statusRepository.Add(ctx, model.Status{ ServiceID: serviceID, Status: status, @@ -163,7 +167,7 @@ func (c *check) ObserveHttp(ctx context.Context, service *model.Service) (*Respo } if response.StatusCode != http.StatusOK { - return meta, httpObserveFailed + return meta, errHttpObserveFailed } return meta, nil From fc8b723114241270fcbabf5d4496aca75a9242a0 Mon Sep 17 00:00:00 2001 From: ostiwe Date: Tue, 4 Nov 2025 19:59:17 +0300 Subject: [PATCH 7/9] refactor: Fix linter errors by auto-apply - Apply automated linter fixes - Manually reformat fields in model/service.go - Resolve code complexity issues --- main.go | 16 +++++++++++ model/service.go | 43 ++++++++++++++-------------- model/status.go | 4 +-- pkg/args/args.go | 14 ++++----- pkg/http/errors.go | 4 +++ router/controller/auth/plain.go | 2 ++ router/controller/ping/controller.go | 1 + router/midlleware/user.go | 1 + router/server.go | 1 - server/server.go | 4 +++ transform/service.go | 2 +- 11 files changed, 60 insertions(+), 32 deletions(-) diff --git a/main.go b/main.go index cfe77a5..94932b6 100644 --- a/main.go +++ b/main.go @@ -27,16 +27,19 @@ func main() { if appArgs.Migration != nil && appArgs.Migration.Create != nil { runMigrationCreateCommand() + return } if appArgs.Server != nil { runServerCommand() + return } if appArgs.Docs != nil { runDocumentationCommand() + return } } @@ -57,11 +60,13 @@ func runServerCommand() { func runDocumentationCommand() { if appArgs.Docs.Generate != nil { runDocsGenerationCommand() + return } if appArgs.Docs.Serve != nil { runDocsServingCommand() + return } } @@ -70,6 +75,7 @@ func runDocsGenerationCommand() { documentate, err := router.Documentate() if err != nil { appLog.Global.Get(appLog.SYSTEM).Error(err) + return } @@ -83,6 +89,7 @@ func runDocsGenerationCommand() { if err != nil { appLog.Global.Get(appLog.SYSTEM).Error(err) + return } @@ -90,14 +97,17 @@ func runDocsGenerationCommand() { _, err = os.Stdout.Write(file) if err != nil { appLog.Global.Get(appLog.SYSTEM).Error(err) + return } + return } err = os.WriteFile(appArgs.Docs.Generate.Out, file, os.ModeAppend) if err != nil { appLog.Global.Get(appLog.SYSTEM).Error(err) + return } } @@ -106,18 +116,21 @@ func runDocsServingCommand() { documentate, err := router.Documentate() if err != nil { appLog.Global.Get(appLog.SYSTEM).Error(err) + return } docsJson, err := documentate.MarshalJSON() if err != nil { appLog.Global.Get(appLog.SYSTEM).Error(err) + return } html, err := htmlFolder.ReadFile("html/redoc.html") if err != nil { appLog.Global.Get(appLog.SYSTEM).Error(err) + return } @@ -127,6 +140,7 @@ func runDocsServingCommand() { _, err = c.Writer.Write(docsJson) if err != nil { c.Writer.WriteHeader(http.StatusInternalServerError) + return } }) @@ -136,12 +150,14 @@ func runDocsServingCommand() { _, err = c.Writer.Write(html) if err != nil { c.Writer.WriteHeader(http.StatusInternalServerError) + return } }) if err = g.Run(fmt.Sprintf(":%s", appArgs.Docs.Serve.Port)); err != nil { appLog.Global.Get(appLog.SYSTEM).Error(err) + return } } diff --git a/model/service.go b/model/service.go index c8b1ada..0433c51 100644 --- a/model/service.go +++ b/model/service.go @@ -7,33 +7,34 @@ type HTTPConfig struct { Headers map[string]string `json:"headers"` } +// ServiceTypeCheckConfig +// MaxFails - max "ping" fails, after with the service marked as unavailable +// Interval - interval between "ping" in seconds +// Timeout - interval after which the task will be canceled type ServiceTypeCheckConfig struct { Version string `json:"version"` HTTPConfig *HTTPConfig `json:"httpConfig"` - // MaxFails - max "ping" fails, after with the service marked as unavailable - MaxFails uint8 `json:"maxFails"` - // Interval - interval between "ping" in seconds - Interval uint64 `json:"interval"` - // Timeout - interval after which the task will be canceled - Timeout uint64 `json:"timeout"` + MaxFails uint8 `json:"maxFails"` + Interval uint64 `json:"interval"` + Timeout uint64 `json:"timeout"` } +// Service +// ID Unique ID for entity +// Name Human-readable service name +// Description Human-readable service description +// Host to check, for example 192.168.1.44 or https://google.com +// Type for check, for now is TCP or HTTP or something else type Service struct { - // Unique ID for entity - ID uint64 `gorm:"primary_key;auto_increment" json:"id"` - // Human-readable service name - Name string `gorm:"size:255;not null" json:"name"` - // Human-readable service description - Description string `gorm:"size:255" json:"description"` - PublicDescription string `gorm:"size:255" json:"publicDescription"` - Public *bool `gorm:"default:false" json:"public"` - // Host to check, for example 192.168.1.44 or https://google.com - Host string `gorm:"size:255;not null" json:"host"` - // Type for check, for now is TCP or HTTP or something else - Type string `gorm:"size:255;not null" json:"type"` - Config *ServiceTypeCheckConfig `gorm:"serializer:json;column:type_config" json:"typeConfig"` - - Statuses []Status `gorm:"foreignkey:ServiceID" json:"statuses"` + ID uint64 `gorm:"primary_key;auto_increment" json:"id"` + Name string `gorm:"size:255;not null" json:"name"` + Description string `gorm:"size:255" json:"description"` + PublicDescription string `gorm:"size:255" json:"publicDescription"` + Public *bool `gorm:"default:false" json:"public"` + Host string `gorm:"size:255;not null" json:"host"` + Type string `gorm:"size:255;not null" json:"type"` + Config *ServiceTypeCheckConfig `gorm:"serializer:json;column:type_config" json:"typeConfig"` + Statuses []Status `gorm:"foreignkey:ServiceID" json:"statuses"` } func (Service) TableName() string { diff --git a/model/status.go b/model/status.go index 8d3b3c6..3136d0a 100644 --- a/model/status.go +++ b/model/status.go @@ -18,8 +18,8 @@ const ( type Status struct { ID uint64 `gorm:"primary_key;auto_increment" json:"-"` ServiceID uint64 `json:"-"` - Status StatusCode `gorm:"size:255;not null" json:"status"` - Description *string `gorm:"size:255" json:"description"` + Status StatusCode `gorm:"size:255;not null" json:"status"` + Description *string `gorm:"size:255" json:"description"` CreatedAt time.Time `json:"createdAt"` ResponseTime uint64 `json:"responseTime"` } diff --git a/pkg/args/args.go b/pkg/args/args.go index 6ea16fa..ad2051d 100644 --- a/pkg/args/args.go +++ b/pkg/args/args.go @@ -3,7 +3,7 @@ package args import "git.ostiwe.com/ostiwe-com/status/version" type ServerCmd struct { - Port string `arg:"-p,--port,env:APP_PORT" help:"Port to listen on" default:"8080"` + Port string `arg:"-p,--port,env:APP_PORT" default:"8080" help:"Port to listen on"` } type MigrationCreate struct { @@ -15,22 +15,22 @@ type Migration struct { } type ServerDocumentationCmd struct { - Port string `arg:"-p,--port,env:APP_PORT_DOCS" help:"Port to listen on" default:"8081"` + Port string `arg:"-p,--port,env:APP_PORT_DOCS" default:"8081" help:"Port to listen on"` } type GenerateDocumentationCmd struct { - Format string `arg:"--format,-f" help:"Set output format (json, yaml)" default:"yaml"` - Out string `arg:"--out,-o" help:"Output file name (or stdout)" default:"stdout"` + Format string `arg:"--format,-f" default:"yaml" help:"Set output format (json, yaml)"` + Out string `arg:"--out,-o" default:"stdout" help:"Output file name (or stdout)"` } type DocsCmd struct { - Serve *ServerDocumentationCmd `arg:"subcommand:serve" help:"Generate and serve the documentation server"` + Serve *ServerDocumentationCmd `arg:"subcommand:serve" help:"Generate and serve the documentation server"` Generate *GenerateDocumentationCmd `arg:"subcommand:generate" help:"Generate documentation to file"` } type AppArgs struct { - Server *ServerCmd `arg:"subcommand:server" help:"Start the api server"` - Docs *DocsCmd `arg:"subcommand:docs" help:"Generate documentation to file or run documentation server"` + Server *ServerCmd `arg:"subcommand:server" help:"Start the api server"` + Docs *DocsCmd `arg:"subcommand:docs" help:"Generate documentation to file or run documentation server"` Migration *Migration `arg:"subcommand:migration" help:"Migration utils"` } diff --git a/pkg/http/errors.go b/pkg/http/errors.go index e5ba4c0..94dd044 100644 --- a/pkg/http/errors.go +++ b/pkg/http/errors.go @@ -58,11 +58,13 @@ func (r readyResponseErr) Send(response http.ResponseWriter) error { func (r responseErrBuilder) WithTrace(s string) ResponseErrBuilder { r.trace = s + return r } func (r responseErrBuilder) WithStatusCode(i int) ResponseErrBuilder { r.status = i + return r } @@ -72,11 +74,13 @@ func NewResponseErrBuilder() ResponseErrBuilder { func (r responseErrBuilder) WithDetails(m map[string]any) ResponseErrBuilder { r.details = m + return r } func (r responseErrBuilder) WithMessage(s string) ResponseErrBuilder { r.message = s + return r } diff --git a/router/controller/auth/plain.go b/router/controller/auth/plain.go index 4b0c1ef..d8c29ed 100644 --- a/router/controller/auth/plain.go +++ b/router/controller/auth/plain.go @@ -26,6 +26,7 @@ func (c *PlainAuthController) Handler() gin.HandlerFunc { Send(ginCtx) if sendErr != nil { ginCtx.Writer.WriteHeader(http.StatusInternalServerError) + return } @@ -41,6 +42,7 @@ func (c *PlainAuthController) Handler() gin.HandlerFunc { Send(ginCtx) if sendErr != nil { ginCtx.Writer.WriteHeader(http.StatusInternalServerError) + return } diff --git a/router/controller/ping/controller.go b/router/controller/ping/controller.go index 084c712..b68f0c5 100644 --- a/router/controller/ping/controller.go +++ b/router/controller/ping/controller.go @@ -30,6 +30,7 @@ func (c *Controller) Handler() gin.HandlerFunc { _, err := ginCtx.Writer.Write([]byte("pong")) if err != nil { log.Global.Get(log.SERVER).Error(err) + return } } diff --git a/router/midlleware/user.go b/router/midlleware/user.go index ba3bea3..b41575e 100644 --- a/router/midlleware/user.go +++ b/router/midlleware/user.go @@ -23,6 +23,7 @@ func SetUserFromJWT() gin.HandlerFunc { subject, err := token.Claims.GetSubject() if err != nil { c.Writer.WriteHeader(http.StatusUnauthorized) + return } diff --git a/router/server.go b/router/server.go index aee3f4f..1d93bd4 100644 --- a/router/server.go +++ b/router/server.go @@ -89,7 +89,6 @@ func Documentate() (*openapi3.Spec, error) { if err != nil { return nil, err } - } return reflector.Spec, nil diff --git a/server/server.go b/server/server.go index 307b0a4..db9582c 100644 --- a/server/server.go +++ b/server/server.go @@ -18,6 +18,7 @@ func Run(serverArgs *args.ServerCmd) { connect, err := db.Connect() if err != nil { appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error, failed connect to database: %v", err)) + return } @@ -26,6 +27,7 @@ func Run(serverArgs *args.ServerCmd) { scheduler.GlobalAppScheduler, err = scheduler.NewAppScheduler() if err != nil { appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error, failed create scheduler: %v", err)) + return } @@ -34,11 +36,13 @@ func Run(serverArgs *args.ServerCmd) { if err = service.GlobalCheckService.RegisterTasks(context.Background()); err != nil { appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error, failed create observe jobs: %v", err)) + return } if err = scheduler.GlobalAppScheduler.StartJobs(); err != nil { appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error, failed start jobs: %v", err)) + return } diff --git a/transform/service.go b/transform/service.go index 41cf4fa..1ad7985 100644 --- a/transform/service.go +++ b/transform/service.go @@ -33,7 +33,6 @@ func PublicServices(items ...model.Service) []dto.PublicService { } wg.Wait() - } return result @@ -57,6 +56,7 @@ func PublicService(item model.Service) dto.PublicService { } slices.Reverse(statuses) + return dto.PublicService{ ID: int(item.ID), Name: item.Name, From 2a411136b70e0ded8ee0b716f5b774f74abe8c9b Mon Sep 17 00:00:00 2001 From: ostiwe Date: Tue, 4 Nov 2025 19:59:44 +0300 Subject: [PATCH 8/9] refactor: Remove unused variable --- modules/jwt/jwt.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/modules/jwt/jwt.go b/modules/jwt/jwt.go index d8511e3..e38f819 100644 --- a/modules/jwt/jwt.go +++ b/modules/jwt/jwt.go @@ -14,9 +14,8 @@ import ( ) var ( - signKey *rsa.PrivateKey - publicSignKey *rsa.PublicKey - signMethod jwt.SigningMethod = jwt.SigningMethodRS256 + signKey *rsa.PrivateKey + signMethod jwt.SigningMethod = jwt.SigningMethodRS256 AuthMiddleware *ginJwt.GinJWTMiddleware ) @@ -49,11 +48,6 @@ func Init() { panic(err) } - publicSignKey, err = jwt.ParseRSAPublicKeyFromPEM(publicFile) - if err != nil { - panic(err) - } - AuthMiddleware = &ginJwt.GinJWTMiddleware{ SigningAlgorithm: signMethod.Alg(), PrivKeyBytes: privateFile, From 465eb99baee098833722931335e7ea6ff1f914c4 Mon Sep 17 00:00:00 2001 From: ostiwe Date: Tue, 4 Nov 2025 20:04:13 +0300 Subject: [PATCH 9/9] refactor: Fix linter errors --- pkg/rabbit/connection.go | 26 +++++++++++--------------- router/midlleware/user.go | 8 +++++++- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pkg/rabbit/connection.go b/pkg/rabbit/connection.go index 2fba784..50620ee 100644 --- a/pkg/rabbit/connection.go +++ b/pkg/rabbit/connection.go @@ -75,25 +75,21 @@ func (c *Connection) listenCloseNotify() { )) for { - select { - case <-c.closeNotify: - c.logger.Info("Trying to reconnect to rabbit") + <-c.closeNotify + c.logger.Info("Trying to reconnect to rabbit") - dial, dialErr := amqp.Dial(c.connString) - if dialErr != nil { - c.logger.Error("Error during reconnect try - ", dialErr) + dial, dialErr := amqp.Dial(c.connString) + if dialErr != nil { + c.logger.Error("Error during reconnect try - ", dialErr) - continue - } - - c.conn = dial - c.closeNotify = dial.NotifyClose(make(chan *amqp.Error)) - - c.logger.Info("Rabbit connection stabilized") - - break + continue } + c.conn = dial + c.closeNotify = dial.NotifyClose(make(chan *amqp.Error)) + + c.logger.Info("Rabbit connection stabilized") + time.Sleep(c.reconnectInterval) } } diff --git a/router/midlleware/user.go b/router/midlleware/user.go index b41575e..2c922e1 100644 --- a/router/midlleware/user.go +++ b/router/midlleware/user.go @@ -9,6 +9,12 @@ import ( "github.com/gin-gonic/gin" ) +type ContextKey string + +const ( + UserContextKey ContextKey = "user" +) + func SetUserFromJWT() gin.HandlerFunc { return func(c *gin.Context) { ctx := c.Request.Context() @@ -34,7 +40,7 @@ func SetUserFromJWT() gin.HandlerFunc { return } - ctx = context.WithValue(ctx, "user", user) + ctx = context.WithValue(ctx, UserContextKey, user) c.Request = c.Request.WithContext(ctx)