├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── config ├── config.go └── system.json ├── go.mod ├── go.sum ├── logger └── logger.go ├── main.go ├── middleware ├── auth.go └── session.go ├── model ├── card.go ├── connect.go └── user.go ├── router └── router.go └── service ├── card ├── index.go ├── message.go ├── notice.go └── register.go ├── health.go └── user ├── bjutRegister.go ├── current.go ├── home.go ├── login.go ├── logout.go ├── register.go └── update.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # goland 15 | .idea 16 | 17 | # log 18 | *.log -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | ## v0.1.0 2019-11-15 3 | ### added 4 | - viper配置文件读取 5 | - mysql数据库连接池 6 | - logger日志模块 7 | - cookie用户登录状态管理 8 | - student模型的增删改查 9 | ## v0.2.0 2019-12-02 10 | ### added 11 | - 丢失一卡通的登记和展示 12 | - 给一卡通失主自动发短信通知 13 | - 通过配置文件选择gorm的模式 14 | ### changed 15 | - 用户系统修改为一张表 16 | ### fixed 17 | - 请求小美接口后挥手 18 | - bjutRegister通过学号来判断是否重复注册 19 | ### security 20 | - 修改密码时需要输入原密码 21 | ## v0.2.1 2019-12-16 22 | ### added 23 | - unique 字段显示的创建索引 24 | ### changed 25 | - gin v1.4.0 -> v1.5.0 26 | - 数据校验充分利用 validator tag 27 | - database合入model包中 28 | - 删除多余的err.error() 29 | ### fixed 30 | - sms请求url中random参数 31 | - sms返回值序列化的错误处理 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 YahuiAn 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Go-bjut 2 | # 项目规范 3 | ## git commit 4 | 一个 commit 尽可能只做一件事 5 | 1. added: 添加,一般在添加了新功能时使用 6 | 2. improved: 改进,一般在优化和改进代码时使用 7 | 3. refactored:重构,一般在优化代码结构和设计时使用 8 | 4. fixbug: 修复bug,一般在修复bug时使用 9 | ## 命名规范 10 | 1. 文件名统一用小驼峰法,例如:bjutRegister 11 | 2. 路由命名统一用"-",例如:bjut-register 12 | 3. 包名统一用小写字母,例如:student 13 | ## 版本约定 14 | 1. 采用主版本号.子版本号.修正版本号,比如:V1.2.1 15 | 2. 修正版本号一般在修复bug时使用 16 | 3. 子版本号一般在添加了新功能时使用 17 | 4. 主版本号一般是在积累了较多新功能且代码稳定时使用 18 | ## 更新日志 19 | 1. added: 添加的新功能 20 | 2. changed: 功能的变更 21 | 3. fixed: 修改的bug 22 | 4. security: 修改的关于安全的bug 23 | 5. removed: 删除的功能 24 | -------------------------------------------------------------------------------- /config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path" 7 | 8 | "github.com/YahuiAn/Go-bjut/model" 9 | 10 | "github.com/spf13/viper" 11 | ) 12 | 13 | func Init() { 14 | // 读取配置文件 15 | dir, _ := os.Getwd() 16 | configPath := path.Join(dir, "config") 17 | configName := "system" 18 | viper.SetConfigName(configName) // 指定配置文件的文件名称(不需要指定配置文件的扩展名) 19 | viper.AddConfigPath(configPath) // 设置配置文件的搜索目录 20 | if err := viper.ReadInConfig(); err != nil { 21 | panic(fmt.Sprintf("配置文件读取失败:%s", err)) 22 | } 23 | 24 | // 连接mysql数据库 25 | addr := viper.GetString("mysql.address") 26 | port := viper.GetString("mysql.port") 27 | user := viper.GetString("mysql.user") 28 | pwd := viper.GetString("mysql.password") 29 | db := viper.GetString("mysql.database") 30 | // "${user}:${pwd}@tcp(${addr}:${port})/${db}?charset=utf8&parseTime=True&loc=Local" 31 | connectStr := user + ":" + pwd + "@tcp(" + addr + ":" + port + ")/" + db + "?charset=utf8&parseTime=True&loc=Local" 32 | if err := model.ConnectMysql(connectStr); err != nil { 33 | panic(err) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /config/system.json: -------------------------------------------------------------------------------- 1 | { 2 | "mysql": { 3 | "address": "127.0.0.1", 4 | "port": "3306", 5 | "user": "root", 6 | "password": "122897", 7 | "database": "go_bjut" 8 | }, 9 | "gin": { 10 | "address": "127.0.0.1", 11 | "mode": "debug", 12 | "port": "8080" 13 | }, 14 | "session": { 15 | "secret": "session_secret" 16 | }, 17 | "tencent": { 18 | "card_sms": { 19 | "sdkappid": "1400299618", 20 | "appkey": "38510b84e92f38b2feaa4ae0e0f007ic", 21 | "sign": "智慧北工大", 22 | "tpl_id": 123654 23 | } 24 | }, 25 | "cron": { 26 | "sms": "1h" 27 | } 28 | } -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/YahuiAn/Go-bjut 2 | 3 | go 1.13 4 | 5 | require ( 6 | github.com/gin-contrib/sessions v0.0.1 7 | github.com/gin-gonic/gin v1.5.0 8 | github.com/jinzhu/gorm v1.9.11 9 | github.com/robfig/cron v1.2.0 10 | github.com/spf13/viper v1.5.0 11 | golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c 12 | ) 13 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 3 | cloud.google.com/go v0.37.4 h1:glPeL3BQJsbF6aIIYfZizMwc5LTYz250bDMjttbBGAU= 4 | cloud.google.com/go v0.37.4/go.mod h1:NHPJ89PdicEuT9hdPXMROBD91xc5uRDxsMtSB16k7hw= 5 | github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= 6 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 7 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= 8 | github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= 9 | github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= 10 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 11 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 12 | github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= 13 | github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= 14 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 15 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 16 | github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw= 17 | github.com/bradfitz/gomemcache v0.0.0-20190329173943-551aad21a668/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA= 18 | github.com/bradleypeabody/gorilla-sessions-memcache v0.0.0-20181103040241-659414f458e1/go.mod h1:dkChI7Tbtx7H1Tj7TqGSZMOeGpMP5gLHtjroHd4agiI= 19 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= 20 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 21 | github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= 22 | github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= 23 | github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= 24 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= 25 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= 26 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 27 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 28 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 29 | github.com/denisenkom/go-mssqldb v0.0.0-20190515213511-eb9f6a1743f3 h1:tkum0XDgfR0jcVVXuTsYv/erY2NnEDqwRojbxR1rBYA= 30 | github.com/denisenkom/go-mssqldb v0.0.0-20190515213511-eb9f6a1743f3/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM= 31 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 32 | github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= 33 | github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= 34 | github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= 35 | github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= 36 | github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y= 37 | github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= 38 | github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= 39 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 40 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 41 | github.com/gin-contrib/sessions v0.0.1 h1:xr9V/u3ERQnkugKSY/u36cNnC4US4bHJpdxcB6eIZLk= 42 | github.com/gin-contrib/sessions v0.0.1/go.mod h1:iziXm/6pvTtf7og1uxT499sel4h3S9DfwsrhNZ+REXM= 43 | github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 h1:t8FVkw33L+wilf2QiWkw0UV77qRpcH/JHPKGpKa2E8g= 44 | github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= 45 | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= 46 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 47 | github.com/gin-gonic/gin v1.4.0 h1:3tMoCCfM7ppqsR0ptz/wi1impNpT7/9wQtMZ8lr1mCQ= 48 | github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM= 49 | github.com/gin-gonic/gin v1.5.0 h1:fi+bqFAx/oLK54somfCtEZs9HeH1LHVoEPUgARpTqyc= 50 | github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do= 51 | github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= 52 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 53 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 54 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 55 | github.com/go-playground/locales v0.12.1 h1:2FITxuFt/xuCNP1Acdhv62OzaCiviiE4kotfhkmOqEc= 56 | github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= 57 | github.com/go-playground/universal-translator v0.16.0 h1:X++omBR/4cE2MNg91AoC3rmGrCjJ8eAeUP/K/EKx4DM= 58 | github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= 59 | github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= 60 | github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= 61 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 62 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 63 | github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 64 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= 65 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 66 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 67 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 68 | github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 69 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 70 | github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= 71 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 72 | github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= 73 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 74 | github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 75 | github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= 76 | github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 77 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 78 | github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= 79 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 80 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 81 | github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= 82 | github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 83 | github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= 84 | github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8= 85 | github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= 86 | github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= 87 | github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= 88 | github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= 89 | github.com/gorilla/sessions v1.1.1/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w= 90 | github.com/gorilla/sessions v1.1.3 h1:uXoZdcdA5XdXF3QzuSlheVRUvjl+1rKY7zBXL68L9RU= 91 | github.com/gorilla/sessions v1.1.3/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w= 92 | github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= 93 | github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= 94 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= 95 | github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= 96 | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 97 | github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= 98 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 99 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= 100 | github.com/jinzhu/gorm v1.9.11 h1:gaHGvE+UnWGlbWG4Y3FUwY1EcZ5n6S9WtqBA/uySMLE= 101 | github.com/jinzhu/gorm v1.9.11/go.mod h1:bu/pK8szGZ2puuErfU0RwyeNdsf3e6nCX/noXaVxkfw= 102 | github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= 103 | github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= 104 | github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M= 105 | github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= 106 | github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= 107 | github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= 108 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 109 | github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo= 110 | github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 111 | github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= 112 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 113 | github.com/kidstuff/mongostore v0.0.0-20181113001930-e650cd85ee4b/go.mod h1:g2nVr8KZVXJSS97Jo8pJ0jgq29P6H7dG0oplUA86MQw= 114 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= 115 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 116 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 117 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 118 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 119 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 120 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 121 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 122 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 123 | github.com/leodido/go-urn v1.1.0 h1:Sm1gr51B1kKyfD2BlRcLSiEkffoG96g6TPv6eRoEiB8= 124 | github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= 125 | github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4= 126 | github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= 127 | github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= 128 | github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 129 | github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc= 130 | github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 131 | github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg= 132 | github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= 133 | github.com/mattn/go-sqlite3 v1.11.0 h1:LDdKkqtYlom37fkvqs8rMPFKAMe8+SgjbwZ6ex1/A/Q= 134 | github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= 135 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 136 | github.com/memcachier/mc v2.0.1+incompatible/go.mod h1:7bkvFE61leUBvXz+yxsOnGBQSZpBSPIMUQSmmSHvuXc= 137 | github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= 138 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 139 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 140 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= 141 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 142 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 143 | github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= 144 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 145 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 146 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= 147 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 148 | github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 149 | github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= 150 | github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= 151 | github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= 152 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 153 | github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= 154 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 155 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 156 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 157 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 158 | github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= 159 | github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= 160 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 161 | github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 162 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 163 | github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= 164 | github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 165 | github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 166 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 167 | github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 168 | github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 169 | github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= 170 | github.com/quasoft/memstore v0.0.0-20180925164028-84a050167438/go.mod h1:wTPjTepVu7uJBYgZ0SdWHQlIas582j6cn2jgk4DDdlg= 171 | github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= 172 | github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ= 173 | github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k= 174 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= 175 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 176 | github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= 177 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 178 | github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= 179 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 180 | github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= 181 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= 182 | github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= 183 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= 184 | github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= 185 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 186 | github.com/spf13/viper v1.5.0 h1:GpsTwfsQ27oS/Aha/6d1oD7tpKIqWnOA6tgOX9HHkt4= 187 | github.com/spf13/viper v1.5.0/go.mod h1:AkYRkVJF8TkSG/xet6PzXX+l39KhhXa2pdqVSxnTcn4= 188 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 189 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 190 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 191 | github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= 192 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 193 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 194 | github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= 195 | github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= 196 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= 197 | github.com/ugorji/go v1.1.4 h1:j4s+tAvLfL3bZyefP2SEWmhBzmuIlH/eqNuPdFPgngw= 198 | github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= 199 | github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= 200 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= 201 | github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= 202 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= 203 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= 204 | github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= 205 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= 206 | go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= 207 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 208 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= 209 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= 210 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 211 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 212 | golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c h1:Vj5n4GlwjmQteupaxJ9+0FNOmBrHfq7vN4btdGoDZgI= 213 | golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 214 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 215 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 216 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 217 | golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 218 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 219 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 220 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 221 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 222 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 223 | golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 224 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 225 | golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 226 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 227 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 228 | golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 229 | golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco= 230 | golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 231 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 232 | golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 233 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 234 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 235 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 236 | golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 237 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 238 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 239 | golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 240 | golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 241 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 242 | golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 243 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 244 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= 245 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 246 | golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ= 247 | golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 248 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 249 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= 250 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 251 | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 252 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 253 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 254 | golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 255 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 256 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 257 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 258 | golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 259 | google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= 260 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 261 | google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= 262 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 263 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 264 | google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 265 | google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 266 | google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= 267 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 268 | google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 269 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 270 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 271 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 272 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 273 | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= 274 | gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= 275 | gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= 276 | gopkg.in/go-playground/validator.v8 v8.18.2 h1:lFB4DoMU6B626w8ny76MV7VX6W2VHct2GVOI3xgiMrQ= 277 | gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= 278 | gopkg.in/go-playground/validator.v9 v9.29.1 h1:SvGtYmN60a5CVKTOzMSyfzWDeZRxRuGvRQyEAKbw1xc= 279 | gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= 280 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= 281 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= 282 | gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= 283 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 284 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 285 | gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= 286 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 287 | honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 288 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 289 | honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 290 | -------------------------------------------------------------------------------- /logger/logger.go: -------------------------------------------------------------------------------- 1 | package logger 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "log" 7 | "os" 8 | "path" 9 | ) 10 | 11 | // 供全局调用的不同日志级别 12 | var ( 13 | Error *log.Logger 14 | Warning *log.Logger 15 | Info *log.Logger 16 | Debug *log.Logger 17 | ) 18 | 19 | func init() { 20 | dir, _ := os.Getwd() 21 | systemLogPath := path.Join(dir, "logger", "system.log") 22 | systemLogFile, err := os.OpenFile(systemLogPath, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0600) 23 | if err != nil { 24 | panic(fmt.Sprintf("systemLogFile加载失败:%s", err)) 25 | } 26 | 27 | // 设置日志输出位置和格式 28 | Error = log.New(io.MultiWriter(systemLogFile, os.Stderr), "[Error] ", log.Ldate|log.Lmicroseconds|log.Lshortfile) 29 | Warning = log.New(io.MultiWriter(systemLogFile, os.Stderr), "[Warning] ", log.Ldate|log.Lmicroseconds|log.Lshortfile) 30 | Info = log.New(io.MultiWriter(systemLogFile, os.Stderr), "[Info] ", log.Ldate|log.Lmicroseconds|log.Lshortfile) 31 | Debug = log.New(io.MultiWriter(systemLogFile, os.Stderr), "[Debug] ", log.Ldate|log.Lmicroseconds|log.Lshortfile) 32 | } 33 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/YahuiAn/Go-bjut/service/card" 7 | 8 | "github.com/YahuiAn/Go-bjut/config" 9 | "github.com/YahuiAn/Go-bjut/router" 10 | "github.com/robfig/cron" 11 | 12 | _ "github.com/jinzhu/gorm/dialects/mysql" 13 | "github.com/spf13/viper" 14 | ) 15 | 16 | func main() { 17 | // 初始化配置文件 18 | config.Init() 19 | 20 | // 加载路由 21 | r := router.NewRouter() 22 | 23 | // 启动定时任务 24 | smsTime := viper.GetString("cron.sms") 25 | spec := "@every " + smsTime 26 | c := cron.New() 27 | if err := c.AddFunc(spec, card.Notice); err != nil { 28 | panic(err) 29 | } 30 | c.Start() 31 | 32 | // 启动项目 33 | addr := viper.GetString("gin.address") 34 | port := viper.GetString("gin.port") 35 | if err := r.Run(addr + ":" + port); err != nil { 36 | panic(fmt.Sprintf("gin启动失败:%s", err)) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /middleware/auth.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gin-contrib/sessions" 7 | 8 | "github.com/gin-gonic/gin" 9 | ) 10 | 11 | // AuthRequired 需要登录 12 | func AuthRequired() gin.HandlerFunc { 13 | return func(c *gin.Context) { 14 | session := sessions.Default(c) 15 | uid := session.Get("user_id") 16 | if uid != nil { 17 | c.Next() 18 | return 19 | } 20 | c.JSON(http.StatusUnauthorized, gin.H{"msg": "请先登陆"}) 21 | c.Abort() 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /middleware/session.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "github.com/gin-contrib/sessions" 5 | "github.com/gin-contrib/sessions/cookie" 6 | "github.com/gin-gonic/gin" 7 | ) 8 | 9 | // Session 初始化session 10 | func Session(secret string) gin.HandlerFunc { 11 | store := cookie.NewStore([]byte(secret)) // TODO 考虑以后将session存到redis中,或者用别的登录认证的方法,增强安全性 12 | // TODO Also set Secure: true if using SSL, you should though 13 | store.Options(sessions.Options{HttpOnly: true, MaxAge: 7 * 86400, Path: "/"}) 14 | return sessions.Sessions("gin-session", store) 15 | } 16 | -------------------------------------------------------------------------------- /model/card.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/jinzhu/gorm" 4 | 5 | type Card struct { 6 | gorm.Model 7 | Registrant string 8 | RealName string 9 | Sex string 10 | College string 11 | Number string `gorm:"unique_index;not null"` 12 | Location string 13 | Status string 14 | } 15 | 16 | // Status字段的值 17 | const ( 18 | WaitingNotification = "等待通知" 19 | SuccessfulNotification = "成功通知" 20 | UnboundPhone = "未绑定电话" 21 | SmsAPIError = "短信API错误" 22 | ) 23 | -------------------------------------------------------------------------------- /model/connect.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | "github.com/spf13/viper" 8 | 9 | "github.com/jinzhu/gorm" 10 | ) 11 | 12 | // DB 数据库链接单例 13 | var DB *gorm.DB 14 | 15 | func ConnectMysql(connString string) error { 16 | db, err := gorm.Open("mysql", connString) 17 | if err != nil { 18 | return fmt.Errorf("数据库连接失败:%s", err) 19 | } 20 | //设置连接池 21 | //空闲 22 | db.DB().SetMaxIdleConns(50) 23 | //打开 24 | db.DB().SetMaxOpenConns(100) 25 | //超时 26 | db.DB().SetConnMaxLifetime(time.Second * 30) 27 | 28 | var mode bool 29 | if viper.GetString("gin.mode") == "debug" { 30 | mode = true 31 | } 32 | db.LogMode(mode) 33 | 34 | DB = db 35 | 36 | // 自动迁移表结构 37 | DB.AutoMigrate(&User{}) 38 | DB.AutoMigrate(&Card{}) 39 | 40 | return nil 41 | } 42 | -------------------------------------------------------------------------------- /model/user.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "github.com/YahuiAn/Go-bjut/logger" 5 | "github.com/jinzhu/gorm" 6 | ) 7 | 8 | type User struct { 9 | gorm.Model 10 | NickName string `gorm:"unique_index;not null"` 11 | Password string 12 | Email *string `gorm:"unique_index"` 13 | Telephone *string `gorm:"unique_index"` 14 | College string 15 | Major string 16 | ClassName string 17 | Number *string `gorm:"unique_index"` // 学号或职工号 18 | RealName string 19 | } 20 | 21 | func ExistUserByUniqueField(field, value string) (bool, error) { 22 | var user User 23 | err := DB.Select("id").Where(gorm.ToColumnName(field)+" = ?", value).First(&user).Error 24 | if err != nil && err != gorm.ErrRecordNotFound { 25 | logger.Error.Println(err) 26 | return false, err 27 | } 28 | if user.ID > 0 { 29 | logger.Info.Printf("field:%s,value:%s.\n", field, value) 30 | return true, nil 31 | } 32 | return false, nil 33 | } 34 | -------------------------------------------------------------------------------- /router/router.go: -------------------------------------------------------------------------------- 1 | package router 2 | 3 | import ( 4 | "github.com/YahuiAn/Go-bjut/middleware" 5 | "github.com/YahuiAn/Go-bjut/service" 6 | "github.com/YahuiAn/Go-bjut/service/card" 7 | "github.com/YahuiAn/Go-bjut/service/user" 8 | "github.com/gin-gonic/gin" 9 | "github.com/spf13/viper" 10 | ) 11 | 12 | func NewRouter() *gin.Engine { 13 | // 设置gin的工作模式 14 | gin.SetMode(viper.GetString("gin.mode")) 15 | 16 | r := gin.Default() 17 | 18 | // 中间件,顺序不能变 19 | r.Use(middleware.Session(viper.GetString("session.secret"))) 20 | 21 | // 路由 22 | v1 := r.Group("/api/v1") 23 | { 24 | // 健康检查 25 | v1.GET("ping", service.Ping) 26 | 27 | v1.POST("/user/register", user.Register) 28 | v1.POST("/user/bjut-register", user.BjutRegister) 29 | v1.POST("/user/login", user.Login) 30 | 31 | v1.GET("card/index", card.Index) 32 | 33 | // 需要登陆保护的 34 | auth := v1.Group("") 35 | auth.Use(middleware.AuthRequired()) 36 | { 37 | auth.GET("user/me", user.Home) 38 | auth.PUT("user/update", user.Update) 39 | auth.DELETE("user/logout", user.Logout) 40 | 41 | auth.POST("card/register", card.Register) 42 | } 43 | 44 | } 45 | 46 | return r 47 | } 48 | -------------------------------------------------------------------------------- /service/card/index.go: -------------------------------------------------------------------------------- 1 | package card 2 | 3 | import ( 4 | "net/http" 5 | "strconv" 6 | "time" 7 | 8 | "github.com/YahuiAn/Go-bjut/model" 9 | 10 | "github.com/YahuiAn/Go-bjut/logger" 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | type cardDisplay struct { 15 | RealName string 16 | Sex string 17 | College string 18 | Number string 19 | Location string 20 | Registrant string 21 | CreatedAt time.Time // TODO 返回前端可读性良好的时间格式 22 | Status string 23 | } 24 | 25 | func Index(c *gin.Context) { 26 | pageIndex, err := strconv.Atoi(c.Query("page")) // 页号 27 | if err != nil { 28 | logger.Error.Println(err) 29 | c.JSON(http.StatusBadRequest, gin.H{"msg": "不合法的页数"}) 30 | return 31 | } 32 | if pageIndex < 1 { 33 | c.JSON(http.StatusBadRequest, gin.H{"msg": "不合法的页数"}) 34 | return 35 | } 36 | pageSize := 10 // 每页的大小 37 | 38 | offset := (pageIndex - 1) * pageSize 39 | var cards []cardDisplay 40 | if err := model.DB.Table("cards").Offset(offset).Limit(pageSize).Order("created_at desc").Scan(&cards).Error; err != nil { 41 | logger.Error.Println(err) 42 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "数据库查询失败"}) 43 | return 44 | } 45 | 46 | var rows int // 表的总行数 47 | if err := model.DB.Table("cards").Count(&rows).Error; err != nil { 48 | logger.Error.Println(err) 49 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "数据库查询失败"}) 50 | return 51 | } 52 | 53 | pages := rows/pageSize + 1 // 总共有多少页 54 | 55 | c.JSON(http.StatusOK, gin.H{"msg": "查询成功", "data": cards, "pages": pages}) 56 | } 57 | -------------------------------------------------------------------------------- /service/card/message.go: -------------------------------------------------------------------------------- 1 | package card 2 | 3 | import ( 4 | "bytes" 5 | "crypto/sha256" 6 | "encoding/hex" 7 | "encoding/json" 8 | "io/ioutil" 9 | "math/rand" 10 | "net/http" 11 | "strconv" 12 | "time" 13 | 14 | "github.com/YahuiAn/Go-bjut/logger" 15 | 16 | "github.com/spf13/viper" 17 | ) 18 | 19 | // 一个特别好用的Json-to-Go的在线工具 20 | // https://mholt.github.io/json-to-go/ 21 | type telephone struct { 22 | Mobile string `json:"mobile"` 23 | Nationcode string `json:"nationcode"` 24 | } 25 | 26 | type payload struct { 27 | Ext string `json:"ext"` 28 | Extend string `json:"extend"` 29 | Params []string `json:"params"` 30 | Sig string `json:"sig"` 31 | Sign string `json:"sign"` 32 | Tel telephone `json:"tel"` 33 | Time int64 `json:"time"` 34 | TplID int `json:"tpl_id"` 35 | } 36 | 37 | type outcome struct { 38 | Result int `json:"result"` 39 | ErrMsg string `json:"errmsg"` 40 | Ext string `json:"ext"` 41 | Fee int `json:"fee"` 42 | Sid string `json:"sid"` 43 | } 44 | 45 | // 指定腾讯云模板单发短信 46 | // 本例模板内容:{Number},您的一卡通在{location},好心人为{registrant} 47 | func sendMessage(telNumber, number, location, registrant string) bool { 48 | // 构造url 49 | sdkappid := viper.GetString("tencent.card_sms.sdkappid") 50 | rand.Seed(time.Now().Unix()) 51 | random := strconv.Itoa(rand.Int())[0:5] 52 | url := "https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=" + sdkappid + "&random=" + random 53 | 54 | // 构造参数 55 | params := []string{number, location, registrant} 56 | appkey := viper.GetString("tencent.card_sms.appkey") 57 | nowTime := time.Now().Unix() 58 | sig := calculateSig(appkey, telNumber, random, nowTime) 59 | if sig == "" { 60 | logger.Error.Println("sig错误") 61 | return false 62 | } 63 | sign := viper.GetString("tencent.card_sms.sign") 64 | tel := telephone{ 65 | Mobile: telNumber, 66 | Nationcode: "86", // 中国大陆 67 | } 68 | tplId := viper.GetInt("tencent.card_sms.tpl_id") 69 | 70 | requestBody, _ := json.Marshal(payload{ 71 | Params: params, 72 | Sig: sig, 73 | Sign: sign, 74 | Tel: tel, 75 | Time: nowTime, 76 | TplID: tplId, 77 | }) 78 | 79 | resp, err := http.Post(url, "application/json", bytes.NewBuffer(requestBody)) 80 | if err != nil { 81 | logger.Error.Println(err) 82 | return false 83 | } 84 | defer resp.Body.Close() 85 | 86 | body, err := ioutil.ReadAll(resp.Body) 87 | if err != nil { 88 | logger.Error.Println(err) 89 | return false 90 | } 91 | 92 | var res outcome 93 | if err := json.Unmarshal(body, &res); err != nil { 94 | logger.Error.Printf("sms return body err,%s.\n", err) 95 | return false 96 | } 97 | 98 | if res.Result != 0 { 99 | logger.Error.Println(res) 100 | return false 101 | } 102 | return true 103 | } 104 | 105 | func calculateSig(appKey, telNumber, random string, time int64) string { 106 | h := sha256.New() 107 | plaintext := "appkey=" + appKey + "&random=" + random + "&time=" + strconv.FormatInt(time, 10) + "&mobile=" + telNumber 108 | if _, err := h.Write([]byte(plaintext)); err != nil { 109 | return "" 110 | } 111 | return hex.EncodeToString(h.Sum(nil)) 112 | } 113 | -------------------------------------------------------------------------------- /service/card/notice.go: -------------------------------------------------------------------------------- 1 | package card 2 | 3 | import ( 4 | "github.com/YahuiAn/Go-bjut/model" 5 | 6 | "github.com/YahuiAn/Go-bjut/logger" 7 | ) 8 | 9 | type smsInfo struct { 10 | ID uint 11 | Number string 12 | Telephone string 13 | Location string 14 | Registrant string 15 | } 16 | 17 | // TODO 如何防止破坏党多次发送短信(登记丢失卡片时进行筛选和判断) 18 | func Notice() { 19 | var info []smsInfo 20 | 21 | err := model.DB.Table("users as u"). 22 | Select("c.id, u.number, u.telephone, c.location, c.registrant"). 23 | Joins("join cards as c on u.number = c.number and c.status != ?", model.SuccessfulNotification). 24 | Scan(&info).Error 25 | 26 | if err != nil { 27 | logger.Error.Println(err) 28 | return 29 | } 30 | 31 | for i := range info { 32 | var temp model.Card 33 | 34 | if info[i].Telephone == "" { 35 | model.DB.Table("cards").First(&temp, info[i].ID).Update("status", model.UnboundPhone) 36 | continue 37 | } 38 | 39 | if !sendMessage(info[i].Telephone, info[i].Number, info[i].Location, info[i].Registrant) { 40 | model.DB.Table("cards").First(&temp, info[i].ID).Update("status", model.SmsAPIError) 41 | } else { 42 | model.DB.Table("cards").First(&temp, info[i].ID).Update("status", model.SuccessfulNotification) 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /service/card/register.go: -------------------------------------------------------------------------------- 1 | package card 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/YahuiAn/Go-bjut/service/user" 7 | 8 | "github.com/YahuiAn/Go-bjut/logger" 9 | "github.com/YahuiAn/Go-bjut/model" 10 | "github.com/gin-gonic/gin" 11 | ) 12 | 13 | type cardInfo struct { 14 | RealName string `binding:"max=20"` 15 | Sex string `binding:"omitempty,oneof=male female secrecy"` 16 | College string `binding:"max=20"` 17 | Number string `binding:"required,max=20"` 18 | Location string `binding:"required,max=50"` 19 | } 20 | 21 | // 用户捡到一卡通后,登记相关信息,并入库 22 | func Register(c *gin.Context) { 23 | var info cardInfo 24 | if err := c.ShouldBindJSON(&info); err != nil { 25 | logger.Error.Println("json信息错误", err) 26 | c.JSON(http.StatusBadRequest, gin.H{"msg": "json信息错误"}) // TODO 具体化错误信息 27 | return 28 | } 29 | 30 | who := user.CurrentUser(c) 31 | if who == (model.User{}) { 32 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "查询登录用户失败"}) 33 | return 34 | } 35 | 36 | count := 0 37 | err := model.DB.Model(&model.Card{}). 38 | Where("number = ? and status != ?", info.Number, model.SuccessfulNotification).Count(&count).Error 39 | if err != nil { 40 | logger.Error.Println(err) 41 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "数据库查询失败"}) 42 | return 43 | } 44 | if count > 0 { 45 | c.JSON(http.StatusBadRequest, gin.H{"msg": "该卡片已经登记,且还未发送通知,请不要重复登记"}) 46 | return 47 | } 48 | 49 | card := &model.Card{ 50 | Registrant: who.NickName, 51 | RealName: info.RealName, 52 | Sex: info.Sex, 53 | College: info.College, 54 | Number: info.Number, 55 | Location: info.Location, 56 | Status: model.WaitingNotification, 57 | } 58 | 59 | if err := model.DB.Create(&card).Error; err != nil { 60 | logger.Error.Println(err) 61 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "登记失败"}) 62 | return 63 | } 64 | c.JSON(http.StatusOK, gin.H{"msg": "登记成功"}) 65 | } 66 | -------------------------------------------------------------------------------- /service/health.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gin-gonic/gin" 7 | ) 8 | 9 | // 健康检查,看服务是否正常 10 | func Ping(c *gin.Context) { 11 | c.JSON(http.StatusOK, gin.H{"message": "pong"}) 12 | } 13 | -------------------------------------------------------------------------------- /service/user/bjutRegister.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "encoding/json" 5 | "io/ioutil" 6 | "net/http" 7 | "net/url" 8 | 9 | "github.com/YahuiAn/Go-bjut/model" 10 | "golang.org/x/crypto/bcrypt" 11 | 12 | "github.com/YahuiAn/Go-bjut/logger" 13 | "github.com/gin-gonic/gin" 14 | ) 15 | 16 | // 用于北工大学子的注册函数 17 | // 用户信息从“工大小美”项目的接口中获取 18 | // 返回的json数据格式如下 19 | /* 20 | { 21 | "class": "160701", 22 | "college": "信息学部", 23 | "major": "计算机科学与技术", 24 | "stuNum": "16010328", 25 | "sutName": "安亚辉" 26 | } 27 | */ 28 | // https://github.com/YahuiAn/BJUTservice 29 | // TODO 小美 该接口目前仅适用于北工大的本科生,考虑开发其他人群的接口,如老师,研究生等等 30 | 31 | const baseInfoAPI = "https://bjut1960.cn/baseinfo" 32 | 33 | type baseInfo struct { 34 | College string `json:"college"` 35 | Major string `json:"major"` 36 | ClassName string `json:"class"` 37 | Number string `json:"stuNum"` 38 | RealName string `json:"sutName"` // sutName这个锅该小美API来背 39 | } 40 | 41 | // 登录bjut正方教务系统所需信息 42 | type stuInfo struct { 43 | Number string `binding:"required,max=20"` 44 | Password string `binding:"required"` 45 | } 46 | 47 | func BjutRegister(c *gin.Context) { 48 | var loginInfo stuInfo 49 | if err := c.ShouldBindJSON(&loginInfo); err != nil { 50 | logger.Error.Println("json信息错误", err) 51 | c.JSON(http.StatusBadRequest, gin.H{"msg": "json信息错误"}) // TODO 具体化错误信息 52 | return 53 | } 54 | 55 | // 检查是否已经注册 56 | exist, err := model.ExistUserByUniqueField("number", loginInfo.Number) 57 | if err != nil { 58 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "数据库查询失败"}) 59 | return 60 | } 61 | if exist { 62 | c.JSON(http.StatusBadRequest, gin.H{"msg": "该学号已经被注册"}) 63 | return 64 | } 65 | 66 | // 向小美API发起HTTP POST请求 67 | data := url.Values{"xh": {loginInfo.Number}, "mm": {loginInfo.Password}} 68 | resp, err := http.PostForm(baseInfoAPI, data) 69 | if err != nil { 70 | logger.Error.Printf("%s请求失败,%s\n", baseInfoAPI, err) 71 | c.JSON(http.StatusInternalServerError, gin.H{"msg": baseInfoAPI + "接口请求失败"}) 72 | return 73 | } 74 | defer resp.Body.Close() 75 | if resp.Status != "200 OK" { 76 | logger.Error.Printf(resp.Status) 77 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "请检查教务账号密码是否有误"}) 78 | return 79 | } 80 | body, err := ioutil.ReadAll(resp.Body) 81 | if err != nil { 82 | logger.Error.Println(err) 83 | c.JSON(http.StatusInternalServerError, gin.H{"msg": baseInfoAPI + "接口请求失败"}) 84 | return 85 | } 86 | 87 | // 序列化数据 88 | var info baseInfo 89 | if err := json.Unmarshal(body, &info); err != nil { 90 | logger.Error.Println(err) 91 | c.JSON(http.StatusInternalServerError, gin.H{"msg": baseInfoAPI + "接口返回数据格式错误"}) 92 | return 93 | } 94 | 95 | // 使用教务管理系统的密码作为用户密码 96 | bytesPwd, err := bcrypt.GenerateFromPassword([]byte(loginInfo.Password), 10) 97 | if err != nil { 98 | logger.Error.Println("密码加密失败", err) 99 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "密码加密失败"}) 100 | return 101 | } 102 | 103 | user := model.User{ 104 | NickName: info.Number, 105 | Password: string(bytesPwd), 106 | College: info.College, 107 | Major: info.Major, 108 | ClassName: info.ClassName, 109 | Number: &info.Number, 110 | RealName: info.RealName, 111 | } 112 | 113 | // 插入数据 114 | err = model.DB.Create(&user).Error 115 | if err != nil { 116 | logger.Error.Println(err) 117 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "注册失败"}) 118 | return 119 | } 120 | 121 | logger.Info.Println("注册成功", info.Number) 122 | c.JSON(http.StatusOK, gin.H{"msg": "注册成功", "data": info.Number}) 123 | } 124 | -------------------------------------------------------------------------------- /service/user/current.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "github.com/YahuiAn/Go-bjut/logger" 5 | "github.com/YahuiAn/Go-bjut/model" 6 | "github.com/gin-contrib/sessions" 7 | "github.com/gin-gonic/gin" 8 | ) 9 | 10 | // 获取当前登录用户的信息 11 | func CurrentUser(c *gin.Context) model.User { 12 | session := sessions.Default(c) 13 | uid := session.Get("user_id") 14 | var user model.User 15 | if err := model.DB.First(&user, uid).Error; err != nil { 16 | logger.Error.Println(err) 17 | } 18 | return user 19 | } 20 | -------------------------------------------------------------------------------- /service/user/home.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "net/http" 5 | "time" 6 | 7 | "github.com/YahuiAn/Go-bjut/model" 8 | 9 | "github.com/YahuiAn/Go-bjut/logger" 10 | "github.com/gin-contrib/sessions" 11 | 12 | "github.com/gin-gonic/gin" 13 | ) 14 | 15 | // 给用户显示的信息 16 | type HomeInfo struct { 17 | ID uint 18 | CreatedAt time.Time 19 | NickName string 20 | Email string 21 | Telephone string 22 | College string 23 | Major string 24 | ClassName string 25 | Number string 26 | RealName string 27 | } 28 | 29 | // 用户主页 30 | func Home(c *gin.Context) { 31 | session := sessions.Default(c) 32 | uid := session.Get("user_id") 33 | 34 | var user HomeInfo 35 | 36 | if err := model.DB.First(&model.User{}, uid).Scan(&user).Error; err != nil { 37 | logger.Error.Println("数据库查询失败", err) 38 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "数据库查询失败"}) 39 | return 40 | } 41 | 42 | c.JSON(http.StatusOK, gin.H{"msg": user}) 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /service/user/login.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gin-contrib/sessions" 7 | 8 | "golang.org/x/crypto/bcrypt" 9 | 10 | "github.com/YahuiAn/Go-bjut/model" 11 | 12 | "github.com/YahuiAn/Go-bjut/logger" 13 | "github.com/gin-gonic/gin" 14 | ) 15 | 16 | type LoginInfo struct { 17 | Nickname string `binding:"required,min=2,max=30"` 18 | Password string `binding:"required,min=8,max=40"` 19 | } 20 | 21 | // 用户登录 22 | func Login(c *gin.Context) { 23 | var info LoginInfo 24 | if err := c.ShouldBindJSON(&info); err != nil { 25 | logger.Error.Println("json信息错误", err) 26 | c.JSON(http.StatusBadRequest, gin.H{"msg": "json信息错误"}) // TODO 具体化错误信息 27 | return 28 | } 29 | 30 | user := model.User{} 31 | if err := model.DB.Where("nick_name = ?", info.Nickname).First(&user).Error; err != nil { 32 | logger.Error.Println("用户名错误", err) 33 | c.JSON(http.StatusBadRequest, gin.H{"msg": "用户名错误"}) 34 | return 35 | } 36 | 37 | if err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(info.Password)); err != nil { 38 | logger.Error.Println("密码错误", err) 39 | c.JSON(http.StatusBadRequest, gin.H{"msg": "密码错误"}) 40 | return 41 | } 42 | 43 | // 设置session 44 | s := sessions.Default(c) 45 | s.Clear() 46 | s.Set("user_id", user.ID) 47 | if err := s.Save(); err != nil { 48 | logger.Error.Println("session设置错误", err) 49 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "session设置错误"}) 50 | return 51 | } 52 | 53 | logger.Info.Println("登录成功", user.NickName) 54 | c.JSON(http.StatusOK, gin.H{"msg": "登录成功", "data": user.NickName}) 55 | } 56 | -------------------------------------------------------------------------------- /service/user/logout.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/YahuiAn/Go-bjut/logger" 7 | "github.com/gin-contrib/sessions" 8 | "github.com/gin-gonic/gin" 9 | ) 10 | 11 | func Logout(c *gin.Context) { 12 | s := sessions.Default(c) 13 | s.Clear() 14 | if err := s.Save(); err != nil { 15 | logger.Error.Println("session设置错误", err) 16 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "session设置错误"}) 17 | return 18 | } 19 | 20 | c.JSON(http.StatusOK, gin.H{"msg": "退出成功"}) 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /service/user/register.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/YahuiAn/Go-bjut/logger" 7 | 8 | "golang.org/x/crypto/bcrypt" 9 | 10 | "github.com/YahuiAn/Go-bjut/model" 11 | 12 | "github.com/gin-gonic/gin" 13 | ) 14 | 15 | type RegisterInfo struct { 16 | NickName string `binding:"required,min=2,max=30"` 17 | Password string `binding:"required,min=8,max=40"` 18 | PwdConfirm string `binding:"eqfield=Password"` 19 | } 20 | 21 | // 用户注册 22 | func Register(c *gin.Context) { 23 | var info RegisterInfo 24 | if err := c.ShouldBindJSON(&info); err != nil { 25 | logger.Error.Println("json信息错误", err) 26 | c.JSON(http.StatusBadRequest, gin.H{"msg": "json信息错误"}) // TODO 具体化错误信息 27 | return 28 | } 29 | 30 | // 检查是否已经注册 31 | exist, err := model.ExistUserByUniqueField("nick_name", info.NickName) 32 | if err != nil { 33 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "数据库查询失败"}) 34 | return 35 | } 36 | if exist { 37 | c.JSON(http.StatusBadRequest, gin.H{"msg": "该昵称已被占用"}) 38 | return 39 | } 40 | 41 | bytesPwd, err := bcrypt.GenerateFromPassword([]byte(info.Password), 10) 42 | if err != nil { 43 | logger.Error.Println("密码加密失败", err) 44 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "密码加密失败"}) 45 | return 46 | } 47 | 48 | user := model.User{ 49 | NickName: info.NickName, 50 | Password: string(bytesPwd), 51 | } 52 | 53 | // 插入数据 54 | err = model.DB.Create(&user).Error 55 | if err != nil { 56 | logger.Error.Println("注册失败", err) 57 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "注册失败"}) 58 | return 59 | } 60 | 61 | logger.Info.Println("注册成功", info.NickName) 62 | c.JSON(http.StatusOK, gin.H{"msg": "注册成功", "data": user.NickName}) 63 | } 64 | 65 | // TODO 增加通过微信注册的方式 66 | -------------------------------------------------------------------------------- /service/user/update.go: -------------------------------------------------------------------------------- 1 | package user 2 | 3 | import ( 4 | "net/http" 5 | 6 | "golang.org/x/crypto/bcrypt" 7 | 8 | "github.com/YahuiAn/Go-bjut/model" 9 | 10 | "github.com/YahuiAn/Go-bjut/logger" 11 | "github.com/gin-gonic/gin" 12 | ) 13 | 14 | // 可供用户更新的数据 15 | type updateInfo struct { 16 | NickName string `binding:"omitempty,min=2,max=30"` 17 | Password string `binding:"omitempty,min=8,max=40"` 18 | NewPassword string `binding:"required_with=Password,omitempty,min=8,max=40"` 19 | PwdConfirm string `binding:"eqfield=NewPassword"` 20 | Email string 21 | Telephone string 22 | College string 23 | Major string 24 | ClassName string 25 | Number string 26 | RealName string 27 | } 28 | 29 | func Update(c *gin.Context) { 30 | var info updateInfo 31 | if err := c.ShouldBindJSON(&info); err != nil { 32 | logger.Error.Println("json信息错误", err) 33 | c.JSON(http.StatusBadRequest, gin.H{"msg": "json信息错误"}) // TODO 具体化错误信息 34 | return 35 | } 36 | 37 | user := CurrentUser(c) 38 | if user == (model.User{}) { 39 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "当前用户查询失败"}) 40 | return 41 | } 42 | 43 | if info.Password != "" { 44 | if err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(info.Password)); err != nil { 45 | logger.Error.Println(err) 46 | c.JSON(http.StatusBadRequest, gin.H{"msg": "原密码错误"}) 47 | return 48 | } 49 | 50 | bytesPwd, err := bcrypt.GenerateFromPassword([]byte(info.NewPassword), 10) 51 | if err != nil { 52 | logger.Error.Println("密码加密失败", err) 53 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "密码加密失败"}) 54 | return 55 | } 56 | info.Password = string(bytesPwd) 57 | } 58 | 59 | if info.NickName != "" { 60 | count := 0 61 | err := model.DB.Model(&model.User{}).Where("nick_name = ?", info.NickName).Count(&count).Error 62 | if err != nil { 63 | logger.Error.Println("数据库查询失败", err) 64 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "数据库查询失败"}) 65 | return 66 | } 67 | if count > 0 { 68 | logger.Error.Println("该昵称已被占用") 69 | c.JSON(http.StatusBadRequest, gin.H{"msg": "该昵称已被占用"}) 70 | return 71 | } 72 | } 73 | 74 | // TODO 对于Email,telephone信息更新时做安全检查和身份认证 75 | // Update multiple attributes with `struct`, will only update those changed & non blank fields 76 | // 更新用户信息 77 | if err := model.DB.Model(&user).Updates(info).Error; err != nil { 78 | logger.Error.Println(err) 79 | c.JSON(http.StatusInternalServerError, gin.H{"msg": "信息更新失败"}) 80 | return 81 | } 82 | 83 | c.JSON(http.StatusOK, gin.H{"msg": "信息更新成功"}) 84 | } 85 | --------------------------------------------------------------------------------