diff --git a/go.mod b/go.mod index 1d70472179b084f5eee7b6aee39b6259b62c75de..abcef6826be5d91afb659479281a6434046b0fbb 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,29 @@ module git.hilo.cn/hilo-common go 1.17 require ( + github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect + github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/fatih/color v1.9.0 // indirect + github.com/go-redis/redis/v8 v8.11.5 // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect + github.com/hashicorp/consul/api v1.7.0 // indirect + github.com/hashicorp/go-cleanhttp v0.5.1 // indirect + github.com/hashicorp/go-hclog v0.12.0 // indirect + github.com/hashicorp/go-immutable-radix v1.0.0 // indirect + github.com/hashicorp/go-rootcerts v1.0.2 // indirect + github.com/hashicorp/golang-lru v0.5.0 // indirect + github.com/hashicorp/serf v0.9.3 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect + github.com/joho/godotenv v1.3.0 // indirect github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect github.com/lestrrat-go/strftime v1.0.6 // indirect + github.com/mattn/go-colorable v0.1.6 // indirect + github.com/mattn/go-isatty v0.0.12 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/mitchellh/mapstructure v1.1.2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 // indirect github.com/satori/go.uuid v1.2.0 // indirect @@ -16,6 +33,7 @@ require ( github.com/spf13/cast v1.5.0 // indirect github.com/tealeg/xlsx v1.0.5 // indirect golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect + gopkg.in/ini.v1 v1.63.2 // indirect gorm.io/driver/mysql v1.4.3 // indirect gorm.io/gorm v1.23.8 // indirect ) diff --git a/go.sum b/go.sum index 17c7b548f67d9489857d2008e130a48e74555e69..e99e1588f675b67523f9943b505be520a06d5809 100644 --- a/go.sum +++ b/go.sum @@ -1,16 +1,61 @@ +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZFFEjBj46YV4rDjvGrNxb0KMWYkL2I= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= +github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 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/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= +github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= +github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= +github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/hashicorp/consul/api v1.7.0 h1:tGs8Oep67r8CcA2Ycmb/8BLBcJ70St44mF2X10a/qPg= +github.com/hashicorp/consul/api v1.7.0/go.mod h1:1NSuaUUkFaJzMasbfq/11wKYWSR67Xn6r2DXKhuDNFg= +github.com/hashicorp/consul/sdk v0.6.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-hclog v0.12.0 h1:d4QkX8FRTYaKaCZBoXYY8zJX2BXjWxurN/GA2tkrmZM= +github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= +github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc= +github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY= +github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= +github.com/hashicorp/serf v0.9.3 h1:AVF6JDQQens6nMHT9OGERBvK0f8rPrAGILnsKLr6lzM= +github.com/hashicorp/serf v0.9.3/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas= github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 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/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is= @@ -18,13 +63,38 @@ github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkL github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA= github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205AhTIGQQ= github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= +github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= +github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +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/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= @@ -34,14 +104,43 @@ github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 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.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE= github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +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-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +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/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/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-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/ini.v1 v1.63.2 h1:tGK/CyBg7SMzb60vP1M03vNZ3VDu3wGQJwn7Sxi9r3c= +gopkg.in/ini.v1 v1.63.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/driver/mysql v1.4.3 h1:/JhWJhO2v17d8hjApTltKNADm7K7YI2ogkR7avJUL3k= gorm.io/driver/mysql v1.4.3/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c= diff --git a/resource/config/config.go b/resource/config/config.go new file mode 100644 index 0000000000000000000000000000000000000000..6b802aeb76fd710d79f421971a5ae571aaf07a06 --- /dev/null +++ b/resource/config/config.go @@ -0,0 +1,779 @@ +package config + +import ( + "git.hilo.cn/hilo-common/mylogrus" + "github.com/joho/godotenv" + "gopkg.in/ini.v1" + "os" + "runtime" + "strconv" +) + +//数据库的配置 +type MysqlConfig struct { + MYSQL_HOST string + MYSQL_USERNAME string + MYSQL_PASSWORD string + MYSQL_DB string +} + +type MysqlCodeConfig struct { + MYSQL_HOST string + MYSQL_USERNAME string + MYSQL_PASSWORD string + MYSQL_DB string +} + +//redis配置 +type RedisConfig struct { + REDIS_HOST string + REDIS_PASSWORD string +} + +//jwt +type JwtConfig struct { + SECRET string + ISSUER_API string + ISSUER_MGR string + EXPIRE string +} + +//jwt +type GameJwtConfig struct { + SECRET string + ISSUER_CLIENT string + ISSUER_SERVER string + EXPIRE string +} + +//oss +type OssConfig struct { + OSS_ACCESS_KEY_ID string + OSS_ACCESS_KEY_SECRET string + OSS_ROLE_ARN string + OSS_END_POINT string + OSS_BUCKET string + OSS_CDN string + OSS_EXPIRED_TIME uint + OSS_STS_POINT string + OSS_STS string + OSS_STS_AES string +} + +// aws +type AwsConfig struct { + AWS_BUCKET string + AWS_CDN string + AWS_DIR string + CONFIDENCE float32 +} + +//APP +type AppConfig struct { + BIZ_SECRET string + WEB_SECRET string + OPERATION_SECRET string + SUPERUSER string + OFFICIAL_GROUP string + MINIMAL_VERSION_ANDROID int + MINIMAL_VERSION_IOS int + MODERATE string +} + +//googlePay 配置信息 +type GooglePayConfig struct { + JsonKey []byte +} + +//融云 +type RongyunConfig struct { + RONG_CLOUD_APP_KEY string + RONG_CLOUD_APP_SECRET string + RONG_CLOUD_URL string +} + +//腾讯云 +type TencentyunConfig struct { + TENCENTYUN_APP_ID int + TENCENTYUN_KEY string + TX_OVERSEA_APP_ID int + TX_OVERSEA_KEY string +} + +//emas +type EmasConfig struct { + ANDROID_APP_KEY string + ANDROID_APP_SECRET string + REGION_ID string + ACCESS_KEY_ID string + ACCESS_KEY_SECRET string + IOS_APP_KEY string + IOS_APP_SECRET string + APNS string +} + +//声网 +type AgoraConfig struct { + APP_ID string + APP_CERTIFICATE string + CUSTOMER_KEY string + CUSTOMER_SECRET string +} + +//匹配的配置 +type MatchConfig struct { + //一开始匹配的默认时长(单位:秒) + MATCH_FREE_TIME int + //一开始匹配的默认时长(单位:秒)VIP + MATCH_FREE_TIME_VIP int + //免费加时的时长 (单位:秒) + MATCH_ADD_TIME_FREE int + //匹配的声网的延迟加时(单位:秒) + MATCH_AGORA_TIME int + //匹配周期(单位:秒) + MATCH_CYCLE int + //过期时间(单位:秒),用户redisCache时间 + MATCH_USER_EXPIRES int + //pb match_success中, wait_duration 开始/下一个时间(单位:秒) + MATCH_SUCCESS_WAIT_DURATION uint32 + //pb match_success中, single_wait_time_in_sec 单方等待连接最长时间(单位:秒) + MATCH_SUCCESS_SINGLE_WAIT_TIME_IN_SEC uint32 + //pb match_success中, dual_wait_time_in_sec 双方连接中最长时间(单位:秒) + MATCH_SUCCESS_DUAL_WAIT_TIME_IN_SEC uint32 +} + +//在线 +type OnlineConfig struct { + //在线周期 + ONLINE_CYCLE int + //在线过期时间 + ONLINE_USER_EXPIRES int +} + +//1对1视频 +type VideoConfig struct { + VIDEO_DAILY_FREE_NUM int + //一开始匹配的默认时长(单位:秒) + VIDEO_FREE_TIME int + //一开始匹配的默认时长(单位:秒),vip + VIDEO_FREE_TIME_VIP int + //免费加时的时长 (单位:秒) + VIDEO_ADD_TIME_FREE int + //声网的延迟加时(单位:秒) + VIDEO_AGORA_TIME int + //1分钟视频,普通用户价格 + VIDEO_MINUTE_NORMAL int + //1分钟视频,公会用户价格 + VIDEO_MINUTE_UNION int +} + +//会话 +type SessionConfig struct { + SESSION_DAILY_FREE_NUM int + GUILD_USER_HELLO_DAY int +} + +type BeanConfig struct { + DIAMOND_BEAN_RATE int +} + +type H5Config struct { + USER_LEVEL string + GROUP_SUPPORT string + LUCKY_WHEEL string + WEEKLY_STAR string + WEEKLY_CP string + COUNTRY_STAR string + NOBLE_BUY_IOS string + GUILD_DATA_URL string + MGR_GUILD_DATA_URL string + RANKING_PINK_DIAMOND_URL string +} + +type GroupImConfig struct { + MSG_SORT_EXPIRE int + MSG_SORT_SNAP int + MSG_PARALLEL_SIZE int +} + +type GradeConfig struct { + //魅力速度 + CHARM_SPEED_VIP int + //活跃 + ACTITY_SPEED_VIP int + //财富 + WEALTH_SPEED_VIP int +} + +type LikeConfig struct { + //喜欢人数 + I_LIKE_NUM int + //喜欢人数VIP + I_LIKE_NUM_VIP int + //喜欢人数贵族 + I_LIKE_NUM_NOBLE int +} + +type ApplePayConfig struct { + PASSWORD string +} + +type RegisterConfig struct { + IMEI_TOTAL int + IMEI_OAUTH int + ACCOUNT_IP int + ACCOUNT_IP_DURATION int +} + +type BannerConfig struct { + GIFT_BANNER_LEVEL1 int + GIFT_BANNER_LEVEL2 int + GIFT_BANNER_LEVEL3 int +} + +type DiamondConfig struct { + DAILY_LOGIN_IMEI_LIMIT int + DAILY_LOGIN_IP_LIMIT int + PRIVATE_GIFT_RETURN int + NEW_USER_INVITE_AWARD uint32 +} + +type LuckWheelConfig struct { + MINIMAL_PARTICIPANT int // 轮盘开始最少需要的参与人数 + WAIT_TIMELONG int // 等待轮盘开始的时长(分钟) + WINNER_DIAMOND_BANNER int //全服广播钻石门槛 +} + +//自定义主题 +type GroupCustomThemeConfig struct { + PIC_LIMIT int //图片数量 + DAY int //有效天数 +} + +type GiftConfig struct { + WALL_DIAMOND int //上礼物墙,礼物钻石金额 +} + +type DailyConfig struct { + LOGIN_COMMON int + LOGIN_VIP int +} + +type FruitTycoonConfig struct { + BIG_WINNER_THRESDHOLD uint + BIG_WINNER_LOW uint + BIG_WINNER_HIGH uint + POOL_RATIO uint32 + WATERMELON_RATIO uint32 +} + +type ActivityConfig struct { + COUNTRY_STAR_POOL_RATIO uint32 + COUNTRY_STAR_ORDINARY_RATIO uint32 +} + +type CheckoutConfig struct { + URL string + AUTHORIZATION string + H5 string + HILO_SECRET_KEY string +} + +type RiskControlConfig struct { + USER_QPS_LIMIT int64 + USER_URL_QPS_LIMIT int64 +} + +type PayerMaxConfig struct { + URL string + KEY string + MERCHANT_ID string + BIZ_TYPE string + VERSION string + FRONT_CALLBACK_URL string + SHOW_RESULT string + EXPIRE_TIME string + LANGUAGE string +} + +type SudConfig struct { + API_LIST string +} + +type URLConfig struct { + BIZ_HTTP string +} + +const ( + LOCAL string = "local" + DEBUG string = "debug" + RELEASE string = "release" +) + +var mysqlConfigData MysqlConfig +var mysqlCodeConfigData MysqlCodeConfig +var redisConfigData RedisConfig +var jwtConfigData JwtConfig +var gameJwtConfigData GameJwtConfig +var appConfigData AppConfig +var ossConfigData OssConfig +var awsConfigData AwsConfig +var googlePayData GooglePayConfig +var rongyunData RongyunConfig +var tencentyunData TencentyunConfig +var emasData EmasConfig +var agora AgoraConfig +var matchData MatchConfig +var onlineData OnlineConfig +var sessionData SessionConfig +var videoData VideoConfig +var beanData BeanConfig +var h5Data H5Config +var groupImData GroupImConfig +var gradeData GradeConfig +var likeData LikeConfig +var applePayData ApplePayConfig +var registerData RegisterConfig +var bannerConfig BannerConfig +var diamondConfig DiamondConfig +var luckyWheelConfig LuckWheelConfig +var groupCustomThemeConfig GroupCustomThemeConfig +var giftConfig GiftConfig +var dailyConfig DailyConfig +var fruitTycoonConfig FruitTycoonConfig +var activityConfig ActivityConfig +var checkoutConfig CheckoutConfig +var riskControl RiskControlConfig +var payerMaxConfig PayerMaxConfig +var mode string +var master bool +var sudConfig SudConfig +var urlConfig URLConfig + +func GetConfigMysql() MysqlConfig { + return mysqlConfigData +} + +func GetConfigMysqlCode() MysqlCodeConfig { + return mysqlCodeConfigData +} + +func GetConfigRedis() RedisConfig { + return redisConfigData +} + +func GetConfigJWT() JwtConfig { + return jwtConfigData +} + +func GetConfigGameJWT() GameJwtConfig { + return gameJwtConfigData +} + +func GetConfigApp() AppConfig { + return appConfigData +} + +func GetConfigOss() OssConfig { + return ossConfigData +} + +func GetConfigAws() AwsConfig { + return awsConfigData +} + +func GetConfigGooglePay() GooglePayConfig { + return googlePayData +} + +func GetMode() string { + return mode +} + +func AppIsRelease() bool { + return GetMode() == RELEASE +} + +func AppIsLocal() bool { + return GetMode() == LOCAL +} + +func IsMaster() bool { + return master +} + +func GetOssCDN() string { + return ossConfigData.OSS_CDN +} + +func GetRongyunAppKey() string { + return rongyunData.RONG_CLOUD_APP_KEY +} + +func GetRongyunAppSecret() string { + return rongyunData.RONG_CLOUD_APP_SECRET +} + +func GetRongyunUrl() string { + return rongyunData.RONG_CLOUD_URL +} + +func GetTencentyunAppId() int { + return tencentyunData.TENCENTYUN_APP_ID +} + +func GetTencentyunKey() string { + return tencentyunData.TENCENTYUN_KEY +} + +func GetTxOverSeaAppId() int { + return tencentyunData.TX_OVERSEA_APP_ID +} + +func GetTxOverSeaAppKey() string { + return tencentyunData.TX_OVERSEA_KEY +} + +func GetEmasRegionId() string { + return emasData.REGION_ID +} + +func GetEmasAccessKeyId() string { + return emasData.ACCESS_KEY_ID +} + +func GetEmasAccessKeySecret() string { + return emasData.ACCESS_KEY_SECRET +} + +func GetEmasAndroidAppKey() string { + return emasData.ANDROID_APP_KEY +} + +func GetEmasIosAppKey() string { + return emasData.IOS_APP_KEY +} + +func GetEmasApns() string { + return emasData.APNS +} + +func GetAgoraAppId() string { + return agora.APP_ID +} + +func GetAgoraAppCertificate() string { + return agora.APP_CERTIFICATE +} + +func GetAgoraCustomerKey() string { + return agora.CUSTOMER_KEY +} + +func GetAgoraCustomerSecret() string { + return agora.CUSTOMER_SECRET +} + +func GetMatchConfig() *MatchConfig { + return &matchData +} + +func GetOnlineConfig() *OnlineConfig { + return &onlineData +} + +func GetSessionConfig() SessionConfig { + return sessionData +} + +func GetVideoConfig() VideoConfig { + return videoData +} + +func GetBeanConfig() BeanConfig { + return beanData +} + +func GetH5Config() H5Config { + return h5Data +} + +func GetGroupImConfig() GroupImConfig { + return groupImData +} + +func GetGradeConfig() GradeConfig { + return gradeData +} + +func GetLikeConfig() LikeConfig { + return likeData +} + +func GetApplePayConfig() ApplePayConfig { + return applePayData +} + +func GetRegisterConfig() RegisterConfig { + return registerData +} + +func GetBannerConfig() BannerConfig { + return bannerConfig +} + +func GetDiamondConfig() DiamondConfig { + return diamondConfig +} + +func GetLuckyWheelConfig() LuckWheelConfig { + return luckyWheelConfig +} + +func GetGroupCustomThemeConfig() GroupCustomThemeConfig { + return groupCustomThemeConfig +} + +func GetGiftConfig() GiftConfig { + return giftConfig +} + +func GetDailyConfig() DailyConfig { + return dailyConfig +} + +func GetFruitTycoonConfig() FruitTycoonConfig { + return fruitTycoonConfig +} + +func GetActivityConfig() ActivityConfig { + return activityConfig +} + +func GetCheckoutConfig() CheckoutConfig { + return checkoutConfig +} + +func GetRiskControlConfig() RiskControlConfig { + return riskControl +} + +func GetPayerMaxConfig() PayerMaxConfig { + return payerMaxConfig +} + +func GetSudConfig() SudConfig { + return sudConfig +} + +func GetUrlConfig() URLConfig { + return urlConfig +} + +func init() { + str, _ := os.Getwd() + mylogrus.MyLog.Info(str) + + envDir := ".env" + + //加载环境变量 + if err := godotenv.Load(envDir); err != nil { + mylogrus.MyLog.Fatalf("Error loading .env err:%v", err) + } + + //获取环境变量 + mode = os.Getenv("MODE") + var err error + master, _ = strconv.ParseBool(os.Getenv("MASTER")) + mylogrus.MyLog.Infof("My role is %t", master) + + iniDir := mode + ".ini" + if runtime.GOOS == "darwin" { // mac本地调试 + iniDir = "/var/log/hilo/" + iniDir + } + //根据环境变量获取具体的配置,实现多环境配置 + //var conf *ini.File + conf, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: true}, iniDir) + if err != nil { + mylogrus.MyLog.Fatal(err) + } + + //加载mysql的配置 + if err := conf.Section("DATABASE").MapTo(&mysqlConfigData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("DATABASECODE").MapTo(&mysqlCodeConfigData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("REDIS").MapTo(&redisConfigData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("JWT").MapTo(&jwtConfigData); err != nil { + mylogrus.MyLog.Fatal(err) + } + if err := conf.Section("GAMEJWT").MapTo(&gameJwtConfigData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("APP").MapTo(&appConfigData); err != nil { + mylogrus.MyLog.Fatal(err) + } else { + mylogrus.MyLog.Infof("APP: %+v", appConfigData) + } + + if err := conf.Section("OSS").MapTo(&ossConfigData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("AWS").MapTo(&awsConfigData); err != nil { + mylogrus.MyLog.Fatal(err) + } else { + if awsConfigData.CONFIDENCE <= 50 { + awsConfigData.CONFIDENCE = 80 + } + mylogrus.MyLog.Infof("AWS: %+v", awsConfigData) + } + + if err := conf.Section("RONGYUN").MapTo(&rongyunData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("TENCENTYUN").MapTo(&tencentyunData); err != nil { + mylogrus.MyLog.Fatal(err) + } else { + mylogrus.MyLog.Info("TENCENTYUN: ", tencentyunData) + } + + if err := conf.Section("EMAS").MapTo(&emasData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("AGORA").MapTo(&agora); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("MATCH").MapTo(&matchData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("ONLINE").MapTo(&onlineData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("SESSION").MapTo(&sessionData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("VIDEO").MapTo(&videoData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("BEAN").MapTo(&beanData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("H5").MapTo(&h5Data); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("GROUPIM").MapTo(&groupImData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("GRADE").MapTo(&gradeData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("LIKE").MapTo(&likeData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("APPLEPAY").MapTo(&applePayData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("REGISTER").MapTo(®isterData); err != nil { + mylogrus.MyLog.Fatal(err) + } + + if err := conf.Section("BANNER").MapTo(&bannerConfig); err != nil { + mylogrus.MyLog.Fatal(err) + } + if err := conf.Section("DIAMOND").MapTo(&diamondConfig); err != nil { + mylogrus.MyLog.Fatal(err) + } else { + if diamondConfig.NEW_USER_INVITE_AWARD <= 0 { + diamondConfig.NEW_USER_INVITE_AWARD = 5000 + } + } + if err := conf.Section("LUCKY_WHEEL").MapTo(&luckyWheelConfig); err != nil { + mylogrus.MyLog.Fatal(err) + } + if err := conf.Section("GROUP_CUSTOM_THEME").MapTo(&groupCustomThemeConfig); err != nil { + mylogrus.MyLog.Fatal(err) + } + if err := conf.Section("GIFT").MapTo(&giftConfig); err != nil { + mylogrus.MyLog.Fatal(err) + } + if err := conf.Section("DAILY").MapTo(&dailyConfig); err != nil { + mylogrus.MyLog.Fatal(err) + } + if err := conf.Section("CHECKOUT").MapTo(&checkoutConfig); err != nil { + mylogrus.MyLog.Fatal(err) + } + if err := conf.Section("PAYER_MAX").MapTo(&payerMaxConfig); err != nil { + mylogrus.MyLog.Fatal(err) + } + if err := conf.Section("FRUIT_TYCOON").MapTo(&fruitTycoonConfig); err != nil { + mylogrus.MyLog.Fatal(err) + } else { + // 防止未配置或配置错误 + if fruitTycoonConfig.BIG_WINNER_LOW <= 0 { + fruitTycoonConfig.BIG_WINNER_LOW = 10000 + } + if fruitTycoonConfig.BIG_WINNER_HIGH <= 0 { + fruitTycoonConfig.BIG_WINNER_HIGH = 20000 + } + if fruitTycoonConfig.POOL_RATIO <= 0 || fruitTycoonConfig.POOL_RATIO > 100 { + fruitTycoonConfig.POOL_RATIO = 20 + } + if fruitTycoonConfig.WATERMELON_RATIO <= 0 || fruitTycoonConfig.WATERMELON_RATIO > 100 { + fruitTycoonConfig.WATERMELON_RATIO = 70 + } + mylogrus.MyLog.Infof("FRUIT_TYCOON: %+v", fruitTycoonConfig) + } + + if err := conf.Section("ACTIVITY").MapTo(&activityConfig); err != nil { + mylogrus.MyLog.Fatal(err) + } else { + // 防止未配置或配置错误 + if activityConfig.COUNTRY_STAR_POOL_RATIO <= 0 { + activityConfig.COUNTRY_STAR_POOL_RATIO = 20 + } + if activityConfig.COUNTRY_STAR_ORDINARY_RATIO <= 0 { + activityConfig.COUNTRY_STAR_ORDINARY_RATIO = 20 + } + mylogrus.MyLog.Infof("ACTIVITY: %+v", activityConfig) + } + + if err := conf.Section("RISK_CONTROL").MapTo(&riskControl); err != nil { + mylogrus.MyLog.Fatal(err) + } else { + if riskControl.USER_QPS_LIMIT <= 0 { + riskControl.USER_QPS_LIMIT = 128 + } + if riskControl.USER_URL_QPS_LIMIT <= 0 { + riskControl.USER_URL_QPS_LIMIT = 64 + } + mylogrus.MyLog.Infof("RISK_CONTROL: %+v", riskControl) + } + if err := conf.Section("SUD").MapTo(&sudConfig); err != nil { + mylogrus.MyLog.Fatal(err) + } + if err := conf.Section("URL").MapTo(&urlConfig); err != nil { + mylogrus.MyLog.Fatal(err) + } +} diff --git a/resource/consul/consul.go b/resource/consul/consul.go new file mode 100644 index 0000000000000000000000000000000000000000..a2a720c5a31aef1dbbc634815e57fb3120f0ac83 --- /dev/null +++ b/resource/consul/consul.go @@ -0,0 +1,112 @@ +package consul + +import ( + "fmt" + "git.hilo.cn/hilo-common/mylogrus" + "git.hilo.cn/hilo-common/utils" + "github.com/hashicorp/consul/api" + "net/http" + "os" + "time" +) + +const ( + RegisterName = "hiloFinance" + RegisterTag = "金融中心" +) + +// 异步注册到consul +func RegisterToConsul(port int) { + go register(port, false) + go selfCheck(port) +} + +func consulCheck(w http.ResponseWriter, r *http.Request) { + _, _ = fmt.Fprintln(w, "consulCheck") +} + +func register(port int, retry bool) { + client, err := api.NewClient(api.DefaultConfig()) //非默认情况下需要设置实际的参数 + if err != nil { + mylogrus.MyLog.Errorf("RegisterToConsul Fail:%v", err) + return + } + if client == nil { + mylogrus.MyLog.Errorf("Fail to get consul client.") + return + } + mylogrus.MyLog.Infof("RegisterToConsul:%v-%v", client, err) + checkPort := port + 1000 + registration := new(api.AgentServiceRegistration) + hostName, _ := os.Hostname() + registration.ID = fmt.Sprintf("%s-%s", RegisterName, hostName) + registration.Name = RegisterName + registration.Port = port + registration.Tags = []string{RegisterTag} + + myIp, myNodeName := "", "" + if localIp, err := utils.GetClientIp(); err != nil { + mylogrus.MyLog.Fatalln("local ip not found", err) + } else { + myIp = localIp + } + mylogrus.MyLog.Infof("My ip is %s, nodeName: %s\n", myIp, myNodeName) + + registration.Address = myIp + registration.Check = &api.AgentServiceCheck{ + HTTP: fmt.Sprintf("http://localhost:%d%s", checkPort, "/check"), + Timeout: "3s", + Interval: "5s", + DeregisterCriticalServiceAfter: "30s", //check失败后30秒删除本服务 + } + err = client.Agent().ServiceRegister(registration) + if err != nil { + mylogrus.MyLog.Errorf("register server error :%v ", err) + return + } + if !retry { + http.HandleFunc("/check", consulCheck) + if err = http.ListenAndServe(fmt.Sprintf(":%d", checkPort), nil); err != nil { + mylogrus.MyLog.Warnf("check server error :%v ", err) + return + } + } +} + +// 自愈检查 +// 启动后每一分钟检查一次 +// 首次启动不执行 +func selfCheck(port int) { + ticker := time.NewTicker(time.Minute) + defer ticker.Stop() + for { + select { + case <-ticker.C: + client, err := api.NewClient(api.DefaultConfig()) //非默认情况下需要设置实际的参数 + if err != nil { + mylogrus.MyLog.Errorf("RegisterToConsul Fail:%v", err) + break + } + if client == nil { + mylogrus.MyLog.Errorf("Fail to get consul client.") + break + } + cataLog := client.Catalog() + if cataLog == nil { + mylogrus.MyLog.Errorf("No catalog.") + break + } + services, _, err := cataLog.Service(RegisterName, "", nil) + if err != nil { + mylogrus.MyLog.Errorf("%v", err) + break + } + if len(services) == 0 { + mylogrus.MyLog.Errorf("%s not found.", RegisterName) + go register(port, true) // 重新注册 + } else { + mylogrus.MyLog.Infof("%s check success %v", RegisterName, services[0]) + } + } + } +} diff --git a/resource/mysql/entity.go b/resource/mysql/entity.go new file mode 100644 index 0000000000000000000000000000000000000000..89823dedaa2813366ddc0465c0db48f9c7d9a97f --- /dev/null +++ b/resource/mysql/entity.go @@ -0,0 +1,116 @@ +package mysql + +import "time" + +type EntityI interface { + GetID() ID + //用于判断数据是否进行持久化 + IsLazyLoad() bool + //默认值为false true:代表要移除数据 + CheckDel() bool + //检查是否唯一键冲突,依旧更新 + CheckOnDuplicateKeyUPDATE() bool + //检查是否唯一键冲突,则不插入 + CheckOnDuplicateKeyIGNORE() bool + //更新乐观锁 默认值为false true:乐观锁更新 + CheckUpdateVersion() bool + //更新条件. + CheckUpdateCondition() bool + //获取版本号 + GetUpdateVersionBefore() uint + //更新情况 + GetUpdateCondition() string + //save 动作排除字段 + GetOmit() []string +} +type Entity struct { + ID ID `gorm:"primary_key"` + CreatedTime time.Time `gorm:"->"` + UpdatedTime time.Time `gorm:"->"` + lazyLoad bool `gorm:"-"` + del bool `gorm:"-"` + onDuplicateKeyUPDATE bool `gorm:"-"` + onDuplicateKeyIGNORE bool `gorm:"-"` + updateVersionFlag bool `gorm:"-"` + updateVersionBefore uint `gorm:"-"` + updateCondition string `gorm:"-"` + omit []string `gorm:"-"` //更新排除 + updateColumns map[string]interface{} `gorm:"-"` //更新字段 +} + +func (t *Entity) GetID() ID { + return t.ID +} + +func (t *Entity) IsLazyLoad() bool { + return t.lazyLoad +} + +func (t *Entity) SetLasyLoad() { + t.lazyLoad = true +} + +func (t *Entity) SetDel() { + t.del = true +} + +func (t *Entity) CheckDel() bool { + return t.del +} + +func (t *Entity) SetOnDuplicateKeyUPDATE() { + t.onDuplicateKeyUPDATE = true +} + +func (t *Entity) SetOnDuplicateKeyIGNORE() { + t.onDuplicateKeyIGNORE = true +} + +func (t *Entity) CheckOnDuplicateKeyUPDATE() bool { + return t.onDuplicateKeyUPDATE +} + +func (t *Entity) CheckOnDuplicateKeyIGNORE() bool { + return t.onDuplicateKeyIGNORE +} + +func (t *Entity) SetCheckUpdateVersionBefore(versionBefore uint) { + t.updateVersionBefore = versionBefore + t.updateVersionFlag = true +} + +func (t *Entity) SetCheckUpdateCondition(condition string) { + t.updateCondition = condition +} + +func (t *Entity) CheckUpdateVersion() bool { + return t.updateVersionFlag +} + +func (t *Entity) CheckUpdateCondition() bool { + return t.updateCondition != "" +} + +func (t *Entity) GetUpdateCondition() string { + return t.updateCondition +} + +func (t *Entity) GetUpdateVersionBefore() uint { + return t.updateVersionBefore +} + +func (t *Entity) GetOmit() []string { + return t.omit +} + +func (t *Entity) SetOmit(omit []string) { + t.omit = omit +} + +func (t *Entity) SetUpdateColumns(updateColumns map[string]interface{}) { + t.updateColumns = updateColumns +} + +func (t *Entity) GetUpdateColumns() map[string]interface{} { + return t.updateColumns +} diff --git a/resource/mysql/logger.go b/resource/mysql/logger.go new file mode 100644 index 0000000000000000000000000000000000000000..d15c2b5e040732504ef4e07f9ba06f0244653105 --- /dev/null +++ b/resource/mysql/logger.go @@ -0,0 +1,114 @@ +package mysql + +import ( + "context" + "fmt" + . "gorm.io/gorm/logger" + "gorm.io/gorm/utils" + "time" +) + +func MyNew(writer Writer, config Config) Interface { + var ( + infoStr = "%s[info] " + warnStr = "%s[warn] " + errStr = "%s[error] " + traceStr = "%s[%.3fms] [rows:%v] %s" + traceWarnStr = "%s %s[%.3fms] [rows:%v] %s" + traceErrStr = "%s %s[%.3fms] [rows:%v] %s" + ) + + //if config.Colorful { + // infoStr = Green + "%s\n" + Reset + Green + "[info] " + Reset + // warnStr = BlueBold + "%s\n" + Reset + Magenta + "[warn] " + Reset + // errStr = Magenta + "%s\n" + Reset + Red + "[error] " + Reset + // traceStr = Green + "%s\n" + Reset + Yellow + "[%.3fms] " + BlueBold + "[rows:%v]" + Reset + " %s" + // traceWarnStr = Green + "%s " + Yellow + "%s\n" + Reset + RedBold + "[%.3fms] " + Yellow + "[rows:%v]" + Magenta + " %s" + Reset + // traceErrStr = RedBold + "%s " + MagentaBold + "%s\n" + Reset + Yellow + "[%.3fms] " + BlueBold + "[rows:%v]" + Reset + " %s" + //} + myTraceStr := " traceId:%v userId:%v" + infoStr += myTraceStr + warnStr += myTraceStr + errStr += myTraceStr + traceStr += myTraceStr + traceWarnStr += myTraceStr + traceErrStr += myTraceStr + + return &myLogger{ + Writer: writer, + Config: config, + infoStr: infoStr, + warnStr: warnStr, + errStr: errStr, + traceStr: traceStr, + traceWarnStr: traceWarnStr, + traceErrStr: traceErrStr, + } +} + +type myLogger struct { + Writer + Config + infoStr, warnStr, errStr string + traceStr, traceErrStr, traceWarnStr string +} + +// LogMode log mode +func (l *myLogger) LogMode(level LogLevel) Interface { + newlogger := *l + newlogger.LogLevel = level + return &newlogger +} + +// Info print info +func (l myLogger) Info(ctx context.Context, msg string, data ...interface{}) { + if l.LogLevel >= Info { + l.Printf(l.infoStr+msg, append([]interface{}{utils.FileWithLineNum()}, data...)...) + } +} + +// Warn print warn messages +func (l myLogger) Warn(ctx context.Context, msg string, data ...interface{}) { + if l.LogLevel >= Warn { + l.Printf(l.warnStr+msg, append([]interface{}{utils.FileWithLineNum()}, data...)...) + } +} + +// Error print error messages +func (l myLogger) Error(ctx context.Context, msg string, data ...interface{}) { + if l.LogLevel >= Error { + l.Printf(l.errStr+msg, append([]interface{}{utils.FileWithLineNum()}, data...)...) + } +} + +// Trace print sql message +func (l myLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error) { + traceId, userId := ctx.Value("traceId"), ctx.Value("userId") + if l.LogLevel > Silent { + elapsed := time.Since(begin) + switch { + case err != nil && l.LogLevel >= Error: + sql, rows := fc() + if rows == -1 { + l.Printf(l.traceErrStr, utils.FileWithLineNum(), err, float64(elapsed.Nanoseconds())/1e6, "-", sql, traceId, userId) + } else { + l.Printf(l.traceErrStr, utils.FileWithLineNum(), err, float64(elapsed.Nanoseconds())/1e6, rows, sql, traceId, userId) + } + case elapsed > l.SlowThreshold && l.SlowThreshold != 0 && l.LogLevel >= Warn: + sql, rows := fc() + slowLog := fmt.Sprintf("SLOW SQL >= %v", l.SlowThreshold) + if rows == -1 { + l.Printf(l.traceWarnStr, utils.FileWithLineNum(), slowLog, float64(elapsed.Nanoseconds())/1e6, "-", sql, traceId, userId) + } else { + l.Printf(l.traceWarnStr, utils.FileWithLineNum(), slowLog, float64(elapsed.Nanoseconds())/1e6, rows, sql, traceId, userId) + } + case l.LogLevel == Info: + sql, rows := fc() + if rows == -1 { + l.Printf(l.traceStr, utils.FileWithLineNum(), float64(elapsed.Nanoseconds())/1e6, "-", sql, traceId, userId) + } else { + l.Printf(l.traceStr, utils.FileWithLineNum(), float64(elapsed.Nanoseconds())/1e6, rows, sql, traceId, userId) + } + } + } +} diff --git a/resource/mysql/mysql.go b/resource/mysql/mysql.go new file mode 100644 index 0000000000000000000000000000000000000000..d80d80fc9e2cb06c00098c51284e2af405b808ef --- /dev/null +++ b/resource/mysql/mysql.go @@ -0,0 +1,57 @@ +package mysql + +import ( + "fmt" + "git.hilo.cn/hilo-common/mylogrus" + "git.hilo.cn/hilo-common/resource/config" + _ "github.com/go-sql-driver/mysql" //加载mysql驱动 + _ "github.com/joho/godotenv/autoload" + "gorm.io/driver/mysql" + "gorm.io/gorm" + "gorm.io/gorm/logger" + "gorm.io/gorm/schema" + "log" + "net/url" + "time" +) + +var Db *gorm.DB + +func init() { + var err error + mysqlConfigData := config.GetConfigMysql() + options := "?charset=utf8mb4&parseTime=True&loc=Local&time_zone=" + url.QueryEscape("'+8:00'") + dsn := "" + mysqlConfigData.MYSQL_USERNAME + ":" + mysqlConfigData.MYSQL_PASSWORD + "@(" + mysqlConfigData.MYSQL_HOST + ")/" + mysqlConfigData.MYSQL_DB + options + + sqlLogger := logger.Default.LogMode(logger.Info) + if file := mylogrus.GetSqlLog(); file != nil { + //sqlLogger = logger.New(log.New(file, "\r\n", log.Ldate|log.Lmicroseconds), logger.Config{ + sqlLogger = MyNew(log.New(file, "", log.Ldate|log.Lmicroseconds), logger.Config{ + SlowThreshold: 200 * time.Millisecond, + LogLevel: logger.Info, + Colorful: false, + }) + } + + Db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{ + Logger: sqlLogger, + NamingStrategy: schema.NamingStrategy{ + SingularTable: true, + }, + }) + if err != nil { + log.Fatalf("mysql connect error %v", err) + } else { + log.Println("mysql connect success") + } + + if Db.Error != nil { + fmt.Printf("database error %v", Db.Error) + } + + if d, err := Db.DB(); err == nil { + d.SetConnMaxLifetime(time.Minute * 30) // 连接可复用的最大时间。 + d.SetMaxIdleConns(20) // 空闲连接数 + d.SetMaxOpenConns(20) // 最大连接数 + } +} diff --git a/resource/mysql/types.go b/resource/mysql/types.go new file mode 100644 index 0000000000000000000000000000000000000000..9e598d116bd91e24b07caeffb6a5c72b8b69de19 --- /dev/null +++ b/resource/mysql/types.go @@ -0,0 +1,93 @@ +package mysql + +import "strconv" + +/** +基于PDM,建立统计的数据domain结构。注意,不要选择0, 因为go的int默认值为0 +*/ + +//主键ID +type ID = uint64 + +//性别 +type Sex = uint8 + +//加减 +type AddReduce = uint8 + +//拥有 +type YesNo = uint8 + +//短描述 +type Str = string + +//时间戳 +type Time = int64 + +//状态 +type UserYesNo = uint8 + +//平台 +type Platform = uint8 + +//多枚举类型 +type Type = uint8 + +//数量 +type Num = uint32 + +//时间戳 +type Timestamp = uint64 + +//排序 +type Index = uint16 + +//数量,并且用到-1作为特殊标记位 +type NumAll = int + +//开启关闭 +type OpenClose = uint8 + +//逻辑删除 +type LogicDel = uint8 + +//设备 +type Device = uint8 + +type PeriodType = uint8 + +type FinishYesNo = uint8 + +//性别 +const ( + MAN Sex = 1 + WOMAN Sex = 2 + EMPTY Sex = 0 +) + +//yes no +const ( + YES YesNo = 1 + NO YesNo = 2 +) + +const ( + OPEN OpenClose = 1 + CLOSE OpenClose = 2 +) + +//加,减 +const ( + ADD AddReduce = 1 + REDUCE AddReduce = 2 + SET AddReduce = 3 // set +) + +const ( + USER UserYesNo = 1 + NOUSER UserYesNo = 2 +) + +func TypeToString(t Type) string { + return strconv.Itoa(int(t)) +} diff --git a/resource/redisCli/redis.go b/resource/redisCli/redis.go new file mode 100644 index 0000000000000000000000000000000000000000..efb7455882c3e4cd4f1b38e4375e985ed1390d5f --- /dev/null +++ b/resource/redisCli/redis.go @@ -0,0 +1,33 @@ +package redisCli + +import ( + "context" + "git.hilo.cn/hilo-common/mylogrus" + "git.hilo.cn/hilo-common/resource/config" + "github.com/go-redis/redis/v8" +) + +var RedisClient *redis.Client + +func init() { + RedisClient = redis.NewClient(&redis.Options{ + Addr: config.GetConfigRedis().REDIS_HOST, + Password: config.GetConfigRedis().REDIS_PASSWORD, // no password set + DB: 0, // use default DB + PoolSize: 20, + MinIdleConns: 20, + }) + mylogrus.MyLog.Infoln(config.GetConfigRedis().REDIS_HOST) + mylogrus.MyLog.Infoln(config.GetConfigRedis().REDIS_PASSWORD) + pong, err := RedisClient.Ping(context.Background()).Result() + if err != nil { + mylogrus.MyLog.Warn(err) + mylogrus.MyLog.Fatal("redis db0 connect fail") + } else { + mylogrus.MyLog.Info("redis db0 connection success - ", pong) + } +} + +func GetRedis() *redis.Client { + return RedisClient +} diff --git a/utils/ip.go b/utils/ip.go new file mode 100644 index 0000000000000000000000000000000000000000..fcb58ea5af374b659ee8d6cd61916cfbcecb2b9e --- /dev/null +++ b/utils/ip.go @@ -0,0 +1,26 @@ +package utils + +import ( + "fmt" + "net" +) + +func GetClientIp() (string, error) { + addrs, err := net.InterfaceAddrs() + + if err != nil { + return "", err + } + + for _, address := range addrs { + // 检查ip地址判断是否回环地址 + if ipNet, ok := address.(*net.IPNet); ok && ipNet.IP.IsGlobalUnicast() { + //if ipNet, ok := address.(*net.IPNet); ok && !ipNet.IP.IsLoopback() { + if ipNet.IP.To4() != nil { + return ipNet.IP.String(), nil + } + + } + } + return "", fmt.Errorf("can not find the client ip address") +}