From bca4e04acce0a7391b5285b8031ab385f63173c2 Mon Sep 17 00:00:00 2001 From: slaventius Date: Mon, 13 Feb 2023 09:27:33 +0300 Subject: [PATCH] * --- .vscode/launch.json | 5 +++-- {deploy => build}/Dockerfile | 0 go.mod | 7 ++++++- go.sum | 28 ++++++++++++++++++++++++---- internal/auth.go | 25 +++++++++++++++++++++++-- internal/config/config.go | 9 +++++++-- scripts/start.sh | 1 + 7 files changed, 64 insertions(+), 11 deletions(-) rename {deploy => build}/Dockerfile (100%) diff --git a/.vscode/launch.json b/.vscode/launch.json index c535165..bba4ea1 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,8 +12,9 @@ "program": "${workspaceRoot}/cmd/main.go", "env": { "DB_HOST": "127.0.0.1", - "DB_PORT":"9995", - "APP_PORT":"9994", + "DB_PORT": "9995", + "APP_PORT": "9994", + "SENTRY_DSN": "https://3f4b31dbbd9a4a6b8a71f9881d962f25@o4504654569799680.ingest.sentry.io/4504654572683264" }, "args": [] } diff --git a/deploy/Dockerfile b/build/Dockerfile similarity index 100% rename from deploy/Dockerfile rename to build/Dockerfile diff --git a/go.mod b/go.mod index 1216d88..4db8cd7 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,19 @@ module git.slaventius.ru/test3k/auth go 1.19 require ( - git.slaventius.ru/test3k/umate v0.0.0-20230209054131-c039ab837f14 + git.slaventius.ru/test3k/umate v0.0.0-20230213061556-8529690e1553 github.com/go-chi/chi/v5 v5.0.8 github.com/kelseyhightower/envconfig v1.4.0 google.golang.org/grpc v1.52.3 ) require ( + github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect + github.com/evalphobia/logrus_sentry v0.8.2 // indirect + github.com/getsentry/raven-go v0.2.0 // indirect github.com/golang/protobuf v1.5.2 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/sirupsen/logrus v1.9.0 // indirect golang.org/x/net v0.4.0 // indirect golang.org/x/sys v0.3.0 // indirect golang.org/x/text v0.5.0 // indirect diff --git a/go.sum b/go.sum index 3b91633..0670a50 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,14 @@ -git.slaventius.ru/test3k/umate v0.0.0-20230204104415-6dd680567696 h1:amkq2DrSdfXKquTYFBm+nBBXAfjqjg8UAYactSKeQWM= -git.slaventius.ru/test3k/umate v0.0.0-20230204104415-6dd680567696/go.mod h1:zC+pjeBAFo0eLwPt+vBrdyt1ObAPU+HMfDG12vXLjBA= -git.slaventius.ru/test3k/umate v0.0.0-20230209054131-c039ab837f14 h1:1GAmFzUQriRn/WfplqIYHKuHF/TDzYfy9D8unxmC8wQ= -git.slaventius.ru/test3k/umate v0.0.0-20230209054131-c039ab837f14/go.mod h1:zC+pjeBAFo0eLwPt+vBrdyt1ObAPU+HMfDG12vXLjBA= +git.slaventius.ru/test3k/umate v0.0.0-20230213061556-8529690e1553 h1:Ojj8kD7B3MwEtopOorx/EZzEHITuBy1BgJsVQV9r598= +git.slaventius.ru/test3k/umate v0.0.0-20230213061556-8529690e1553/go.mod h1:xE7ik2EnLB+CNDJA5+HbRIwAk+V7sgUjS0HPeXS5Ka0= +github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d h1:S2NE3iHSwP0XV47EEXL8mWmRdEfGscSJ+7EgePNgt0s= +github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= +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/evalphobia/logrus_sentry v0.8.2 h1:dotxHq+YLZsT1Bb45bB5UQbfCh3gM/nFFetyN46VoDQ= +github.com/evalphobia/logrus_sentry v0.8.2/go.mod h1:pKcp+vriitUqu9KiWj/VRFbRfFNUwz95/UkgG8a6MNc= +github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs= +github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0= github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= @@ -11,8 +18,18 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= +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/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU= golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= @@ -26,3 +43,6 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/auth.go b/internal/auth.go index a7f0847..cac8906 100644 --- a/internal/auth.go +++ b/internal/auth.go @@ -7,6 +7,7 @@ import ( "git.slaventius.ru/test3k/auth/internal/config" db "git.slaventius.ru/test3k/auth/internal/transport/grpc" + "git.slaventius.ru/test3k/umate/pkg/logger" mux "github.com/go-chi/chi/v5" "google.golang.org/grpc/status" @@ -17,6 +18,7 @@ type AuthServer struct { db *db.AuthDBClient Router *mux.Mux config *config.Config + logger *logger.Logger ctx context.Context } @@ -25,11 +27,15 @@ func NewServer(ctx context.Context, config *config.Config) *AuthServer { db: db.NewDBClient(ctx, config), Router: mux.NewMux(), config: config, + logger: logger.NewLogger("test3k:authService", config.Sentry.DSN), ctx: ctx, } // - s.Router.Get("/api/v1/ready", ready(s)) + s.Router.Get("/api/v1/live", live(s)) + s.Router.Get("/api/v1/ready", live(s)) + + // s.Router.Post("/api/v1/login", login(s)) s.Router.Post("/api/v1/registration", registration(s)) s.Router.Post("/api/v1/confirmation", confirmation(s)) @@ -41,7 +47,7 @@ func (s *AuthServer) GracefulStop() error { return s.db.Close() } -func ready(s *AuthServer) http.HandlerFunc { +func live(s *AuthServer) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("ok")) } @@ -54,6 +60,11 @@ func login(s *AuthServer) http.HandlerFunc { err := s.db.Login(uid, password) if err != nil { status := status.Convert(err) + + // + s.logger.Error(status.Message()) + + // w.Write([]byte(status.Message())) return @@ -71,6 +82,11 @@ func registration(s *AuthServer) http.HandlerFunc { _, err := s.db.Registration(uid, email, password) if err != nil { status := status.Convert(err) + + // + s.logger.Error(status.Message()) + + // w.Write([]byte(status.Message())) return @@ -86,6 +102,11 @@ func confirmation(s *AuthServer) http.HandlerFunc { err := s.db.Confirmation(code) if err != nil { status := status.Convert(err) + + // + s.logger.Error(status.Message()) + + // w.Write([]byte(status.Message())) return diff --git a/internal/config/config.go b/internal/config/config.go index 61e060b..24b69a0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -15,10 +15,15 @@ type AppConfig struct { Port int `envconfig:"APP_PORT"` } +type SentryConfig struct { + DSN string `envconfig:"SENTRY_DSN"` +} + // ... type Config struct { - Db DbConfig - App AppConfig + Db DbConfig + App AppConfig + Sentry SentryConfig } func NewConfig() *Config { diff --git a/scripts/start.sh b/scripts/start.sh index 8ab338a..f7e43a9 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -3,5 +3,6 @@ export DB_HOST=127.0.0.1 export DB_PORT=9995 export APP_PORT=9994 +export SENTRY_DSN="https://3f4b31dbbd9a4a6b8a71f9881d962f25@o4504654569799680.ingest.sentry.io/4504654572683264" ./authService \ No newline at end of file