diff --git a/cmd/gophermart/main.go b/cmd/gophermart/main.go index 38dd16d..fd71845 100644 --- a/cmd/gophermart/main.go +++ b/cmd/gophermart/main.go @@ -1,3 +1,16 @@ package main -func main() {} +import ( + "github.com/spqrcor/gofermart/internal/config" + "github.com/spqrcor/gofermart/internal/db" + "github.com/spqrcor/gofermart/internal/logger" + "github.com/spqrcor/gofermart/internal/server" +) + +func main() { + config.Init() + logger.Init() + db.Init() + + server.Start() +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3713cd4 --- /dev/null +++ b/go.mod @@ -0,0 +1,74 @@ +module github.com/spqrcor/gofermart + +go 1.22 + +require ( + filippo.io/edwards25519 v1.1.0 // indirect + github.com/ClickHouse/ch-go v0.62.0 // indirect + github.com/ClickHouse/clickhouse-go/v2 v2.28.1 // indirect + github.com/andybalholm/brotli v1.1.0 // indirect + github.com/antlr4-go/antlr/v4 v4.13.1 // indirect + github.com/coder/websocket v1.8.12 // indirect + github.com/dustin/go-humanize v1.0.1 // indirect + github.com/elastic/go-sysinfo v1.14.1 // indirect + github.com/elastic/go-windows v1.0.2 // indirect + github.com/go-chi/chi/v5 v5.1.0 // indirect + github.com/go-faster/city v1.0.1 // indirect + github.com/go-faster/errors v0.7.1 // indirect + github.com/go-sql-driver/mysql v1.8.1 // indirect + github.com/golang-jwt/jwt/v4 v4.5.0 // indirect + github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect + github.com/golang-sql/sqlexp v0.1.0 // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.7 // 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.6.0 // indirect + github.com/jackc/puddle/v2 v2.2.1 // indirect + github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect + github.com/jonboulle/clockwork v0.4.0 // indirect + github.com/klauspost/compress v1.17.9 // indirect + github.com/libsql/sqlite-antlr4-parser v0.0.0-20240721121621-c0bdc870f11c // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mfridman/interpolate v0.0.2 // indirect + github.com/microsoft/go-mssqldb v1.7.2 // indirect + github.com/ncruces/go-strftime v0.1.9 // indirect + github.com/paulmach/orb v0.11.1 // indirect + github.com/pierrec/lz4/v4 v4.1.21 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/pressly/goose/v3 v3.21.1 // indirect + github.com/prometheus/procfs v0.15.1 // indirect + github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect + github.com/segmentio/asm v1.2.0 // indirect + github.com/sethvargo/go-retry v0.3.0 // indirect + github.com/shopspring/decimal v1.4.0 // indirect + github.com/tursodatabase/libsql-client-go v0.0.0-20240812094001-348a4e45b535 // indirect + github.com/vertica/vertica-sql-go v1.3.3 // indirect + github.com/ydb-platform/ydb-go-genproto v0.0.0-20240821162910-6cb364b2ccc8 // indirect + github.com/ydb-platform/ydb-go-sdk/v3 v3.77.1 // indirect + github.com/ziutek/mymysql v1.5.4 // indirect + go.opentelemetry.io/otel v1.29.0 // indirect + go.opentelemetry.io/otel/trace v1.29.0 // indirect + go.uber.org/multierr v1.11.0 // indirect + go.uber.org/zap v1.27.0 // indirect + golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.24.0 // indirect + golang.org/x/text v0.17.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect + google.golang.org/grpc v1.66.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + howett.net/plist v1.0.1 // indirect + modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a // indirect + modernc.org/libc v1.60.0 // indirect + modernc.org/mathutil v1.6.0 // indirect + modernc.org/memory v1.8.0 // indirect + modernc.org/sqlite v1.32.0 // indirect + modernc.org/strutil v1.2.0 // indirect + modernc.org/token v1.1.0 // indirect + nhooyr.io/websocket v1.8.17 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..2e19945 --- /dev/null +++ b/go.sum @@ -0,0 +1,311 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= +filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/ClickHouse/ch-go v0.62.0 h1:eXH0hytXeCEEZHgMvOX9IiW7wqBb4w1MJMp9rArbkrc= +github.com/ClickHouse/ch-go v0.62.0/go.mod h1:uzso52/PD9+gZj7tL6XAo8/EYDrx7CIwNF4c6PnO6S0= +github.com/ClickHouse/clickhouse-go v1.5.4 h1:cKjXeYLNWVJIx2J1K6H2CqyRmfwVJVY1OV1coaaFcI0= +github.com/ClickHouse/clickhouse-go v1.5.4/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI= +github.com/ClickHouse/clickhouse-go/v2 v2.28.1 h1:tpdOxWZlZ4IYiFWpIteU57JVdWVbSI5OwflofAdhFno= +github.com/ClickHouse/clickhouse-go/v2 v2.28.1/go.mod h1:0U915l9qynE508ehh3ea9+UMGc7gZlAV+9W6pUZd7kk= +github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= +github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ= +github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= +github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo= +github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/elastic/go-sysinfo v1.8.1/go.mod h1:JfllUnzoQV/JRYymbH3dO1yggI3mV2oTKSXsDHM+uIM= +github.com/elastic/go-sysinfo v1.14.1 h1:BpY/Utfz75oKSpsQnbAJmmlnT3gBV9WFsopBEYgjhZY= +github.com/elastic/go-sysinfo v1.14.1/go.mod h1:FKUXnZWhnYI0ueO7jhsGV3uQJ5hiz8OqM5b3oGyaRr8= +github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU= +github.com/elastic/go-windows v1.0.2 h1:yoLLsAsV5cfg9FLhZ9EXZ2n2sQFKeDYrHenkcivY4vI= +github.com/elastic/go-windows v1.0.2/go.mod h1:bGcDpBzXgYSqM0Gx3DM4+UxFj300SZLixie9u9ixLM8= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= +github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/go-faster/city v1.0.1 h1:4WAxSZ3V2Ws4QRDrscLEDcibJY8uf41H6AhXDrNDcGw= +github.com/go-faster/city v1.0.1/go.mod h1:jKcUJId49qdW3L1qKHH/3wPeUstCVpVSXTM6vO3VcTw= +github.com/go-faster/errors v0.7.1 h1:MkJTnDoEdi9pDabt1dpWf7AA8/BaSYZqibYyhZ20AYg= +github.com/go-faster/errors v0.7.1/go.mod h1:5ySTjWFiphBs07IKuiL69nxdfd5+fzh1u7FPGZP2quo= +github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= +github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA= +github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= +github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A= +github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +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/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= +github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY= +github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw= +github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= +github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4= +github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= +github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4= +github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/libsql/sqlite-antlr4-parser v0.0.0-20240721121621-c0bdc870f11c h1:WsJ6G+hkDXIMfQE8FIxnnziT26WmsRgZhdWQ0IQGlcc= +github.com/libsql/sqlite-antlr4-parser v0.0.0-20240721121621-c0bdc870f11c/go.mod h1:gIcFddvsvPcRCO6QDmWH9/zcFd5U26QWWRMgZh4ddyo= +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/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY= +github.com/mfridman/interpolate v0.0.2/go.mod h1:p+7uk6oE07mpE/Ik1b8EckO0O4ZXiGAfshKBWLUM9Xg= +github.com/microsoft/go-mssqldb v1.7.2 h1:CHkFJiObW7ItKTJfHo1QX7QBBD1iV+mn1eOyRP3b/PA= +github.com/microsoft/go-mssqldb v1.7.2/go.mod h1:kOvZKUdrhhFQmxLZqbwUV0rHkNkZpthMITIb2Ko1IoA= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +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/paulmach/orb v0.11.1 h1:3koVegMC4X/WeiXYz9iswopaTwMem53NzTJuTF20JzU= +github.com/paulmach/orb v0.11.1/go.mod h1:5mULz1xQfs3bmQm63QEJA6lNGujuRafwA5S/EnuLaLU= +github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY= +github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= +github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +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/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pressly/goose/v3 v3.21.1 h1:5SSAKKWej8LVVzNLuT6KIvP1eFDuPvxa+B6H0w78buQ= +github.com/pressly/goose/v3 v3.21.1/go.mod h1:sqthmzV8PitchEkjecFJII//l43dLOCzfWh8pHEe+vE= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +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/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= +github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +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/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/tursodatabase/libsql-client-go v0.0.0-20240812094001-348a4e45b535 h1:iLjJLq2A5J6L9zrhyNn+fpmxFvtEpYB4XLMr0rX3epI= +github.com/tursodatabase/libsql-client-go v0.0.0-20240812094001-348a4e45b535/go.mod h1:l8xTsYB90uaVdMHXMCxKKLSgw5wLYBwBKKefNIUnm9s= +github.com/vertica/vertica-sql-go v1.3.3 h1:fL+FKEAEy5ONmsvya2WH5T8bhkvY27y/Ik3ReR2T+Qw= +github.com/vertica/vertica-sql-go v1.3.3/go.mod h1:jnn2GFuv+O2Jcjktb7zyc4Utlbu9YVqpHH/lx63+1M4= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= +github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= +github.com/ydb-platform/ydb-go-genproto v0.0.0-20240821162910-6cb364b2ccc8 h1:ZWxYw6L51aNAMLbTpC/VbXP0rcnvsCAJqx7EI/CjWmc= +github.com/ydb-platform/ydb-go-genproto v0.0.0-20240821162910-6cb364b2ccc8/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I= +github.com/ydb-platform/ydb-go-sdk/v3 v3.77.1 h1:1ICGD18cquyG7/bKQ1ZFdQYSvDvmF7m62b5bIYC8Dkw= +github.com/ydb-platform/ydb-go-sdk/v3 v3.77.1/go.mod h1:IHwuXyolaAmGK2Dp7+dlhsnXphG1pwCoaP/OITT3+tU= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs= +github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= +go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= +go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= +go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= +go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4= +go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++8WpuKPcR5yjLBjvLEA= +golang.org/x/exp v0.0.0-20240823005443-9b4947da3948/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed h1:J6izYgfBXAI3xTKLgxzTmUltdYaLsuBxFCgDHWJ/eXg= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c= +google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0= +howett.net/plist v1.0.1 h1:37GdZ8tP09Q35o9ych3ehygcsL+HqKSwzctveSlarvM= +howett.net/plist v1.0.1/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g= +modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a h1:CfbpOLEo2IwNzJdMvE8aiRbPMxoTpgAJeyePh0SmO8M= +modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4= +modernc.org/libc v1.60.0 h1:XeRF1gXky7JE5E8IErtYAdKj+ykZPdYUsgJNQ8RFWIA= +modernc.org/libc v1.60.0/go.mod h1:xJuobKuNxKH3RUatS7GjR+suWj+5c2K7bi4m/S5arOY= +modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4= +modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo= +modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E= +modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU= +modernc.org/sqlite v1.32.0 h1:6BM4uGza7bWypsw4fdLRsLxut6bHe4c58VeqjRgST8s= +modernc.org/sqlite v1.32.0/go.mod h1:UqoylwmTb9F+IqXERT8bW9zzOWN8qwAIcLdzeBZs4hA= +modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= +modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0= +modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= +modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= +nhooyr.io/websocket v1.8.17 h1:KEVeLJkUywCKVsnLIDlD/5gtayKp8VoCkksHCGGfT9Y= +nhooyr.io/websocket v1.8.17/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c= diff --git a/internal/actions/add_orders.go b/internal/actions/add_orders.go new file mode 100644 index 0000000..7bd10a8 --- /dev/null +++ b/internal/actions/add_orders.go @@ -0,0 +1,53 @@ +package actions + +import ( + "context" + "fmt" + "github.com/google/uuid" + "github.com/spqrcor/gofermart/internal/authenticate" + "github.com/spqrcor/gofermart/internal/db" + "time" +) + +var ErrOrderAnotherUserExists = fmt.Errorf("order another user exists") +var ErrOrderUserExists = fmt.Errorf("order user exists") +var ErrOrderInvalidFormat = fmt.Errorf("order invalid format") + +func AddOrder(ctx context.Context, orderNum string) error { + if !isNumberValid(orderNum) { + return ErrOrderInvalidFormat + } + + var baseUserID, baseOrderID string + orderId := uuid.NewString() + userId := ctx.Value(authenticate.ContextUserID) + childCtx, cancel := context.WithTimeout(ctx, time.Second*3) + defer cancel() + err := db.Source.QueryRowContext(childCtx, "INSERT INTO orders (id, user_id, number) VALUES ($1, $2, $3) "+ + "ON CONFLICT(number) DO UPDATE SET number = EXCLUDED.number RETURNING id, user_id", orderId, userId, orderNum).Scan(&baseOrderID, &baseUserID) + if err != nil { + return err + } else if userId != uuid.MustParse(baseUserID) { + return ErrOrderAnotherUserExists + } else if orderId != baseOrderID { + return ErrOrderUserExists + } + return nil +} + +func isNumberValid(orderNum string) bool { + total := 0 + isSecondDigit := false + for i := len(orderNum) - 1; i >= 0; i-- { + digit := int(orderNum[i] - '0') + if isSecondDigit { + digit *= 2 + if digit > 9 { + digit -= 9 + } + } + total += digit + isSecondDigit = !isSecondDigit + } + return total%10 == 0 +} diff --git a/internal/actions/add_withdraw.go b/internal/actions/add_withdraw.go new file mode 100644 index 0000000..34668f0 --- /dev/null +++ b/internal/actions/add_withdraw.go @@ -0,0 +1,57 @@ +package actions + +import ( + "context" + "database/sql" + "errors" + "fmt" + "github.com/jackc/pgx/v5/pgconn" + "github.com/spqrcor/gofermart/internal/authenticate" + "github.com/spqrcor/gofermart/internal/db" + "time" +) + +type InputWithdraw struct { + OrderNum string `json:"order"` + Sum int `json:"sum"` +} + +var ErrBalance = fmt.Errorf("balance error") + +func AddWithdraw(ctx context.Context, input InputWithdraw) error { + if !isNumberValid(input.OrderNum) { + return ErrOrderInvalidFormat + } + userId := ctx.Value(authenticate.ContextUserID) + + childCtx, cancel := context.WithTimeout(ctx, time.Second*3) + defer cancel() + + tx, err := db.Source.BeginTx(childCtx, nil) + if err != nil { + return err + } + _, err = tx.ExecContext(childCtx, "UPDATE users SET balance = balance - $2 WHERE id = $1", userId, input.Sum) + if err != nil { + _ = tx.Rollback() + var pgError *pgconn.PgError + if errors.As(err, &pgError) && pgError.ConstraintName == "users_balance_check" { + return ErrBalance + } + return err + } + + var withdrawID string + err = tx.QueryRowContext(childCtx, "INSERT INTO withdraw_list (order_id, sum) SELECT id, $3 FROM orders WHERE user_id = $1 AND number = $2 RETURNING id", userId, input.OrderNum, input.Sum).Scan(&withdrawID) + if err != nil { + _ = tx.Rollback() + if errors.Is(err, sql.ErrNoRows) { + return ErrOrderInvalidFormat + } + return err + } + if err = tx.Commit(); err != nil { + return err + } + return nil +} diff --git a/internal/actions/get_balance.go b/internal/actions/get_balance.go new file mode 100644 index 0000000..e173706 --- /dev/null +++ b/internal/actions/get_balance.go @@ -0,0 +1,27 @@ +package actions + +import ( + "context" + "errors" + "github.com/spqrcor/gofermart/internal/authenticate" + "github.com/spqrcor/gofermart/internal/db" + "time" +) + +type BalanceInfo struct { + Current int `json:"current"` + Withdrawn int `json:"withdrawn"` +} + +func GetBalanceInfo(ctx context.Context) (BalanceInfo, error) { + balanceInfo := BalanceInfo{} + childCtx, cancel := context.WithTimeout(ctx, time.Second*3) + defer cancel() + + row := db.Source.QueryRowContext(childCtx, "SELECT balance, (SELECT COALESCE(SUM(wl.sum), 0) FROM withdraw_list wl INNER JOIN orders o ON o.id = wl.order_id WHERE o.user_id = u.id) "+ + "FROM users u WHERE id = $1", ctx.Value(authenticate.ContextUserID)) + if err := row.Scan(&balanceInfo.Current, &balanceInfo.Withdrawn); err != nil { + return balanceInfo, errors.New("User not found") + } + return balanceInfo, nil +} diff --git a/internal/actions/get_orders.go b/internal/actions/get_orders.go new file mode 100644 index 0000000..365435d --- /dev/null +++ b/internal/actions/get_orders.go @@ -0,0 +1,54 @@ +package actions + +import ( + "context" + "database/sql" + "fmt" + "github.com/spqrcor/gofermart/internal/authenticate" + "github.com/spqrcor/gofermart/internal/db" + "github.com/spqrcor/gofermart/internal/logger" + "time" +) + +type Order struct { + Number string `json:"number"` + Status string `json:"status"` + Accrual int `json:"accrual,omitempty"` + UploadedAt string `json:"uploaded_at"` +} + +var ErrOrdersNotFound = fmt.Errorf("orders not found") + +func GetOrders(ctx context.Context) ([]Order, error) { + var orders []Order + childCtx, cancel := context.WithTimeout(ctx, time.Second*3) + defer cancel() + + rows, err := db.Source.QueryContext(childCtx, "SELECT number, status, accrual, created_at FROM orders WHERE user_id = $1 ORDER BY created_at DESC", ctx.Value(authenticate.ContextUserID)) + if err != nil { + return nil, err + } + defer func() { + if err := rows.Close(); err != nil { + logger.Log.Error(err.Error()) + } + if err := rows.Err(); err != nil { + logger.Log.Error(err.Error()) + } + }() + + for rows.Next() { + o := Order{} + var accrual sql.NullInt32 + if err = rows.Scan(&o.Number, &o.Status, &accrual, &o.UploadedAt); err != nil { + return nil, err + } + o.Accrual = int(accrual.Int32) + orders = append(orders, o) + } + + if len(orders) == 0 { + return nil, ErrOrdersNotFound + } + return orders, nil +} diff --git a/internal/actions/get_withdrawals.go b/internal/actions/get_withdrawals.go new file mode 100644 index 0000000..bea2bb5 --- /dev/null +++ b/internal/actions/get_withdrawals.go @@ -0,0 +1,50 @@ +package actions + +import ( + "context" + "fmt" + "github.com/spqrcor/gofermart/internal/authenticate" + "github.com/spqrcor/gofermart/internal/db" + "github.com/spqrcor/gofermart/internal/logger" + "time" +) + +type Withdraw struct { + OrderNum string `json:"order"` + Sum int `json:"sum"` + ProcessedAt string `json:"processed_at"` +} + +var ErrWithdrawNotFound = fmt.Errorf("withdraw not found") + +func GetWithdraws(ctx context.Context) ([]Withdraw, error) { + var withdraws []Withdraw + childCtx, cancel := context.WithTimeout(ctx, time.Second*3) + defer cancel() + + rows, err := db.Source.QueryContext(childCtx, "SELECT o.number, wl.sum, wl.created_at FROM withdraw_list wl "+ + "INNER JOIN orders o ON o.id = wl.order_id WHERE o.user_id = $1 ORDER BY wl.created_at DESC", ctx.Value(authenticate.ContextUserID)) + if err != nil { + return nil, err + } + defer func() { + if err := rows.Close(); err != nil { + logger.Log.Error(err.Error()) + } + if err := rows.Err(); err != nil { + logger.Log.Error(err.Error()) + } + }() + + for rows.Next() { + w := Withdraw{} + if err = rows.Scan(&w.OrderNum, &w.Sum, &w.ProcessedAt); err != nil { + return nil, err + } + withdraws = append(withdraws, w) + } + if len(withdraws) == 0 { + return nil, ErrWithdrawNotFound + } + return withdraws, nil +} diff --git a/internal/actions/login.go b/internal/actions/login.go new file mode 100644 index 0000000..77664ab --- /dev/null +++ b/internal/actions/login.go @@ -0,0 +1,33 @@ +package actions + +import ( + "context" + "database/sql" + "errors" + "fmt" + "github.com/google/uuid" + "github.com/spqrcor/gofermart/internal/db" + "golang.org/x/crypto/bcrypt" + "time" +) + +var ErrLogin = fmt.Errorf("login error") + +func Login(ctx context.Context, input InputDataUser) (uuid.UUID, error) { + childCtx, cancel := context.WithTimeout(ctx, time.Second*3) + defer cancel() + row := db.Source.QueryRowContext(childCtx, "SELECT id, password FROM users WHERE login = $1", input.Login) + + var userID, password string + err := row.Scan(&userID, &password) + if errors.Is(err, sql.ErrNoRows) { + return uuid.Nil, ErrLogin + } else if err != nil { + return uuid.Nil, err + } + + if err := bcrypt.CompareHashAndPassword([]byte(password), []byte(input.Password)); err != nil { + return uuid.Nil, ErrLogin + } + return uuid.MustParse(userID), nil +} diff --git a/internal/actions/register.go b/internal/actions/register.go new file mode 100644 index 0000000..2d77149 --- /dev/null +++ b/internal/actions/register.go @@ -0,0 +1,56 @@ +package actions + +import ( + "context" + "fmt" + "github.com/google/uuid" + "github.com/spqrcor/gofermart/internal/db" + "golang.org/x/crypto/bcrypt" + "time" +) + +const minPasswordLength = 6 +const maxPasswordLength = 72 +const minLoginLength = 3 +const maxLoginLength = 255 + +type InputDataUser struct { + Login string `json:"login"` + Password string `json:"password"` +} + +var ErrLoginExists = fmt.Errorf("login exists") +var ErrValidation = fmt.Errorf("validation error") + +func Register(ctx context.Context, input InputDataUser) (uuid.UUID, error) { + if err := validate(input); err != nil { + return uuid.Nil, err + } + bytes, err := bcrypt.GenerateFromPassword([]byte(input.Password), 14) + if err != nil { + return uuid.Nil, err + } + + baseUserID := "" + userId := uuid.NewString() + childCtx, cancel := context.WithTimeout(ctx, time.Second*3) + defer cancel() + err = db.Source.QueryRowContext(childCtx, "INSERT INTO users (id, login, password) VALUES ($1, $2, $3) "+ + "ON CONFLICT(login) DO UPDATE SET login = EXCLUDED.login RETURNING id", userId, input.Login, string(bytes)).Scan(&baseUserID) + if err != nil { + return uuid.Nil, err + } else if userId != baseUserID { + return uuid.Nil, ErrLoginExists + } + return uuid.MustParse(baseUserID), nil +} + +func validate(input InputDataUser) error { + if (len(input.Login) < minLoginLength) || (len(input.Login) > maxLoginLength) { + return fmt.Errorf("%w: ошибка при заполнении login, корректная длина от 3 до 255", ErrValidation) + } + if (len(input.Password) < minPasswordLength) || (len(input.Password) > maxPasswordLength) { + return fmt.Errorf("%w: ошибка при заполнении password, корректная длина от 6 до 72", ErrValidation) + } + return nil +} diff --git a/internal/authenticate/authenticate.go b/internal/authenticate/authenticate.go new file mode 100644 index 0000000..1614641 --- /dev/null +++ b/internal/authenticate/authenticate.go @@ -0,0 +1,70 @@ +package authenticate + +import ( + "fmt" + "github.com/golang-jwt/jwt/v4" + "github.com/google/uuid" + "github.com/spqrcor/gofermart/internal/logger" + "net/http" + "strings" + "time" +) + +type Claims struct { + jwt.RegisteredClaims + UserID uuid.UUID +} +type ContextKey string + +var ContextUserID ContextKey = "UserID" + +const tokenExp = time.Hour * 3 +const secretKey = "KLJ-fo3Fksd3fl!=" + +func CreateCookie(UserID uuid.UUID) (http.Cookie, error) { + token, err := createToken(UserID) + if err != nil { + return http.Cookie{}, err + } + return http.Cookie{Name: "Authorization", Value: token, Expires: time.Now().Add(tokenExp), HttpOnly: true, Path: "/"}, nil +} + +func createToken(UserID uuid.UUID) (string, error) { + token := jwt.NewWithClaims(jwt.SigningMethodHS256, Claims{ + RegisteredClaims: jwt.RegisteredClaims{ + ExpiresAt: jwt.NewNumericDate(time.Now().Add(tokenExp)), + }, + UserID: UserID, + }) + + tokenString, err := token.SignedString([]byte(secretKey)) + if err != nil { + return "", err + } + return "Bearer " + tokenString, nil +} + +func GetUserIDFromCookie(tokenString string) (uuid.UUID, error) { + claims := &Claims{} + token, err := jwt.ParseWithClaims(strings.TrimPrefix(tokenString, "Bearer "), claims, + func(t *jwt.Token) (interface{}, error) { + return []byte(secretKey), nil + }) + if err != nil { + return uuid.Nil, err + } + + if !token.Valid { + return uuid.Nil, fmt.Errorf("invalid token") + } + return claims.UserID, nil +} + +func SetCookie(rw http.ResponseWriter, UserID uuid.UUID) { + cookie, err := CreateCookie(UserID) + if err != nil { + logger.Log.Error(err.Error()) + } else { + http.SetCookie(rw, &cookie) + } +} diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..92b559d --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,43 @@ +package config + +import ( + "flag" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "os" +) + +type Config struct { + RunAddr string `env:"RUN_ADDRESS"` + AccrualSystemAddress string `env:"ACCRUAL_SYSTEM_ADDRESS"` + LogLevel zapcore.Level `env:"LOG_LEVEL"` + DatabaseURI string `env:"DATABASE_URI"` +} + +var Cfg = Config{ + RunAddr: "localhost:8080", + LogLevel: zap.InfoLevel, + AccrualSystemAddress: "", + DatabaseURI: "", +} + +func Init() { + flag.StringVar(&Cfg.RunAddr, "a", Cfg.RunAddr, "address and port to run server") + flag.StringVar(&Cfg.AccrualSystemAddress, "r", Cfg.AccrualSystemAddress, "accrual system address") + flag.StringVar(&Cfg.DatabaseURI, "d", Cfg.DatabaseURI, "database uri") + flag.Parse() + + serverAddressEnv, findAddress := os.LookupEnv("RUN_ADDRESS") + serverDatabaseURI, findDatabaseURI := os.LookupEnv("DATABASE_URI") + serverAccrualSystemAddress, findAccrualSystemAddress := os.LookupEnv("ACCRUAL_SYSTEM_ADDRESS") + + if findAddress { + Cfg.RunAddr = serverAddressEnv + } + if findDatabaseURI { + Cfg.DatabaseURI = serverDatabaseURI + } + if findAccrualSystemAddress { + Cfg.AccrualSystemAddress = serverAccrualSystemAddress + } +} diff --git a/internal/db/connector.go b/internal/db/connector.go new file mode 100644 index 0000000..b64c38f --- /dev/null +++ b/internal/db/connector.go @@ -0,0 +1,32 @@ +package db + +import ( + "database/sql" + _ "github.com/jackc/pgx/v5/stdlib" + "github.com/spqrcor/gofermart/internal/config" + "github.com/spqrcor/gofermart/internal/logger" +) + +var Source *sql.DB + +func connect() (*sql.DB, error) { + db, err := sql.Open("pgx", config.Cfg.DatabaseURI) + if err != nil { + logger.Log.Fatal(err.Error()) + return nil, err + } + if err := db.Ping(); err != nil { + logger.Log.Error(err.Error()) + return nil, err + } + return db, nil +} + +func Init() { + res, err := connect() + if err != nil { + logger.Log.Fatal(err.Error()) + } + Migrate(res) + Source = res +} diff --git a/internal/db/migrator.go b/internal/db/migrator.go new file mode 100644 index 0000000..124b1f6 --- /dev/null +++ b/internal/db/migrator.go @@ -0,0 +1,17 @@ +package db + +import ( + "database/sql" + "github.com/pressly/goose/v3" + "github.com/spqrcor/gofermart/internal/logger" +) + +func Migrate(db *sql.DB) { + if err := goose.SetDialect("postgres"); err != nil { + logger.Log.Fatal(err.Error()) + } + + if err := goose.Up(db, "internal/migrations"); err != nil { + logger.Log.Fatal(err.Error()) + } +} diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go new file mode 100644 index 0000000..9fddbd4 --- /dev/null +++ b/internal/handlers/handlers.go @@ -0,0 +1,154 @@ +package handlers + +import ( + "encoding/json" + "errors" + "github.com/spqrcor/gofermart/internal/actions" + "github.com/spqrcor/gofermart/internal/authenticate" + "github.com/spqrcor/gofermart/internal/utils" + "net/http" +) + +func RegisterHandler(res http.ResponseWriter, req *http.Request) { + var input actions.InputDataUser + if err := utils.FromPostJSON(req, &input); err != nil { + res.WriteHeader(http.StatusBadRequest) + return + } + + UserID, err := actions.Register(req.Context(), input) + if errors.Is(err, actions.ErrValidation) { + http.Error(res, err.Error(), http.StatusBadRequest) + return + } else if errors.Is(err, actions.ErrLoginExists) { + res.WriteHeader(http.StatusConflict) + return + } else if err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } + + authenticate.SetCookie(res, UserID) + res.WriteHeader(http.StatusOK) +} + +func LoginHandler(res http.ResponseWriter, req *http.Request) { + var input actions.InputDataUser + if err := utils.FromPostJSON(req, &input); err != nil { + res.WriteHeader(http.StatusBadRequest) + return + } + + UserID, err := actions.Login(req.Context(), input) + if errors.Is(err, actions.ErrLogin) { + http.Error(res, err.Error(), http.StatusUnauthorized) + return + } else if err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } + + authenticate.SetCookie(res, UserID) + res.WriteHeader(http.StatusOK) +} + +func AddOrdersHandler(res http.ResponseWriter, req *http.Request) { + orderNum, err := utils.FromPostPlain(req) + if err != nil { + res.WriteHeader(http.StatusBadRequest) + return + } + + err = actions.AddOrder(req.Context(), orderNum) + if errors.Is(err, actions.ErrOrderInvalidFormat) { + http.Error(res, err.Error(), http.StatusUnprocessableEntity) + return + } else if errors.Is(err, actions.ErrOrderAnotherUserExists) { + res.WriteHeader(http.StatusConflict) + return + } else if errors.Is(err, actions.ErrOrderUserExists) { + res.WriteHeader(http.StatusOK) + return + } else if err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } + + res.WriteHeader(http.StatusAccepted) +} + +func GetOrdersHandler(res http.ResponseWriter, req *http.Request) { + orders, err := actions.GetOrders(req.Context()) + if errors.Is(err, actions.ErrOrdersNotFound) { + res.WriteHeader(http.StatusNoContent) + return + } else if err != nil { + http.Error(res, err.Error(), http.StatusInternalServerError) + return + } + + res.Header().Set("Content-Type", "application/json; charset=utf-8") + res.WriteHeader(http.StatusOK) + enc := json.NewEncoder(res) + if err := enc.Encode(orders); err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } +} + +func GetBalanceHandler(res http.ResponseWriter, req *http.Request) { + balanceInfo, err := actions.GetBalanceInfo(req.Context()) + if err != nil { + http.Error(res, err.Error(), http.StatusInternalServerError) + return + } + + res.Header().Set("Content-Type", "application/json; charset=utf-8") + res.WriteHeader(http.StatusOK) + enc := json.NewEncoder(res) + if err := enc.Encode(balanceInfo); err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } +} + +func GetWithdrawalsHandler(res http.ResponseWriter, req *http.Request) { + withdraws, err := actions.GetWithdraws(req.Context()) + if errors.Is(err, actions.ErrWithdrawNotFound) { + res.WriteHeader(http.StatusNoContent) + return + } else if err != nil { + http.Error(res, err.Error(), http.StatusInternalServerError) + return + } + + res.Header().Set("Content-Type", "application/json; charset=utf-8") + res.WriteHeader(http.StatusOK) + enc := json.NewEncoder(res) + if err := enc.Encode(withdraws); err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } +} + +func BalanceWithdrawHandler(res http.ResponseWriter, req *http.Request) { + var input actions.InputWithdraw + if err := utils.FromPostJSON(req, &input); err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } + + err := actions.AddWithdraw(req.Context(), input) + if errors.Is(err, actions.ErrOrderInvalidFormat) { + http.Error(res, err.Error(), http.StatusUnprocessableEntity) + return + } else if errors.Is(err, actions.ErrBalance) { + http.Error(res, err.Error(), http.StatusPaymentRequired) + return + } else if err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } + + res.WriteHeader(http.StatusOK) +} diff --git a/internal/logger/logger.go b/internal/logger/logger.go new file mode 100644 index 0000000..3ebf795 --- /dev/null +++ b/internal/logger/logger.go @@ -0,0 +1,19 @@ +package logger + +import ( + "github.com/spqrcor/gofermart/internal/config" + "go.uber.org/zap" + "log" +) + +var Log *zap.Logger = zap.NewNop() + +func Init() { + cfg := zap.NewProductionConfig() + cfg.Level = zap.NewAtomicLevelAt(config.Cfg.LogLevel) + zl, err := cfg.Build() + if err != nil { + log.Fatal(err) + } + Log = zl +} diff --git a/internal/migrations/20240829113459_create_users_table.sql b/internal/migrations/20240829113459_create_users_table.sql new file mode 100644 index 0000000..b72c7e5 --- /dev/null +++ b/internal/migrations/20240829113459_create_users_table.sql @@ -0,0 +1,23 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE public.users ( + id uuid DEFAULT gen_random_uuid() NOT NULL, + login varchar(255) NOT NULL, + password varchar(60) NOT NULL, + balance integer DEFAULT 0 NOT NULL CHECK (balance >= 0), + created_at timestamptz DEFAULT now() NOT NULL, + CONSTRAINT users_pkey PRIMARY KEY (id) +); +CREATE UNIQUE INDEX users_login_idx ON public.users (login); + +COMMENT ON COLUMN public.users.id IS 'UUID'; +COMMENT ON COLUMN public.users.login IS 'Логин'; +COMMENT ON COLUMN public.users.password IS 'Пароль'; +COMMENT ON COLUMN public.users.balance IS 'Текущий баланс'; +COMMENT ON COLUMN public.users.created_at IS 'Дата создания'; +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE public.users; +-- +goose StatementEnd diff --git a/internal/migrations/20240903125144_create_orders_table.sql b/internal/migrations/20240903125144_create_orders_table.sql new file mode 100644 index 0000000..403800e --- /dev/null +++ b/internal/migrations/20240903125144_create_orders_table.sql @@ -0,0 +1,33 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TYPE e_order_status AS ENUM ('NEW', 'PROCESSING', 'INVALID', 'PROCESSED'); + +CREATE TABLE public.orders ( + id uuid DEFAULT gen_random_uuid() NOT NULL, + user_id uuid NOT NULL, + number varchar(20) NOT NULL, + status e_order_status DEFAULT 'NEW' NOT NULL, + accrual integer, + created_at timestamptz DEFAULT now() NOT NULL, + updated_at timestamptz, + CONSTRAINT orders_pkey PRIMARY KEY (id) +); +CREATE UNIQUE INDEX orders_number_idx ON public.orders (number); +CREATE INDEX orders_user_id_idx ON public.orders (user_id); +CREATE INDEX orders_created_at_idx ON public.orders (created_at DESC); + +COMMENT ON COLUMN public.orders.id IS 'UUID'; +COMMENT ON COLUMN public.orders.user_id IS 'UUID пользователя'; +COMMENT ON COLUMN public.orders.number IS 'Номер заказа'; +COMMENT ON COLUMN public.orders.status IS 'Статус заказа'; +COMMENT ON COLUMN public.orders.accrual IS 'Рассчитанные баллы к начислению'; +COMMENT ON COLUMN public.orders.created_at IS 'Дата создания'; +COMMENT ON COLUMN public.orders.updated_at IS 'Дата последнего обновления'; +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE public.orders; + +DROP TYPE public.e_order_status; +-- +goose StatementEnd diff --git a/internal/migrations/20240903131837_create_withdraw_list_table.sql b/internal/migrations/20240903131837_create_withdraw_list_table.sql new file mode 100644 index 0000000..2773437 --- /dev/null +++ b/internal/migrations/20240903131837_create_withdraw_list_table.sql @@ -0,0 +1,22 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE public.withdraw_list ( + id uuid DEFAULT gen_random_uuid() NOT NULL, + order_id uuid NOT NULL, + sum integer NOT NULL CHECK (sum > 0), + created_at timestamptz DEFAULT now() NOT NULL, + CONSTRAINT withdraw_list_pkey PRIMARY KEY (id) +); +CREATE INDEX withdraw_list_order_id_idx ON public.withdraw_list (order_id); +CREATE INDEX withdraw_list_created_at_idx ON public.withdraw_list (created_at DESC); + +COMMENT ON COLUMN public.withdraw_list.id IS 'UUID'; +COMMENT ON COLUMN public.withdraw_list.order_id IS 'UUID заказа'; +COMMENT ON COLUMN public.withdraw_list.sum IS 'Сумма баллов к списанию'; +COMMENT ON COLUMN public.withdraw_list.created_at IS 'Дата создания'; +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE public.withdraw_list; +-- +goose StatementEnd diff --git a/internal/server/middleware.go b/internal/server/middleware.go new file mode 100644 index 0000000..1f1abec --- /dev/null +++ b/internal/server/middleware.go @@ -0,0 +1,70 @@ +package server + +import ( + "compress/gzip" + "context" + "github.com/go-chi/chi/v5/middleware" + "github.com/spqrcor/gofermart/internal/authenticate" + "github.com/spqrcor/gofermart/internal/logger" + "go.uber.org/zap" + "net/http" + "slices" + "time" +) + +func getBodyMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { + if r.Header.Get(`Content-Encoding`) == `gzip` { + gz, err := gzip.NewReader(r.Body) + if err != nil { + logger.Log.Error(err.Error()) + } else { + r.Body = gz + } + if err = gz.Close(); err != nil { + logger.Log.Error(err.Error()) + } + } + next.ServeHTTP(rw, r) + }) +} + +func loggerMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { + start := time.Now() + ww := middleware.NewWrapResponseWriter(rw, r.ProtoMajor) + next.ServeHTTP(ww, r) + duration := time.Since(start) + + logger.Log.Info("HTTP request", + zap.String("method", r.Method), + zap.String("path", r.URL.Path), + zap.Int("status", ww.Status()), + zap.Int("content-length", ww.BytesWritten()), + zap.String("duration", duration.String()), + ) + }) +} + +func authenticateMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { + cookie, err := r.Cookie("Authorization") + if err != nil { + idx := slices.IndexFunc(publicRoutes, func(c string) bool { return c == r.RequestURI }) + if idx == -1 { + http.Error(rw, err.Error(), http.StatusUnauthorized) + return + } + next.ServeHTTP(rw, r) + } else { + UserID, err := authenticate.GetUserIDFromCookie(cookie.Value) + if err != nil { + logger.Log.Error(err.Error()) + http.Error(rw, err.Error(), http.StatusInternalServerError) + return + } + ctx := context.WithValue(r.Context(), authenticate.ContextUserID, UserID) + next.ServeHTTP(rw, r.WithContext(ctx)) + } + }) +} diff --git a/internal/server/server.go b/internal/server/server.go new file mode 100644 index 0000000..aaa052a --- /dev/null +++ b/internal/server/server.go @@ -0,0 +1,34 @@ +package server + +import ( + "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5/middleware" + "github.com/spqrcor/gofermart/internal/config" + "github.com/spqrcor/gofermart/internal/handlers" + "log" + "net/http" +) + +var publicRoutes = []string{"/api/user/register", "/api/user/login"} + +func Start() { + r := chi.NewRouter() + r.Use(authenticateMiddleware) + r.Use(loggerMiddleware) + r.Use(middleware.Compress(5, "application/json", "text/html")) + r.Use(getBodyMiddleware) + + r.Post("/api/user/register", handlers.RegisterHandler) + r.Post("/api/user/login", handlers.LoginHandler) + r.Post("/api/user/orders", handlers.AddOrdersHandler) + r.Get("/api/user/orders", handlers.GetOrdersHandler) + r.Get("/api/user/balance", handlers.GetBalanceHandler) + r.Post("/api/user/balance/withdraw", handlers.BalanceWithdrawHandler) + r.Get("/api/user/withdrawals", handlers.GetWithdrawalsHandler) + + r.HandleFunc(`/*`, func(res http.ResponseWriter, req *http.Request) { + res.WriteHeader(http.StatusBadRequest) + }) + + log.Fatal(http.ListenAndServe(config.Cfg.RunAddr, r)) +} diff --git a/internal/utils/utils.go b/internal/utils/utils.go new file mode 100644 index 0000000..46eac26 --- /dev/null +++ b/internal/utils/utils.go @@ -0,0 +1,38 @@ +package utils + +import ( + "bytes" + "encoding/json" + "errors" + "net/http" + "strings" +) + +func FromPostJSON(req *http.Request, input any) error { + if req.Method != http.MethodPost || !strings.Contains(req.Header.Get("Content-Type"), "application/json") { + return errors.New("invalid request") + } + + var buf bytes.Buffer + _, err := buf.ReadFrom(req.Body) + if err != nil { + return err + } + if err = json.Unmarshal(buf.Bytes(), &input); err != nil { + return err + } + return nil +} + +func FromPostPlain(req *http.Request) (string, error) { + if req.Method != http.MethodPost || !strings.Contains(req.Header.Get("Content-Type"), "text/plain") { + return "", errors.New("invalid request") + } + + var buf bytes.Buffer + _, err := buf.ReadFrom(req.Body) + if err != nil { + return "", err + } + return buf.String(), nil +}