├── .github └── workflows │ └── master.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── app ├── api │ ├── a_auth.go │ ├── a_role.go │ ├── a_user.go │ └── dig.go ├── app.go ├── auth.go ├── dbs │ ├── dbs.go │ └── dig.go ├── interfaces │ ├── IAuthService.go │ ├── IDatabase.go │ ├── IRoleRepository.go │ ├── IRoleService.go │ ├── IUserRepository.go │ └── IUserService.go ├── middleware │ ├── auth.go │ ├── cache │ │ ├── cache.go │ │ └── gredis.go │ ├── jwt │ │ └── jwt.go │ ├── middleware.go │ └── roles │ │ └── roles.go ├── migration │ └── migration.go ├── mocks │ ├── mock_auth_service.go │ ├── mock_database.go │ ├── mock_role_repository.go │ ├── mock_role_service.go │ ├── mock_user_repository.go │ └── mock_user_service.go ├── models │ ├── base.go │ ├── m_role.go │ └── m_user.go ├── repositories │ ├── dig.go │ ├── r_role.go │ └── r_user.go ├── router │ ├── api.go │ └── docs.go ├── schema │ ├── sc_response.go │ ├── sc_role.go │ └── sc_user.go └── services │ ├── dig.go │ ├── s_auth.go │ ├── s_role.go │ └── s_user.go ├── cmd └── admin.go ├── config ├── config.go └── config.sample.yaml ├── deploy.sh ├── docker-compose.yml ├── docs ├── docs.go ├── swagger.json └── swagger.yaml ├── go.mod ├── go.sum ├── main.go ├── pkg ├── app │ └── request.go ├── errors │ ├── code.go │ ├── context.go │ ├── errors.go │ ├── message.go │ └── types.go ├── http │ ├── model.go │ └── wrapper │ │ └── gin.go ├── jwt │ ├── jwt_auth.go │ └── token.go └── utils │ ├── copy.go │ ├── generator.go │ ├── json.go │ ├── response.go │ ├── token.go │ └── validation.go ├── scripts ├── golint.sh ├── init.d │ └── postgres-init.sh └── startup.sh └── test ├── main_test.go └── user_repository_test.go /.github/workflows/master.yml: -------------------------------------------------------------------------------- 1 | name: master 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | 13 | env: 14 | GIN_MODE: release 15 | DATABASE__HOST: 127.0.0.1 16 | DATABASE__NAME: goadmin 17 | DATABASE__PORT: 5432 18 | DATABASE__ENV: native 19 | DATABASE__USER: postgres 20 | DATABASE__PASSWORD: 1234 21 | DATABASE__SSLMODE: disable 22 | 23 | services: 24 | postgres: 25 | image: postgres:latest 26 | env: 27 | POSTGRES_DB: goadmin 28 | POSTGRES_PASSWORD: 1234 29 | ports: 30 | - 5432:5432 31 | 32 | redis: 33 | image: redis:alpine 34 | ports: 35 | - 6379:6379 36 | 37 | steps: 38 | - uses: actions/checkout@v2 39 | 40 | - name: Set up Go 41 | uses: actions/setup-go@v2 42 | with: 43 | go-version: 1.15 44 | 45 | - name: Setup SSH Keys and known_hosts 46 | uses: webfactory/ssh-agent@v0.4.1 47 | with: 48 | ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} 49 | 50 | - name: Cache Go modules 51 | uses: actions/cache@preview 52 | with: 53 | path: ~/go/pkg/mod 54 | key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }} 55 | restore-keys: | 56 | ${{ runner.OS }}-build-${{ env.cache-name }}- 57 | ${{ runner.OS }}-build- 58 | ${{ runner.OS }}- 59 | 60 | - name: Go Test 61 | run: | 62 | make startup 63 | go test -timeout 9000s -a -v -coverpkg=./... ./test -coverprofile coverage.out -json > report.json 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Go template 3 | # Binaries for programs and plugins 4 | .idea 5 | *.exe 6 | *.exe~ 7 | *.dll 8 | *.so 9 | *.dylib 10 | 11 | # Test binary, built with `go test -c` 12 | *.test 13 | 14 | # Output of the go coverage tool, specifically when used with LiteIDE 15 | *.out 16 | 17 | # Dependency directories (remove the comment below to include it) 18 | # vendor/ 19 | 20 | ### JetBrains template 21 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 22 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 23 | 24 | # User-specific stuff 25 | .idea/**/workspace.xml 26 | .idea/**/tasks.xml 27 | .idea/**/usage.statistics.xml 28 | .idea/**/dictionaries 29 | .idea/**/shelf 30 | 31 | # Generated files 32 | .idea/**/contentModel.xml 33 | 34 | # Sensitive or high-churn files 35 | .idea/**/dataSources/ 36 | .idea/**/dataSources.ids 37 | .idea/**/dataSources.local.xml 38 | .idea/**/sqlDataSources.xml 39 | .idea/**/dynamic.xml 40 | .idea/**/uiDesigner.xml 41 | .idea/**/dbnavigator.xml 42 | 43 | # Gradle 44 | .idea/**/gradle.xml 45 | .idea/**/libraries 46 | 47 | # Gradle and Maven with auto-import 48 | # When using Gradle or Maven with auto-import, you should exclude module files, 49 | # since they will be recreated, and may cause churn. Uncomment if using 50 | # auto-import. 51 | # .idea/modules.xml 52 | # .idea/*.iml 53 | # .idea/modules 54 | # *.iml 55 | # *.ipr 56 | 57 | # CMake 58 | cmake-build-*/ 59 | 60 | # Mongo Explorer plugin 61 | .idea/**/mongoSettings.xml 62 | 63 | # File-based project format 64 | *.iws 65 | 66 | # IntelliJ 67 | out/ 68 | 69 | # mpeltonen/sbt-idea plugin 70 | .idea_modules/ 71 | 72 | # JIRA plugin 73 | atlassian-ide-plugin.xml 74 | 75 | # Cursive Clojure plugin 76 | .idea/replstate.xml 77 | 78 | # Crashlytics plugin (for Android Studio and IntelliJ) 79 | com_crashlytics_export_strings.xml 80 | crashlytics.properties 81 | crashlytics-build.properties 82 | fabric.properties 83 | 84 | # Editor-based Rest Client 85 | .idea/httpRequests 86 | 87 | # Android studio 3.1+ serialized cache file 88 | .idea/caches/build_file_checksums.ser 89 | 90 | .history 91 | 92 | config/config.yaml 93 | vendor/ 94 | .local/ 95 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:alpine as builder 2 | 3 | MAINTAINER quangdp 4 | 5 | WORKDIR /go/src/go-admin 6 | COPY . /go/src/go-admin 7 | RUN go build -o ./dist/go-admin 8 | 9 | FROM alpine:3.11.3 10 | RUN apk add --update ca-certificates 11 | RUN apk add --no-cache tzdata && \ 12 | cp -f /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime && \ 13 | apk del tzdata 14 | 15 | COPY ./config/config.yaml . 16 | COPY --from=builder /go/src/go-admin/dist/go-admin . 17 | EXPOSE 8888 18 | ENTRYPOINT ["./go-admin"] 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Đặng Phước Quang 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 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | startup: 2 | sh scripts/startup.sh 3 | 4 | test: startup 5 | go test -timeout 9000s -cover -a -v ./... 6 | 7 | admin: 8 | go run cmd/admin.go 9 | 10 | golint: 11 | sh scripts/golint.sh 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Go Admin 2 | [![Master](https://github.com/quangdangfit/go-admin/workflows/master/badge.svg)](https://github.com/quangdangfit/go-admin/actions) 3 | 4 | RBAC scaffolding based on Gin + Gorm + Casbin + Dig 5 | [Documentation here](https://pkg.go.dev/github.com/quangdangfit/go-admin). 6 | 7 | 8 | ## How to run 9 | 10 | ### Required 11 | 12 | - Postgres 13 | - Redis 14 | 15 | ### Config 16 | Simply run `make startup`, or run following commands step - by - step: 17 | - Copy config file: `cp config/config.sample.yaml config/config.yaml` 18 | 19 | 20 | - You should modify `config/config.yaml` 21 | 22 | ```yaml 23 | database: 24 | host: localhost 25 | port: 5432 26 | name: goadmin 27 | env: production 28 | user: postgres 29 | password: 1234 30 | sslmode: disable 31 | 32 | redis: 33 | enable: true 34 | host: localhost 35 | port: 6397 36 | password: 37 | database: 0 38 | 39 | cache: 40 | enable: true 41 | expiry_time: 3600 42 | ``` 43 | 44 | ### Migration - Create Admin User 45 | ```shell script 46 | $ make admin 47 | ``` 48 | 49 | ### Run 50 | ```shell script 51 | $ go run main.go 52 | ``` 53 | 54 | ### Run with docker 55 | ```shell script 56 | $ docker-compose up -d 57 | ``` 58 | 59 | ### Document 60 | * API document at: `http://localhost:8888/swagger/index.html` 61 | 62 | ### Structure 63 | ```shell 64 | ├── app 65 | │   ├── api # Handle request & response 66 | │   ├── dbs # Database Layer 67 | │   ├── middleware # Middlewares 68 | │   │   ├── cache # Cache middleware 69 | │   │   ├── jwt # JWT middleware 70 | │   │   └── roles # Authorization middleware 71 | │   ├── migration # Migration 72 | │   ├── mocks # Mocks 73 | │   ├── models # Models 74 | │   ├── repositories # Repository Layer 75 | │   │   └── impl # Implement repositories 76 | │   ├── router # Router api 77 | │   ├── schema # Schemas 78 | │   ├── services # Business Logic Layer 79 | │   │   └── impl # Implement services 80 | │   └── test # Test 81 | ├── cmd # Contains commands 82 | ├── config # Config files 83 | ├── docs # Swagger API document 84 | ├── pkg # Internal packages 85 | │   ├── app # App packages 86 | │   ├── errors # Errors packages 87 | │   ├── http # HTTP packages 88 | │   ├── jwt # JWT packages 89 | │   └── utils # Utils packages 90 | ├── scripts # Scripts 91 | ``` 92 | 93 | ### Techstack 94 | - RESTful API 95 | - Gorm 96 | - Swagger 97 | - Logging 98 | - Jwt-go 99 | - Gin 100 | - Graceful restart or stop (fvbock/endless) 101 | - Cron Job 102 | - Redis 103 | - Dig (Dependency Injection) 104 | -------------------------------------------------------------------------------- /app/api/a_auth.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "github.com/gin-gonic/gin" 5 | "github.com/quangdangfit/gocommon/logger" 6 | "github.com/quangdangfit/gocommon/validation" 7 | 8 | "github.com/quangdangfit/go-admin/app/interfaces" 9 | "github.com/quangdangfit/go-admin/app/schema" 10 | "github.com/quangdangfit/go-admin/pkg/errors" 11 | gohttp "github.com/quangdangfit/go-admin/pkg/http" 12 | ) 13 | 14 | // AuthAPI handle authentication api 15 | type AuthAPI struct { 16 | service interfaces.IAuthService 17 | } 18 | 19 | // NewAuthAPI return new AuthAPI 20 | func NewAuthAPI(service interfaces.IAuthService) *AuthAPI { 21 | return &AuthAPI{service: service} 22 | } 23 | 24 | // Login godoc 25 | // @Tags Auth 26 | // @Summary api login 27 | // @Description api login 28 | // @Accept json 29 | // @Produce json 30 | // @Param body body schema.LoginBodyParams true "Body" 31 | // @Success 200 {object} schema.BaseResponse 32 | // @Router /login [post] 33 | func (a *AuthAPI) Login(c *gin.Context) gohttp.Response { 34 | var params schema.LoginBodyParams 35 | if err := c.ShouldBindJSON(¶ms); err != nil { 36 | logger.Error(err.Error()) 37 | return gohttp.Response{ 38 | Error: errors.InvalidParams.New(), 39 | } 40 | } 41 | 42 | validator := validation.New() 43 | if err := validator.ValidateStruct(params); err != nil { 44 | return gohttp.Response{ 45 | Error: errors.InvalidParams.New(), 46 | } 47 | } 48 | 49 | tokenInfo, err := a.service.Login(c, ¶ms) 50 | if err != nil { 51 | logger.Error(err.Error()) 52 | return gohttp.Response{ 53 | Error: err, 54 | } 55 | } 56 | 57 | return gohttp.Response{ 58 | Error: errors.Success.New(), 59 | Data: tokenInfo, 60 | } 61 | } 62 | 63 | // Register godoc 64 | // @Tags Auth 65 | // @Summary api register 66 | // @Description api register 67 | // @Accept json 68 | // @Produce json 69 | // @Param body body schema.RegisterBodyParams true "Body" 70 | // @Success 200 {object} schema.BaseResponse 71 | // @Router /register [post] 72 | func (a *AuthAPI) Register(c *gin.Context) gohttp.Response { 73 | var params schema.RegisterBodyParams 74 | if err := c.ShouldBindJSON(¶ms); err != nil { 75 | logger.Error(err.Error()) 76 | return gohttp.Response{ 77 | Error: errors.InvalidParams.New(), 78 | } 79 | } 80 | 81 | validator := validation.New() 82 | if err := validator.ValidateStruct(params); err != nil { 83 | return gohttp.Response{ 84 | Error: errors.InvalidParams.New(), 85 | } 86 | } 87 | 88 | ctx := c.Request.Context() 89 | tokenInfo, err := a.service.Register(ctx, ¶ms) 90 | if err != nil { 91 | logger.Error(err.Error()) 92 | return gohttp.Response{ 93 | Error: err, 94 | } 95 | } 96 | 97 | return gohttp.Response{ 98 | Error: errors.Success.New(), 99 | Data: tokenInfo, 100 | } 101 | } 102 | 103 | // Refresh godoc 104 | // @Tags Auth 105 | // @Summary api refresh token 106 | // @Description api refresh token 107 | // @Accept json 108 | // @Produce json 109 | // @Param body body schema.RefreshBodyParams true "Body" 110 | // @Success 200 {object} schema.BaseResponse 111 | // @Router /refresh [post] 112 | func (a *AuthAPI) Refresh(c *gin.Context) gohttp.Response { 113 | var params schema.RefreshBodyParams 114 | if err := c.ShouldBindJSON(¶ms); err != nil { 115 | logger.Error(err.Error()) 116 | return gohttp.Response{ 117 | Error: errors.InvalidParams.New(), 118 | } 119 | } 120 | 121 | validator := validation.New() 122 | if err := validator.ValidateStruct(params); err != nil { 123 | return gohttp.Response{ 124 | Error: errors.InvalidParams.New(), 125 | } 126 | } 127 | 128 | ctx := c.Request.Context() 129 | tokenInfo, err := a.service.Refresh(ctx, ¶ms) 130 | if err != nil { 131 | logger.Error(err.Error()) 132 | return gohttp.Response{ 133 | Error: err, 134 | } 135 | } 136 | 137 | return gohttp.Response{ 138 | Error: errors.Success.New(), 139 | Data: tokenInfo, 140 | } 141 | } 142 | 143 | // Logout godoc 144 | // @Tags Auth 145 | // @Summary api logout 146 | // @Description api logout 147 | // @Accept json 148 | // @Produce json 149 | // @Security ApiKeyAuth 150 | // @Success 200 {object} schema.BaseResponse 151 | // @Router /logout [post] 152 | func (a *AuthAPI) Logout(c *gin.Context) gohttp.Response { 153 | err := a.service.Logout(c) 154 | if err != nil { 155 | logger.Error(err.Error()) 156 | return gohttp.Response{ 157 | Error: err, 158 | } 159 | } 160 | 161 | return gohttp.Response{ 162 | Error: errors.Success.New(), 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /app/api/a_role.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "github.com/gin-gonic/gin" 5 | "github.com/quangdangfit/gocommon/validation" 6 | 7 | "github.com/quangdangfit/go-admin/app/interfaces" 8 | "github.com/quangdangfit/go-admin/app/schema" 9 | "github.com/quangdangfit/go-admin/pkg/errors" 10 | gohttp "github.com/quangdangfit/go-admin/pkg/http" 11 | "github.com/quangdangfit/go-admin/pkg/utils" 12 | ) 13 | 14 | // RoleAPI handle role api 15 | type RoleAPI struct { 16 | service interfaces.IRoleService 17 | } 18 | 19 | // NewRoleAPI return new RoleAPI pointer 20 | func NewRoleAPI(service interfaces.IRoleService) *RoleAPI { 21 | return &RoleAPI{service: service} 22 | } 23 | 24 | // CreateRole create new role 25 | func (r *RoleAPI) CreateRole(c *gin.Context) gohttp.Response { 26 | var params schema.RoleBodyParams 27 | if err := c.ShouldBindJSON(¶ms); err != nil { 28 | return gohttp.Response{ 29 | Error: errors.InvalidParams.Newm(err.Error()), 30 | } 31 | } 32 | 33 | validator := validation.New() 34 | if err := validator.ValidateStruct(params); err != nil { 35 | return gohttp.Response{ 36 | Error: errors.InvalidParams.Newm(err.Error()), 37 | } 38 | } 39 | 40 | ctx := c.Request.Context() 41 | user, err := r.service.Create(ctx, ¶ms) 42 | if err != nil { 43 | return gohttp.Response{ 44 | Error: err, 45 | } 46 | } 47 | 48 | var res schema.Role 49 | err = utils.Copy(&res, &user) 50 | if err != nil { 51 | return gohttp.Response{ 52 | Error: err, 53 | } 54 | } 55 | 56 | return gohttp.Response{ 57 | Data: res, 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/api/a_user.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gin-gonic/gin" 7 | "github.com/jinzhu/copier" 8 | "github.com/quangdangfit/gocommon/logger" 9 | 10 | "github.com/quangdangfit/go-admin/app/interfaces" 11 | "github.com/quangdangfit/go-admin/app/schema" 12 | "github.com/quangdangfit/go-admin/pkg/errors" 13 | gohttp "github.com/quangdangfit/go-admin/pkg/http" 14 | "github.com/quangdangfit/go-admin/pkg/utils" 15 | ) 16 | 17 | // UserAPI handle user api 18 | type UserAPI struct { 19 | service interfaces.IUserService 20 | } 21 | 22 | // NewUserAPI return new UserAPI pointer 23 | func NewUserAPI(service interfaces.IUserService) *UserAPI { 24 | return &UserAPI{service: service} 25 | } 26 | 27 | // GetByID get user by id 28 | func (u *UserAPI) GetByID(c *gin.Context) { 29 | userID := c.Param("id") 30 | ctx := c.Request.Context() 31 | user, err := u.service.GetByID(ctx, userID) 32 | if err != nil { 33 | err = errors.Wrap(err, "API.GetByID") 34 | logger.Error("Failed to get user: ", err) 35 | c.JSON(http.StatusBadRequest, utils.PrepareResponse(nil, err.Error(), utils.ErrorGetDatabase)) 36 | return 37 | } 38 | 39 | var res schema.User 40 | copier.Copy(&res, &user) 41 | c.JSON(http.StatusOK, utils.PrepareResponse(res, "OK", "")) 42 | } 43 | 44 | // List user by query 45 | func (u *UserAPI) List(c *gin.Context) gohttp.Response { 46 | var queryParam schema.UserQueryParam 47 | if err := c.ShouldBindQuery(&queryParam); err != nil { 48 | logger.Error(err.Error()) 49 | return gohttp.Response{ 50 | Error: errors.InvalidParams.New(), 51 | } 52 | } 53 | 54 | user, err := u.service.List(c, &queryParam) 55 | if err != nil { 56 | logger.Error(err.Error()) 57 | return gohttp.Response{ 58 | Error: err, 59 | } 60 | } 61 | 62 | var res []schema.User 63 | copier.Copy(&res, &user) 64 | return gohttp.Response{ 65 | Error: errors.Success.New(), 66 | Data: res, 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/api/dig.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "go.uber.org/dig" 5 | ) 6 | 7 | // Inject apis 8 | func Inject(container *dig.Container) error { 9 | _ = container.Provide(NewAuthAPI) 10 | _ = container.Provide(NewUserAPI) 11 | _ = container.Provide(NewRoleAPI) 12 | return nil 13 | } 14 | -------------------------------------------------------------------------------- /app/app.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "github.com/gin-gonic/gin" 5 | "github.com/quangdangfit/gocommon/logger" 6 | "go.uber.org/dig" 7 | 8 | "github.com/quangdangfit/go-admin/app/api" 9 | "github.com/quangdangfit/go-admin/app/dbs" 10 | "github.com/quangdangfit/go-admin/app/repositories" 11 | "github.com/quangdangfit/go-admin/app/router" 12 | "github.com/quangdangfit/go-admin/app/services" 13 | "github.com/quangdangfit/go-admin/pkg/jwt" 14 | ) 15 | 16 | // BuildContainer build dig container 17 | func BuildContainer() *dig.Container { 18 | container := dig.New() 19 | 20 | auth, err := InitAuth() 21 | _ = container.Provide(func() jwt.IJWTAuth { 22 | return auth 23 | }) 24 | 25 | // Inject database 26 | err = dbs.Inject(container) 27 | if err != nil { 28 | logger.Error("Failed to inject database", err) 29 | } 30 | 31 | // Inject repositories 32 | err = repositories.Inject(container) 33 | if err != nil { 34 | logger.Error("Failed to inject repositories", err) 35 | } 36 | 37 | // Inject services 38 | err = services.Inject(container) 39 | if err != nil { 40 | logger.Error("Failed to inject services", err) 41 | } 42 | 43 | // Inject APIs 44 | err = api.Inject(container) 45 | if err != nil { 46 | logger.Error("Failed to inject APIs", err) 47 | } 48 | 49 | return container 50 | } 51 | 52 | // InitGinEngine initial new gin engine 53 | func InitGinEngine(container *dig.Container) *gin.Engine { 54 | app := gin.New() 55 | router.Docs(app) 56 | err := router.RegisterAPI(app, container) 57 | if err != nil { 58 | return nil 59 | } 60 | 61 | return app 62 | } 63 | -------------------------------------------------------------------------------- /app/auth.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "github.com/dgrijalva/jwt-go" 5 | 6 | "github.com/quangdangfit/go-admin/config" 7 | "github.com/quangdangfit/go-admin/pkg/errors" 8 | jwtAuth "github.com/quangdangfit/go-admin/pkg/jwt" 9 | ) 10 | 11 | // InitAuth initial new IJWTAuth 12 | func InitAuth() (jwtAuth.IJWTAuth, error) { 13 | conf := config.Config.JWTAuth 14 | var opts []jwtAuth.Option 15 | //access token 16 | opts = append(opts, jwtAuth.WithKeyFunc(func(t *jwt.Token) (interface{}, error) { 17 | if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok { 18 | return nil, errors.ErrTokenInvalid 19 | } 20 | return []byte(conf.SigningKey), nil 21 | })) 22 | if conf.Expired != 0 { 23 | opts = append(opts, jwtAuth.WithExpired(conf.Expired)) 24 | } 25 | opts = append(opts, jwtAuth.WithSigningKey([]byte(conf.SigningKey))) 26 | 27 | //refresh token 28 | opts = append(opts, jwtAuth.WithKeyFuncRefresh(func(t *jwt.Token) (interface{}, error) { 29 | if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok { 30 | return nil, errors.ErrTokenInvalid 31 | } 32 | return []byte(conf.SigningRefreshKey), nil 33 | })) 34 | 35 | if conf.ExpiredRefreshToken != 0 { 36 | opts = append(opts, jwtAuth.WithExpiredRefresh(conf.ExpiredRefreshToken)) 37 | } 38 | opts = append(opts, jwtAuth.WithSigningKeyRefresh([]byte(conf.SigningRefreshKey))) 39 | return jwtAuth.NewJWTAuth(opts...), nil 40 | } 41 | -------------------------------------------------------------------------------- /app/dbs/dbs.go: -------------------------------------------------------------------------------- 1 | package dbs 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/jinzhu/gorm" 7 | "github.com/quangdangfit/gocommon/logger" 8 | 9 | "github.com/quangdangfit/go-admin/app/interfaces" 10 | "github.com/quangdangfit/go-admin/config" 11 | ) 12 | 13 | type database struct { 14 | db *gorm.DB 15 | } 16 | 17 | // NewDatabase return new IDatabase interface 18 | func NewDatabase() interfaces.IDatabase { 19 | dbConfig := config.Config.Database 20 | connectionPath := fmt.Sprintf("host=%s port=%d user=%s dbname=%s password=%s sslmode=%s", 21 | dbConfig.Host, dbConfig.Port, dbConfig.User, dbConfig.Name, dbConfig.Password, dbConfig.SSLMode) 22 | 23 | logger.Info(connectionPath) 24 | 25 | db, err := gorm.Open("postgres", connectionPath) 26 | if err != nil { 27 | logger.Fatal("Cannot connect to database: ", err) 28 | } 29 | 30 | // Set up connection pool 31 | db.DB().SetMaxIdleConns(20) 32 | db.DB().SetMaxOpenConns(200) 33 | 34 | return &database{ 35 | db: db, 36 | } 37 | } 38 | 39 | // GetInstance get database instance 40 | func (d *database) GetInstance() *gorm.DB { 41 | return d.db 42 | } 43 | -------------------------------------------------------------------------------- /app/dbs/dig.go: -------------------------------------------------------------------------------- 1 | package dbs 2 | 3 | import ( 4 | "go.uber.org/dig" 5 | ) 6 | 7 | // Inject dbs 8 | func Inject(container *dig.Container) error { 9 | _ = container.Provide(NewDatabase) 10 | return nil 11 | } 12 | -------------------------------------------------------------------------------- /app/interfaces/IAuthService.go: -------------------------------------------------------------------------------- 1 | package interfaces 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/quangdangfit/go-admin/app/schema" 7 | ) 8 | 9 | // IAuthService interface 10 | type IAuthService interface { 11 | Login(ctx context.Context, bodyParam *schema.LoginBodyParams) (*schema.UserTokenInfo, error) 12 | Register(ctx context.Context, param *schema.RegisterBodyParams) (*schema.UserTokenInfo, error) 13 | Refresh(ctx context.Context, bodyParam *schema.RefreshBodyParams) (*schema.UserTokenInfo, error) 14 | Logout(ctx context.Context) error 15 | } 16 | -------------------------------------------------------------------------------- /app/interfaces/IDatabase.go: -------------------------------------------------------------------------------- 1 | package interfaces 2 | 3 | import ( 4 | "github.com/jinzhu/gorm" 5 | ) 6 | 7 | // IDatabase interface 8 | type IDatabase interface { 9 | GetInstance() *gorm.DB 10 | } 11 | -------------------------------------------------------------------------------- /app/interfaces/IRoleRepository.go: -------------------------------------------------------------------------------- 1 | package interfaces 2 | 3 | import ( 4 | "github.com/quangdangfit/go-admin/app/models" 5 | ) 6 | 7 | // IRoleRepository interface 8 | type IRoleRepository interface { 9 | GetByName(name string) (*models.Role, error) 10 | Create(role *models.Role) error 11 | } 12 | -------------------------------------------------------------------------------- /app/interfaces/IRoleService.go: -------------------------------------------------------------------------------- 1 | package interfaces 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/quangdangfit/go-admin/app/models" 7 | "github.com/quangdangfit/go-admin/app/schema" 8 | ) 9 | 10 | // IRoleService interface 11 | type IRoleService interface { 12 | Create(ctx context.Context, item *schema.RoleBodyParams) (*models.Role, error) 13 | } 14 | -------------------------------------------------------------------------------- /app/interfaces/IUserRepository.go: -------------------------------------------------------------------------------- 1 | package interfaces 2 | 3 | import ( 4 | "github.com/quangdangfit/go-admin/app/models" 5 | "github.com/quangdangfit/go-admin/app/schema" 6 | ) 7 | 8 | // IUserRepository interface 9 | type IUserRepository interface { 10 | Create(user *models.User) error 11 | GetByID(id string) (*models.User, error) 12 | GetUserByToken(token string) (*models.User, error) 13 | List(queryParam *schema.UserQueryParam) (*[]models.User, error) 14 | Login(item *schema.LoginBodyParams) (*models.User, error) 15 | RemoveToken(userID string) (*models.User, error) 16 | Update(userID string, bodyParam *schema.UserUpdateBodyParam) (*models.User, error) 17 | } 18 | -------------------------------------------------------------------------------- /app/interfaces/IUserService.go: -------------------------------------------------------------------------------- 1 | package interfaces 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/quangdangfit/go-admin/app/models" 7 | "github.com/quangdangfit/go-admin/app/schema" 8 | ) 9 | 10 | // IUserService interface 11 | type IUserService interface { 12 | GetByID(ctx context.Context, id string) (*models.User, error) 13 | List(ctx context.Context, param *schema.UserQueryParam) (*[]models.User, error) 14 | } 15 | -------------------------------------------------------------------------------- /app/middleware/auth.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "github.com/gin-gonic/gin" 5 | 6 | "github.com/quangdangfit/go-admin/pkg/app" 7 | gohttp "github.com/quangdangfit/go-admin/pkg/http" 8 | "github.com/quangdangfit/go-admin/pkg/http/wrapper" 9 | "github.com/quangdangfit/go-admin/pkg/jwt" 10 | ) 11 | 12 | func wrapUserAuthContext(c *gin.Context, userID string) { 13 | app.SetUserID(c, userID) 14 | c.Request = c.Request.WithContext(c) 15 | } 16 | 17 | // UserAuthMiddleware User Auth Middleware 18 | func UserAuthMiddleware(a jwt.IJWTAuth, skippers ...SkipperFunc) gin.HandlerFunc { 19 | return func(c *gin.Context) { 20 | if SkipHandler(c, skippers...) { 21 | c.Next() 22 | return 23 | } 24 | 25 | userID, err := a.ParseUserID(app.GetToken(c), false) 26 | if err != nil { 27 | wrapper.Translate(c, gohttp.Response{Error: err}) 28 | c.Abort() 29 | return 30 | } 31 | wrapUserAuthContext(c, userID) 32 | c.Next() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/middleware/cache/cache.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "bytes" 5 | "net/http" 6 | "strings" 7 | 8 | "github.com/gin-gonic/gin" 9 | "github.com/quangdangfit/gocommon/logger" 10 | ) 11 | 12 | // Cache interface 13 | type Cache interface { 14 | IsConnected() bool 15 | Get(key string, data interface{}) error 16 | Set(key string, val []byte) error 17 | Remove(keys ...string) error 18 | Keys(pattern string) ([]string, error) 19 | } 20 | 21 | // New Setup Initialize the Cache instance 22 | func New() Cache { 23 | return NewRedis() 24 | } 25 | 26 | var cache = New() 27 | 28 | type responseBodyWriter struct { 29 | gin.ResponseWriter 30 | body *bytes.Buffer 31 | } 32 | 33 | // Write ResponseWriter 34 | func (r responseBodyWriter) Write(b []byte) (int, error) { 35 | r.body.Write(b) 36 | return r.ResponseWriter.Write(b) 37 | } 38 | 39 | // Cached middleware 40 | func Cached() gin.HandlerFunc { 41 | return func(c *gin.Context) { 42 | if cache == nil || !cache.IsConnected() { 43 | logger.Warn("Cache cache is not available") 44 | c.Next() 45 | return 46 | } 47 | 48 | w := &responseBodyWriter{body: &bytes.Buffer{}, ResponseWriter: c.Writer} 49 | c.Writer = w 50 | 51 | key := c.Request.URL.RequestURI() 52 | if c.Request.Method != "GET" { 53 | c.Next() 54 | 55 | statusCode := w.Status() 56 | if statusCode != http.StatusOK { 57 | return 58 | } 59 | 60 | if c.Request.Method == "POST" || c.Request.Method == "PUT" || c.Request.Method == "DELETE" { 61 | temp := strings.Split(key, "/") 62 | objName := temp[len(temp)-1] 63 | 64 | keys, _ := cache.Keys("*" + objName + "*") 65 | if keys != nil { 66 | cache.Remove(keys...) 67 | } 68 | } 69 | 70 | return 71 | } 72 | 73 | var data map[string]interface{} 74 | cache.Get(key, &data) 75 | 76 | if data != nil { 77 | c.JSON(http.StatusOK, data) 78 | c.Abort() 79 | return 80 | } 81 | 82 | c.Next() 83 | 84 | statusCode := w.Status() 85 | if statusCode == http.StatusOK { 86 | cache.Set(key, w.body.Bytes()) 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/middleware/cache/gredis.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "time" 8 | 9 | "github.com/go-redis/redis/v8" 10 | "github.com/quangdangfit/gocommon/logger" 11 | 12 | "github.com/quangdangfit/go-admin/config" 13 | ) 14 | 15 | // constants cache 16 | const ( 17 | RedisExpiredTimes = 600 18 | ) 19 | 20 | var ctx = context.Background() 21 | 22 | // GRedis struct 23 | type GRedis struct { 24 | client *redis.Client 25 | expiryTime int 26 | } 27 | 28 | // NewRedis new redis pointer 29 | func NewRedis() *GRedis { 30 | redisConfig := config.Config.Redis 31 | rdb := redis.NewClient(&redis.Options{ 32 | Addr: fmt.Sprintf("%s:%d", redisConfig.Host, redisConfig.Port), 33 | Password: redisConfig.Password, 34 | DB: redisConfig.Database, 35 | }) 36 | 37 | pong, err := rdb.Ping(ctx).Result() 38 | if err != nil { 39 | logger.Error(pong, err) 40 | return nil 41 | } 42 | expiryTime := config.Config.Cache.ExpiryTime 43 | if expiryTime <= 0 { 44 | expiryTime = RedisExpiredTimes 45 | } 46 | 47 | return &GRedis{client: rdb, expiryTime: expiryTime} 48 | } 49 | 50 | // IsConnected check redis is connected or not 51 | func (g *GRedis) IsConnected() bool { 52 | if g.client == nil { 53 | return false 54 | } 55 | 56 | _, err := g.client.Ping(ctx).Result() 57 | if err != nil { 58 | return false 59 | } 60 | return true 61 | } 62 | 63 | // Get get key from redis 64 | func (g *GRedis) Get(key string, data interface{}) error { 65 | val, err := g.client.Get(ctx, key).Bytes() 66 | if err == redis.Nil { 67 | return nil 68 | } 69 | if err != nil { 70 | logger.Info("Cache fail to get: ", err) 71 | return nil 72 | } 73 | logger.Debugf("Get from redis %s - %s", key, val) 74 | 75 | err = json.Unmarshal(val, &data) 76 | if err != nil { 77 | return err 78 | } 79 | 80 | return nil 81 | } 82 | 83 | // Set data to redis 84 | func (g *GRedis) Set(key string, val []byte) error { 85 | err := g.client.Set(ctx, key, val, time.Duration(g.expiryTime)*time.Second).Err() 86 | if err != nil { 87 | logger.Error("Cache fail to set: ", err) 88 | return err 89 | } 90 | logger.Debugf("Set to redis %s - %s", key, val) 91 | 92 | return nil 93 | } 94 | 95 | // Remove return list keys from redis 96 | func (g *GRedis) Remove(keys ...string) error { 97 | err := g.client.Del(ctx, keys...).Err() 98 | if err != nil { 99 | logger.Errorf("Cache fail to delete key %s: %s", keys, err) 100 | return err 101 | } 102 | logger.Debug("Cache deleted key", keys) 103 | 104 | return nil 105 | } 106 | 107 | // Keys get redis keys by pattern regex 108 | func (g *GRedis) Keys(pattern string) ([]string, error) { 109 | keys, err := g.client.Keys(ctx, pattern).Result() 110 | if err != nil { 111 | return nil, err 112 | } 113 | 114 | return keys, nil 115 | } 116 | -------------------------------------------------------------------------------- /app/middleware/jwt/jwt.go: -------------------------------------------------------------------------------- 1 | package jwt 2 | 3 | import ( 4 | "net/http" 5 | "strings" 6 | "time" 7 | 8 | "github.com/dgrijalva/jwt-go" 9 | "github.com/gin-gonic/gin" 10 | "github.com/jinzhu/copier" 11 | "github.com/quangdangfit/gocommon/logger" 12 | 13 | "github.com/quangdangfit/go-admin/pkg/utils" 14 | ) 15 | 16 | // constants jwt 17 | const ( 18 | TokenExpiredTime = 300 19 | ) 20 | 21 | // GenerateToken generate jwt token 22 | func GenerateToken(payload interface{}) string { 23 | tokenContent := jwt.MapClaims{ 24 | "payload": payload, 25 | "exp": time.Now().Add(time.Second * TokenExpiredTime).Unix(), 26 | } 27 | jwtToken := jwt.NewWithClaims(jwt.GetSigningMethod("HS256"), tokenContent) 28 | token, err := jwtToken.SignedString([]byte("TokenPassword")) 29 | if err != nil { 30 | logger.Error("Failed to generate token: ", err) 31 | return "" 32 | } 33 | 34 | return token 35 | } 36 | 37 | // ValidateToken validate jwt token 38 | func ValidateToken(jwtToken string) (map[string]interface{}, error) { 39 | cleanJWT := strings.Replace(jwtToken, "Bearer ", "", -1) 40 | tokenData := jwt.MapClaims{} 41 | token, err := jwt.ParseWithClaims(cleanJWT, tokenData, func(token *jwt.Token) (interface{}, error) { 42 | return []byte("TokenPassword"), nil 43 | }) 44 | 45 | if err != nil { 46 | return nil, err 47 | } 48 | 49 | if !token.Valid { 50 | return nil, jwt.ErrInvalidKey 51 | } 52 | 53 | var data map[string]interface{} 54 | copier.Copy(&data, tokenData["payload"]) 55 | return data, nil 56 | } 57 | 58 | // JWT middleware 59 | func JWT() gin.HandlerFunc { 60 | return func(c *gin.Context) { 61 | var code string 62 | 63 | code = utils.Success 64 | token := c.GetHeader("Authorization") 65 | 66 | if token == "" { 67 | code = utils.InvalidParams 68 | c.JSON(http.StatusUnauthorized, utils.PrepareResponse(nil, "Unauthorized", code)) 69 | 70 | c.Abort() 71 | return 72 | } 73 | 74 | _, err := ValidateToken(token) 75 | if err != nil { 76 | switch err.(*jwt.ValidationError).Errors { 77 | case jwt.ValidationErrorExpired: 78 | code = utils.ErrorAuthCheckTokenTimeout 79 | default: 80 | code = utils.ErrorAuthCheckTokenFail 81 | } 82 | } 83 | 84 | if code != utils.Success { 85 | c.JSON(http.StatusUnauthorized, utils.PrepareResponse(nil, "Unauthorized", code)) 86 | 87 | c.Abort() 88 | return 89 | } 90 | 91 | c.Next() 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /app/middleware/middleware.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/gin-gonic/gin" 8 | ) 9 | 10 | // SkipperFunc skipper function 11 | type SkipperFunc func(*gin.Context) bool 12 | 13 | // AllowPathPrefixSkipper allow paths have prefix skip middleware 14 | func AllowPathPrefixSkipper(prefixes ...string) SkipperFunc { 15 | return func(c *gin.Context) bool { 16 | path := c.Request.URL.Path 17 | pathLen := len(path) 18 | 19 | for _, p := range prefixes { 20 | if plen := len(p); pathLen >= plen && path[:plen] == p { 21 | return true 22 | } 23 | } 24 | return false 25 | } 26 | } 27 | 28 | // AllowPathPrefixNoSkipper allow paths have prefix no skip middleware 29 | func AllowPathPrefixNoSkipper(prefixes ...string) SkipperFunc { 30 | return func(c *gin.Context) bool { 31 | path := c.Request.URL.Path 32 | pathLen := len(path) 33 | 34 | for _, p := range prefixes { 35 | if pl := len(p); pathLen >= pl && path[:pl] == p { 36 | return false 37 | } 38 | } 39 | return true 40 | } 41 | } 42 | 43 | // AllowMethodAndPathPrefixSkipper allow method and paths have prefix no skip middleware 44 | func AllowMethodAndPathPrefixSkipper(prefixes ...string) SkipperFunc { 45 | return func(c *gin.Context) bool { 46 | path := JoinRouter(c.Request.Method, c.Request.URL.Path) 47 | pathLen := len(path) 48 | 49 | for _, p := range prefixes { 50 | if pl := len(p); pathLen >= pl && path[:pl] == p { 51 | return true 52 | } 53 | } 54 | return false 55 | } 56 | } 57 | 58 | // JoinRouter join router 59 | func JoinRouter(method, path string) string { 60 | if len(path) > 0 && path[0] != '/' { 61 | path = "/" + path 62 | } 63 | return fmt.Sprintf("%s%s", strings.ToUpper(method), path) 64 | } 65 | 66 | // SkipHandler skip handler 67 | func SkipHandler(c *gin.Context, skippers ...SkipperFunc) bool { 68 | for _, skipper := range skippers { 69 | if skipper(c) { 70 | return true 71 | } 72 | } 73 | return false 74 | } 75 | 76 | // EmptyMiddleware return empty middleware 77 | func EmptyMiddleware() gin.HandlerFunc { 78 | return func(c *gin.Context) { 79 | c.Next() 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /app/middleware/roles/roles.go: -------------------------------------------------------------------------------- 1 | package roles 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/dgrijalva/jwt-go" 7 | "github.com/gin-gonic/gin" 8 | 9 | jwtMiddle "github.com/quangdangfit/go-admin/app/middleware/jwt" 10 | "github.com/quangdangfit/go-admin/pkg/utils" 11 | ) 12 | 13 | // CheckAdmin middleware 14 | func CheckAdmin() gin.HandlerFunc { 15 | return func(c *gin.Context) { 16 | var code string 17 | 18 | code = utils.Success 19 | token := c.GetHeader("Authorization") 20 | 21 | if token == "" { 22 | code = utils.InvalidParams 23 | c.JSON(http.StatusUnauthorized, utils.PrepareResponse(nil, "Unauthorized", code)) 24 | 25 | c.Abort() 26 | return 27 | } 28 | 29 | _, err := jwtMiddle.ValidateToken(token) 30 | if err != nil { 31 | switch err.(*jwt.ValidationError).Errors { 32 | case jwt.ValidationErrorExpired: 33 | code = utils.ErrorAuthCheckTokenTimeout 34 | default: 35 | code = utils.ErrorAuthCheckTokenFail 36 | } 37 | } 38 | 39 | if code != utils.Success { 40 | c.JSON(http.StatusUnauthorized, utils.PrepareResponse(nil, "Unauthorized", code)) 41 | 42 | c.Abort() 43 | return 44 | } 45 | 46 | c.Next() 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/migration/migration.go: -------------------------------------------------------------------------------- 1 | package migration 2 | 3 | import ( 4 | "go.uber.org/dig" 5 | 6 | "github.com/quangdangfit/go-admin/app/interfaces" 7 | "github.com/quangdangfit/go-admin/app/models" 8 | ) 9 | 10 | // CreateAdmin create new user role admin 11 | func CreateAdmin(container *dig.Container) error { 12 | return container.Invoke(func( 13 | userRepo interfaces.IUserRepository, 14 | roleRepo interfaces.IRoleRepository, 15 | ) error { 16 | adminRole := &models.Role{Name: "admin", Description: "Admin"} 17 | userRole := &models.Role{Name: "user", Description: "User"} 18 | err := roleRepo.Create(adminRole) 19 | err = roleRepo.Create(userRole) 20 | if err != nil { 21 | return err 22 | } 23 | 24 | err = userRepo.Create(&models.User{ 25 | Username: "admin", 26 | Password: "admin", 27 | Email: "admin@admin.com", 28 | RoleID: adminRole.ID, 29 | }) 30 | if err != nil { 31 | return err 32 | } 33 | 34 | return nil 35 | }) 36 | } 37 | 38 | // Migrate migrate to database 39 | func Migrate(container *dig.Container) error { 40 | return container.Invoke(func( 41 | db interfaces.IDatabase, 42 | ) error { 43 | User := models.User{} 44 | Role := models.Role{} 45 | 46 | db.GetInstance().AutoMigrate(&User, &Role) 47 | db.GetInstance().Model(&User).AddForeignKey("role_id", "roles(id)", "RESTRICT", "RESTRICT") 48 | 49 | return nil 50 | }) 51 | } 52 | -------------------------------------------------------------------------------- /app/mocks/mock_auth_service.go: -------------------------------------------------------------------------------- 1 | // Code generated by MockGen. DO NOT EDIT. 2 | // Source: app/services/auth.go 3 | 4 | package mocks 5 | 6 | import ( 7 | context "context" 8 | gomock "github.com/golang/mock/gomock" 9 | schema "github.com/quangdangfit/go-admin/app/schema" 10 | reflect "reflect" 11 | ) 12 | 13 | // MockIAuthService is a mock of IAuthService interface 14 | type MockIAuthService struct { 15 | ctrl *gomock.Controller 16 | recorder *MockIAuthServiceMockRecorder 17 | } 18 | 19 | // MockIAuthServiceMockRecorder is the mock recorder for MockIAuthService 20 | type MockIAuthServiceMockRecorder struct { 21 | mock *MockIAuthService 22 | } 23 | 24 | // NewMockIAuthService creates a new mock instance 25 | func NewMockIAuthService(ctrl *gomock.Controller) *MockIAuthService { 26 | mock := &MockIAuthService{ctrl: ctrl} 27 | mock.recorder = &MockIAuthServiceMockRecorder{mock} 28 | return mock 29 | } 30 | 31 | // EXPECT returns an object that allows the caller to indicate expected use 32 | func (_m *MockIAuthService) EXPECT() *MockIAuthServiceMockRecorder { 33 | return _m.recorder 34 | } 35 | 36 | // Login mocks base method 37 | func (_m *MockIAuthService) Login(ctx context.Context, bodyParam *schema.LoginBodyParams) (*schema.UserTokenInfo, error) { 38 | ret := _m.ctrl.Call(_m, "Login", ctx, bodyParam) 39 | ret0, _ := ret[0].(*schema.UserTokenInfo) 40 | ret1, _ := ret[1].(error) 41 | return ret0, ret1 42 | } 43 | 44 | // Login indicates an expected call of Login 45 | func (_mr *MockIAuthServiceMockRecorder) Login(arg0, arg1 interface{}) *gomock.Call { 46 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Login", reflect.TypeOf((*MockIAuthService)(nil).Login), arg0, arg1) 47 | } 48 | 49 | // Register mocks base method 50 | func (_m *MockIAuthService) Register(ctx context.Context, bodyParam *schema.RegisterBodyParams) (*schema.UserTokenInfo, error) { 51 | ret := _m.ctrl.Call(_m, "Register", ctx, bodyParam) 52 | ret0, _ := ret[0].(*schema.UserTokenInfo) 53 | ret1, _ := ret[1].(error) 54 | return ret0, ret1 55 | } 56 | 57 | // Register indicates an expected call of Register 58 | func (_mr *MockIAuthServiceMockRecorder) Register(arg0, arg1 interface{}) *gomock.Call { 59 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Register", reflect.TypeOf((*MockIAuthService)(nil).Register), arg0, arg1) 60 | } 61 | 62 | // Refresh mocks base method 63 | func (_m *MockIAuthService) Refresh(ctx context.Context, bodyParam *schema.RefreshBodyParams) (*schema.UserTokenInfo, error) { 64 | ret := _m.ctrl.Call(_m, "Refresh", ctx, bodyParam) 65 | ret0, _ := ret[0].(*schema.UserTokenInfo) 66 | ret1, _ := ret[1].(error) 67 | return ret0, ret1 68 | } 69 | 70 | // Refresh indicates an expected call of Refresh 71 | func (_mr *MockIAuthServiceMockRecorder) Refresh(arg0, arg1 interface{}) *gomock.Call { 72 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Refresh", reflect.TypeOf((*MockIAuthService)(nil).Refresh), arg0, arg1) 73 | } 74 | 75 | // Logout mocks base method 76 | func (_m *MockIAuthService) Logout(ctx context.Context) error { 77 | ret := _m.ctrl.Call(_m, "Logout", ctx) 78 | ret0, _ := ret[0].(error) 79 | return ret0 80 | } 81 | 82 | // Logout indicates an expected call of Logout 83 | func (_mr *MockIAuthServiceMockRecorder) Logout(arg0 interface{}) *gomock.Call { 84 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Logout", reflect.TypeOf((*MockIAuthService)(nil).Logout), arg0) 85 | } 86 | -------------------------------------------------------------------------------- /app/mocks/mock_database.go: -------------------------------------------------------------------------------- 1 | // Code generated by MockGen. DO NOT EDIT. 2 | // Source: app/dbs/dbs.go 3 | 4 | package mocks 5 | 6 | import ( 7 | gomock "github.com/golang/mock/gomock" 8 | gorm "github.com/jinzhu/gorm" 9 | reflect "reflect" 10 | ) 11 | 12 | // MockIDatabase is a mock of IDatabase interface 13 | type MockIDatabase struct { 14 | ctrl *gomock.Controller 15 | recorder *MockIDatabaseMockRecorder 16 | } 17 | 18 | // MockIDatabaseMockRecorder is the mock recorder for MockIDatabase 19 | type MockIDatabaseMockRecorder struct { 20 | mock *MockIDatabase 21 | } 22 | 23 | // NewMockIDatabase creates a new mock instance 24 | func NewMockIDatabase(ctrl *gomock.Controller) *MockIDatabase { 25 | mock := &MockIDatabase{ctrl: ctrl} 26 | mock.recorder = &MockIDatabaseMockRecorder{mock} 27 | return mock 28 | } 29 | 30 | // EXPECT returns an object that allows the caller to indicate expected use 31 | func (_m *MockIDatabase) EXPECT() *MockIDatabaseMockRecorder { 32 | return _m.recorder 33 | } 34 | 35 | // GetInstance mocks base method 36 | func (_m *MockIDatabase) GetInstance() *gorm.DB { 37 | ret := _m.ctrl.Call(_m, "GetInstance") 38 | ret0, _ := ret[0].(*gorm.DB) 39 | return ret0 40 | } 41 | 42 | // GetInstance indicates an expected call of GetInstance 43 | func (_mr *MockIDatabaseMockRecorder) GetInstance() *gomock.Call { 44 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetInstance", reflect.TypeOf((*MockIDatabase)(nil).GetInstance)) 45 | } 46 | -------------------------------------------------------------------------------- /app/mocks/mock_role_repository.go: -------------------------------------------------------------------------------- 1 | // Code generated by MockGen. DO NOT EDIT. 2 | // Source: app/repositories/role.go 3 | 4 | package mocks 5 | 6 | import ( 7 | gomock "github.com/golang/mock/gomock" 8 | models "github.com/quangdangfit/go-admin/app/models" 9 | reflect "reflect" 10 | ) 11 | 12 | // MockIRoleRepository is a mock of IRoleRepository interface 13 | type MockIRoleRepository struct { 14 | ctrl *gomock.Controller 15 | recorder *MockIRoleRepositoryMockRecorder 16 | } 17 | 18 | // MockIRoleRepositoryMockRecorder is the mock recorder for MockIRoleRepository 19 | type MockIRoleRepositoryMockRecorder struct { 20 | mock *MockIRoleRepository 21 | } 22 | 23 | // NewMockIRoleRepository creates a new mock instance 24 | func NewMockIRoleRepository(ctrl *gomock.Controller) *MockIRoleRepository { 25 | mock := &MockIRoleRepository{ctrl: ctrl} 26 | mock.recorder = &MockIRoleRepositoryMockRecorder{mock} 27 | return mock 28 | } 29 | 30 | // EXPECT returns an object that allows the caller to indicate expected use 31 | func (_m *MockIRoleRepository) EXPECT() *MockIRoleRepositoryMockRecorder { 32 | return _m.recorder 33 | } 34 | 35 | // GetByName mocks base method 36 | func (_m *MockIRoleRepository) GetByName(name string) (*models.Role, error) { 37 | ret := _m.ctrl.Call(_m, "GetByName", name) 38 | ret0, _ := ret[0].(*models.Role) 39 | ret1, _ := ret[1].(error) 40 | return ret0, ret1 41 | } 42 | 43 | // GetByName indicates an expected call of GetByName 44 | func (_mr *MockIRoleRepositoryMockRecorder) GetByName(arg0 interface{}) *gomock.Call { 45 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetByName", reflect.TypeOf((*MockIRoleRepository)(nil).GetByName), arg0) 46 | } 47 | 48 | // Create mocks base method 49 | func (_m *MockIRoleRepository) Create(role *models.Role) error { 50 | ret := _m.ctrl.Call(_m, "Create", role) 51 | ret0, _ := ret[0].(error) 52 | return ret0 53 | } 54 | 55 | // Create indicates an expected call of Create 56 | func (_mr *MockIRoleRepositoryMockRecorder) Create(arg0 interface{}) *gomock.Call { 57 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Create", reflect.TypeOf((*MockIRoleRepository)(nil).Create), arg0) 58 | } 59 | -------------------------------------------------------------------------------- /app/mocks/mock_role_service.go: -------------------------------------------------------------------------------- 1 | // Code generated by MockGen. DO NOT EDIT. 2 | // Source: app/services/role.go 3 | 4 | package mocks 5 | 6 | import ( 7 | context "context" 8 | gomock "github.com/golang/mock/gomock" 9 | models "github.com/quangdangfit/go-admin/app/models" 10 | schema "github.com/quangdangfit/go-admin/app/schema" 11 | reflect "reflect" 12 | ) 13 | 14 | // MockIRoleService is a mock of IRoleService interface 15 | type MockIRoleService struct { 16 | ctrl *gomock.Controller 17 | recorder *MockIRoleServiceMockRecorder 18 | } 19 | 20 | // MockIRoleServiceMockRecorder is the mock recorder for MockIRoleService 21 | type MockIRoleServiceMockRecorder struct { 22 | mock *MockIRoleService 23 | } 24 | 25 | // NewMockIRoleService creates a new mock instance 26 | func NewMockIRoleService(ctrl *gomock.Controller) *MockIRoleService { 27 | mock := &MockIRoleService{ctrl: ctrl} 28 | mock.recorder = &MockIRoleServiceMockRecorder{mock} 29 | return mock 30 | } 31 | 32 | // EXPECT returns an object that allows the caller to indicate expected use 33 | func (_m *MockIRoleService) EXPECT() *MockIRoleServiceMockRecorder { 34 | return _m.recorder 35 | } 36 | 37 | // CreateRole mocks base method 38 | func (_m *MockIRoleService) Create(ctx context.Context, item *schema.RoleBodyParams) (*models.Role, error) { 39 | ret := _m.ctrl.Call(_m, "Create", ctx, item) 40 | ret0, _ := ret[0].(*models.Role) 41 | ret1, _ := ret[1].(error) 42 | return ret0, ret1 43 | } 44 | 45 | // CreateRole indicates an expected call of CreateRole 46 | func (_mr *MockIRoleServiceMockRecorder) CreateRole(arg0, arg1 interface{}) *gomock.Call { 47 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Create", reflect.TypeOf((*MockIRoleService)(nil).Create), arg0, arg1) 48 | } 49 | -------------------------------------------------------------------------------- /app/mocks/mock_user_repository.go: -------------------------------------------------------------------------------- 1 | // Code generated by MockGen. DO NOT EDIT. 2 | // Source: app/repositories/user.go 3 | 4 | package mocks 5 | 6 | import ( 7 | gomock "github.com/golang/mock/gomock" 8 | models "github.com/quangdangfit/go-admin/app/models" 9 | schema "github.com/quangdangfit/go-admin/app/schema" 10 | reflect "reflect" 11 | ) 12 | 13 | // MockIUserRepository is a mock of IUserRepository interface 14 | type MockIUserRepository struct { 15 | ctrl *gomock.Controller 16 | recorder *MockIUserRepositoryMockRecorder 17 | } 18 | 19 | // MockIUserRepositoryMockRecorder is the mock recorder for MockIUserRepository 20 | type MockIUserRepositoryMockRecorder struct { 21 | mock *MockIUserRepository 22 | } 23 | 24 | // NewMockIUserRepository creates a new mock instance 25 | func NewMockIUserRepository(ctrl *gomock.Controller) *MockIUserRepository { 26 | mock := &MockIUserRepository{ctrl: ctrl} 27 | mock.recorder = &MockIUserRepositoryMockRecorder{mock} 28 | return mock 29 | } 30 | 31 | // EXPECT returns an object that allows the caller to indicate expected use 32 | func (_m *MockIUserRepository) EXPECT() *MockIUserRepositoryMockRecorder { 33 | return _m.recorder 34 | } 35 | 36 | // Create mocks base method 37 | func (_m *MockIUserRepository) Create(user *models.User) error { 38 | ret := _m.ctrl.Call(_m, "Create", user) 39 | ret0, _ := ret[0].(error) 40 | return ret0 41 | } 42 | 43 | // Create indicates an expected call of Create 44 | func (_mr *MockIUserRepositoryMockRecorder) Create(arg0 interface{}) *gomock.Call { 45 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Create", reflect.TypeOf((*MockIUserRepository)(nil).Create), arg0) 46 | } 47 | 48 | // GetByID mocks base method 49 | func (_m *MockIUserRepository) GetByID(id string) (*models.User, error) { 50 | ret := _m.ctrl.Call(_m, "GetByID", id) 51 | ret0, _ := ret[0].(*models.User) 52 | ret1, _ := ret[1].(error) 53 | return ret0, ret1 54 | } 55 | 56 | // GetByID indicates an expected call of GetByID 57 | func (_mr *MockIUserRepositoryMockRecorder) GetByID(arg0 interface{}) *gomock.Call { 58 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetByID", reflect.TypeOf((*MockIUserRepository)(nil).GetByID), arg0) 59 | } 60 | 61 | // GetUserByToken mocks base method 62 | func (_m *MockIUserRepository) GetUserByToken(token string) (*models.User, error) { 63 | ret := _m.ctrl.Call(_m, "GetUserByToken", token) 64 | ret0, _ := ret[0].(*models.User) 65 | ret1, _ := ret[1].(error) 66 | return ret0, ret1 67 | } 68 | 69 | // GetUserByToken indicates an expected call of GetUserByToken 70 | func (_mr *MockIUserRepositoryMockRecorder) GetUserByToken(arg0 interface{}) *gomock.Call { 71 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetUserByToken", reflect.TypeOf((*MockIUserRepository)(nil).GetUserByToken), arg0) 72 | } 73 | 74 | // List mocks base method 75 | func (_m *MockIUserRepository) List(queryParam *schema.UserQueryParam) (*[]models.User, error) { 76 | ret := _m.ctrl.Call(_m, "List", queryParam) 77 | ret0, _ := ret[0].(*[]models.User) 78 | ret1, _ := ret[1].(error) 79 | return ret0, ret1 80 | } 81 | 82 | // List indicates an expected call of List 83 | func (_mr *MockIUserRepositoryMockRecorder) List(arg0 interface{}) *gomock.Call { 84 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "List", reflect.TypeOf((*MockIUserRepository)(nil).List), arg0) 85 | } 86 | 87 | // Login mocks base method 88 | func (_m *MockIUserRepository) Login(item *schema.LoginBodyParams) (*models.User, error) { 89 | ret := _m.ctrl.Call(_m, "Login", item) 90 | ret0, _ := ret[0].(*models.User) 91 | ret1, _ := ret[1].(error) 92 | return ret0, ret1 93 | } 94 | 95 | // Login indicates an expected call of Login 96 | func (_mr *MockIUserRepositoryMockRecorder) Login(arg0 interface{}) *gomock.Call { 97 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Login", reflect.TypeOf((*MockIUserRepository)(nil).Login), arg0) 98 | } 99 | 100 | // RemoveToken mocks base method 101 | func (_m *MockIUserRepository) RemoveToken(userId string) (*models.User, error) { 102 | ret := _m.ctrl.Call(_m, "RemoveToken", userId) 103 | ret0, _ := ret[0].(*models.User) 104 | ret1, _ := ret[1].(error) 105 | return ret0, ret1 106 | } 107 | 108 | // RemoveToken indicates an expected call of RemoveToken 109 | func (_mr *MockIUserRepositoryMockRecorder) RemoveToken(arg0 interface{}) *gomock.Call { 110 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "RemoveToken", reflect.TypeOf((*MockIUserRepository)(nil).RemoveToken), arg0) 111 | } 112 | 113 | // Update mocks base method 114 | func (_m *MockIUserRepository) Update(userId string, bodyParam *schema.UserUpdateBodyParam) (*models.User, error) { 115 | ret := _m.ctrl.Call(_m, "Update", userId, bodyParam) 116 | ret0, _ := ret[0].(*models.User) 117 | ret1, _ := ret[1].(error) 118 | return ret0, ret1 119 | } 120 | 121 | // Update indicates an expected call of Update 122 | func (_mr *MockIUserRepositoryMockRecorder) Update(arg0, arg1 interface{}) *gomock.Call { 123 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Update", reflect.TypeOf((*MockIUserRepository)(nil).Update), arg0, arg1) 124 | } 125 | -------------------------------------------------------------------------------- /app/mocks/mock_user_service.go: -------------------------------------------------------------------------------- 1 | // Code generated by MockGen. DO NOT EDIT. 2 | // Source: app/services/user.go 3 | 4 | package mocks 5 | 6 | import ( 7 | context "context" 8 | gomock "github.com/golang/mock/gomock" 9 | models "github.com/quangdangfit/go-admin/app/models" 10 | schema "github.com/quangdangfit/go-admin/app/schema" 11 | reflect "reflect" 12 | ) 13 | 14 | // MockIUserService is a mock of IUserService interface 15 | type MockIUserService struct { 16 | ctrl *gomock.Controller 17 | recorder *MockIUserServiceMockRecorder 18 | } 19 | 20 | // MockIUserServiceMockRecorder is the mock recorder for MockIUserService 21 | type MockIUserServiceMockRecorder struct { 22 | mock *MockIUserService 23 | } 24 | 25 | // NewMockIUserService creates a new mock instance 26 | func NewMockIUserService(ctrl *gomock.Controller) *MockIUserService { 27 | mock := &MockIUserService{ctrl: ctrl} 28 | mock.recorder = &MockIUserServiceMockRecorder{mock} 29 | return mock 30 | } 31 | 32 | // EXPECT returns an object that allows the caller to indicate expected use 33 | func (_m *MockIUserService) EXPECT() *MockIUserServiceMockRecorder { 34 | return _m.recorder 35 | } 36 | 37 | // GetByID mocks base method 38 | func (_m *MockIUserService) GetByID(ctx context.Context, id string) (*models.User, error) { 39 | ret := _m.ctrl.Call(_m, "GetByID", ctx, id) 40 | ret0, _ := ret[0].(*models.User) 41 | ret1, _ := ret[1].(error) 42 | return ret0, ret1 43 | } 44 | 45 | // GetByID indicates an expected call of GetByID 46 | func (_mr *MockIUserServiceMockRecorder) GetByID(arg0, arg1 interface{}) *gomock.Call { 47 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetByID", reflect.TypeOf((*MockIUserService)(nil).GetByID), arg0, arg1) 48 | } 49 | 50 | // List mocks base method 51 | func (_m *MockIUserService) List(ctx context.Context, param *schema.UserQueryParam) (*[]models.User, error) { 52 | ret := _m.ctrl.Call(_m, "List", ctx, param) 53 | ret0, _ := ret[0].(*[]models.User) 54 | ret1, _ := ret[1].(error) 55 | return ret0, ret1 56 | } 57 | 58 | // List indicates an expected call of List 59 | func (_mr *MockIUserServiceMockRecorder) List(arg0, arg1 interface{}) *gomock.Call { 60 | return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "List", reflect.TypeOf((*MockIUserService)(nil).List), arg0, arg1) 61 | } 62 | -------------------------------------------------------------------------------- /app/models/base.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/google/uuid" 7 | "github.com/jinzhu/gorm" 8 | ) 9 | 10 | // Model base model 11 | type Model struct { 12 | ID string `json:"id" gorm:"unique;not null;index;primary_key"` 13 | CreatedAt time.Time `json:"created_at" gorm:"not null;index"` 14 | UpdatedAt time.Time `json:"updated_at" gorm:"not null;index"` 15 | } 16 | 17 | // BeforeCreate handle before create 18 | func (model *Model) BeforeCreate(scope *gorm.Scope) error { 19 | if model.ID == "" { 20 | model.ID = uuid.New().String() 21 | } 22 | if model.CreatedAt.IsZero() { 23 | model.CreatedAt = time.Now() 24 | } 25 | if model.UpdatedAt.IsZero() { 26 | model.UpdatedAt = time.Now() 27 | } 28 | return nil 29 | } 30 | 31 | // BeforeUpdate handle before update 32 | func (model *Model) BeforeUpdate(scope *gorm.Scope) error { 33 | model.UpdatedAt = time.Now().UTC() 34 | return nil 35 | } 36 | -------------------------------------------------------------------------------- /app/models/m_role.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | // Role model role 4 | type Role struct { 5 | Model `json:"inline"` 6 | Name string `json:"name" gorm:"unique;not null;index"` 7 | Description string `json:"description"` 8 | } 9 | -------------------------------------------------------------------------------- /app/models/m_user.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "github.com/jinzhu/gorm" 5 | 6 | "github.com/quangdangfit/go-admin/pkg/errors" 7 | "github.com/quangdangfit/go-admin/pkg/utils" 8 | ) 9 | 10 | // User model user 11 | type User struct { 12 | Model `json:"inline"` 13 | Username string `json:"username" gorm:"unique;not null;index"` 14 | Email string `json:"email" gorm:"unique;not null;index"` 15 | Password string `json:"password" gorm:"not null;index"` 16 | RoleID string `json:"role_id" gorm:"not null;index"` 17 | RefreshToken string `json:"refresh_token" gorm:"index"` 18 | } 19 | 20 | // BeforeCreate handle before create user 21 | func (u *User) BeforeCreate(scope *gorm.Scope) error { 22 | err := u.Model.BeforeCreate(scope) 23 | if err != nil { 24 | return err 25 | } 26 | 27 | hashedPassword, err := utils.HashPassword([]byte(u.Password)) 28 | if err != nil { 29 | return errors.Wrap(err, "User.BeforeCreate") 30 | } 31 | u.Password = hashedPassword 32 | 33 | return nil 34 | } 35 | -------------------------------------------------------------------------------- /app/repositories/dig.go: -------------------------------------------------------------------------------- 1 | package repositories 2 | 3 | import ( 4 | "go.uber.org/dig" 5 | ) 6 | 7 | // Inject repositories 8 | func Inject(container *dig.Container) error { 9 | _ = container.Provide(NewUserRepository) 10 | _ = container.Provide(NewRoleRepository) 11 | return nil 12 | } 13 | -------------------------------------------------------------------------------- /app/repositories/r_role.go: -------------------------------------------------------------------------------- 1 | package repositories 2 | 3 | import ( 4 | "github.com/quangdangfit/go-admin/app/interfaces" 5 | "github.com/quangdangfit/go-admin/app/models" 6 | "github.com/quangdangfit/go-admin/pkg/errors" 7 | ) 8 | 9 | // RoleRepo role repository struct 10 | type RoleRepo struct { 11 | db interfaces.IDatabase 12 | } 13 | 14 | // NewRoleRepository return new IRoleRepository interface 15 | func NewRoleRepository(db interfaces.IDatabase) interfaces.IRoleRepository { 16 | return &RoleRepo{db: db} 17 | } 18 | 19 | // Create new role 20 | func (r *RoleRepo) Create(role *models.Role) error { 21 | if err := r.db.GetInstance().Create(&role).Error; err != nil { 22 | return errors.ErrorDatabaseCreate.Newm(err.Error()) 23 | } 24 | return nil 25 | } 26 | 27 | // GetByName get role by name 28 | func (r *RoleRepo) GetByName(name string) (*models.Role, error) { 29 | var role models.Role 30 | if err := r.db.GetInstance().Where("name = ? ", name).First(&role).Error; err != nil { 31 | return nil, errors.ErrorDatabaseGet.Newm(err.Error()) 32 | } 33 | return &role, nil 34 | } 35 | -------------------------------------------------------------------------------- /app/repositories/r_user.go: -------------------------------------------------------------------------------- 1 | package repositories 2 | 3 | import ( 4 | "github.com/jinzhu/copier" 5 | "golang.org/x/crypto/bcrypt" 6 | 7 | "github.com/quangdangfit/go-admin/app/interfaces" 8 | "github.com/quangdangfit/go-admin/app/models" 9 | "github.com/quangdangfit/go-admin/app/schema" 10 | "github.com/quangdangfit/go-admin/pkg/errors" 11 | "github.com/quangdangfit/go-admin/pkg/utils" 12 | ) 13 | 14 | // UserRepo user repository struct 15 | type UserRepo struct { 16 | db interfaces.IDatabase 17 | } 18 | 19 | // NewUserRepository return new IUserRepository interface 20 | func NewUserRepository(db interfaces.IDatabase) interfaces.IUserRepository { 21 | return &UserRepo{db: db} 22 | } 23 | 24 | // Login handle user login 25 | func (r *UserRepo) Login(item *schema.LoginBodyParams) (*models.User, error) { 26 | user := &models.User{} 27 | if err := r.db.GetInstance().Where("username = ? ", item.Username).First(&user).Error; err != nil { 28 | return nil, errors.ErrorDatabaseGet.Newm(err.Error()) 29 | } 30 | 31 | passErr := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(item.Password)) 32 | if passErr == bcrypt.ErrMismatchedHashAndPassword && passErr != nil { 33 | return nil, errors.ErrorInvalidPassword.Newm("invalid password") 34 | } 35 | 36 | return user, nil 37 | } 38 | 39 | // Register new user 40 | func (r *UserRepo) Register(item *schema.RegisterBodyParams) (*models.User, error) { 41 | var user models.User 42 | copier.Copy(&user, &item) 43 | if err := r.db.GetInstance().Create(&user).Error; err != nil { 44 | return nil, errors.ErrorDatabaseCreate.Newm(err.Error()) 45 | } 46 | 47 | return &user, nil 48 | } 49 | 50 | // GetUserByID get user by id 51 | func (r *UserRepo) GetUserByID(id string) (*models.User, error) { 52 | user := models.User{} 53 | if err := r.db.GetInstance().Where("id = ? ", id).First(&user).Error; err != nil { 54 | return nil, errors.ErrorDatabaseGet.Newm(err.Error()) 55 | } 56 | 57 | return &user, nil 58 | } 59 | 60 | // GetUserByToken get user by refresh token 61 | func (r *UserRepo) GetUserByToken(token string) (*models.User, error) { 62 | var user models.User 63 | if err := r.db.GetInstance().Where("refresh_token = ? ", token).First(&user).Error; err != nil { 64 | return nil, errors.ErrorDatabaseGet.Newm(err.Error()) 65 | } 66 | 67 | return &user, nil 68 | } 69 | 70 | // GetUsers get users by by query 71 | func (r *UserRepo) GetUsers(queryParam *schema.UserQueryParam) (*[]models.User, error) { 72 | var query map[string]interface{} 73 | err := utils.Copy(&query, &queryParam) 74 | if err != nil { 75 | return nil, errors.ErrorMarshal.Newm(err.Error()) 76 | } 77 | 78 | var user []models.User 79 | if err := r.db.GetInstance().Where(query).Find(&user).Error; err != nil { 80 | return nil, errors.ErrorDatabaseGet.Newm(err.Error()) 81 | } 82 | 83 | return &user, nil 84 | } 85 | 86 | // Update user 87 | func (r *UserRepo) Update(userID string, bodyParam *schema.UserUpdateBodyParam) (*models.User, error) { 88 | var body map[string]interface{} 89 | err := utils.Copy(&body, &bodyParam) 90 | if err != nil { 91 | return nil, errors.ErrorMarshal.Newm(err.Error()) 92 | } 93 | 94 | var change models.User 95 | if err := r.db.GetInstance().Model(&change).Where("id = ?", userID).Update(body).Error; err != nil { 96 | return nil, errors.ErrorDatabaseUpdate.Newm(err.Error()) 97 | } 98 | 99 | return &change, nil 100 | } 101 | 102 | // RemoveToken remove refresh token 103 | func (r *UserRepo) RemoveToken(userID string) (*models.User, error) { 104 | var body = map[string]interface{}{"refresh_token": ""} 105 | var change models.User 106 | if err := r.db.GetInstance().Model(&change).Where("id = ?", userID).Update(body).Error; err != nil { 107 | return nil, errors.ErrorDatabaseUpdate.Newm(err.Error()) 108 | } 109 | 110 | return &change, nil 111 | } 112 | 113 | // Create new user 114 | func (r *UserRepo) Create(user *models.User) error { 115 | if err := r.db.GetInstance().Create(&user).Error; err != nil { 116 | return errors.ErrorDatabaseCreate.Newm(err.Error()) 117 | } 118 | return nil 119 | } 120 | 121 | // GetByID get user by id 122 | func (r *UserRepo) GetByID(id string) (*models.User, error) { 123 | user := models.User{} 124 | if err := r.db.GetInstance().Where("id = ? ", id).First(&user).Error; err != nil { 125 | return nil, errors.ErrorDatabaseGet.Newm(err.Error()) 126 | } 127 | 128 | return &user, nil 129 | } 130 | 131 | // List get user by UserQueryParam 132 | func (r *UserRepo) List(param *schema.UserQueryParam) (*[]models.User, error) { 133 | var query map[string]interface{} 134 | err := utils.Copy(&query, ¶m) 135 | if err != nil { 136 | return nil, errors.ErrorMarshal.Newm(err.Error()) 137 | } 138 | 139 | var user []models.User 140 | if err := r.db.GetInstance().Where(query).Offset(param.Offset).Limit(param.Limit).Find(&user).Error; err != nil { 141 | return nil, errors.ErrorDatabaseGet.Newm(err.Error()) 142 | } 143 | 144 | return &user, nil 145 | } 146 | -------------------------------------------------------------------------------- /app/router/api.go: -------------------------------------------------------------------------------- 1 | package router 2 | 3 | import ( 4 | "github.com/gin-gonic/gin" 5 | "github.com/quangdangfit/gocommon/logger" 6 | "go.uber.org/dig" 7 | 8 | "github.com/quangdangfit/go-admin/app/api" 9 | "github.com/quangdangfit/go-admin/app/middleware" 10 | "github.com/quangdangfit/go-admin/pkg/http/wrapper" 11 | "github.com/quangdangfit/go-admin/pkg/jwt" 12 | ) 13 | 14 | // RegisterAPI register api routes 15 | func RegisterAPI(r *gin.Engine, container *dig.Container) error { 16 | err := container.Invoke(func( 17 | jwt jwt.IJWTAuth, 18 | authAPI *api.AuthAPI, 19 | userAPI *api.UserAPI, 20 | roleAPI *api.RoleAPI, 21 | ) error { 22 | jwtMiddle := middleware.UserAuthMiddleware(jwt) 23 | 24 | { 25 | r.POST("/register", wrapper.Wrap(authAPI.Register)) 26 | r.POST("/login", wrapper.Wrap(authAPI.Login)) 27 | r.POST("/refresh", wrapper.Wrap(authAPI.Refresh)) 28 | r.POST("/logout", jwtMiddle, wrapper.Wrap(authAPI.Logout)) 29 | } 30 | 31 | adminPath := r.Group("/admin") 32 | { 33 | adminPath.POST("/roles", wrapper.Wrap(roleAPI.CreateRole)) 34 | } 35 | 36 | //--------------------------------API----------------------------------- 37 | apiPath := r.Group("/api/v1", jwtMiddle) 38 | { 39 | apiPath.GET("/users/:id", userAPI.GetByID) 40 | apiPath.GET("/users", wrapper.Wrap(userAPI.List)) 41 | } 42 | return nil 43 | }) 44 | 45 | if err != nil { 46 | logger.Error(err) 47 | } 48 | 49 | return err 50 | } 51 | -------------------------------------------------------------------------------- /app/router/docs.go: -------------------------------------------------------------------------------- 1 | package router 2 | 3 | import ( 4 | "github.com/gin-gonic/gin" 5 | swaggerFiles "github.com/swaggo/files" 6 | ginSwagger "github.com/swaggo/gin-swagger" 7 | ) 8 | 9 | // Docs routes 10 | func Docs(e *gin.Engine) { 11 | e.GET("swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) 12 | } 13 | -------------------------------------------------------------------------------- /app/schema/sc_response.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | // BaseResponse base response body 4 | type BaseResponse struct { 5 | Status int `json:"status"` 6 | Code string `json:"code"` 7 | Message string `json:"message"` 8 | Data interface{} `json:"data"` 9 | } 10 | -------------------------------------------------------------------------------- /app/schema/sc_role.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | // Role schema 4 | type Role struct { 5 | ID string `json:"id"` 6 | Name string `json:"name"` 7 | Description string `json:"description"` 8 | } 9 | 10 | // RoleBodyParams schema 11 | type RoleBodyParams struct { 12 | Name string `json:"name" validate:"required"` 13 | Description string `json:"description"` 14 | } 15 | -------------------------------------------------------------------------------- /app/schema/sc_user.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | // User schema 4 | type User struct { 5 | ID string `json:"id"` 6 | Username string `json:"username"` 7 | Email string `json:"email"` 8 | Extra interface{} `json:"extra,omitempty"` 9 | } 10 | 11 | // RegisterBodyParams schema 12 | type RegisterBodyParams struct { 13 | Username string `json:"username" validate:"required"` 14 | Email string `json:"email" validate:"required,email"` 15 | Password string `json:"password" validate:"required,password"` 16 | RoleID string `json:"role_id"` 17 | } 18 | 19 | // LoginBodyParams schema 20 | type LoginBodyParams struct { 21 | Username string `json:"username" validate:"required"` 22 | Password string `json:"password" validate:"required,password"` 23 | } 24 | 25 | // RefreshBodyParams schema 26 | type RefreshBodyParams struct { 27 | RefreshToken string `json:"refresh_token,omitempty" validate:"required"` 28 | } 29 | 30 | // UserQueryParam schema 31 | type UserQueryParam struct { 32 | Username string `json:"username,omitempty" form:"username,omitempty"` 33 | Email string `json:"email,omitempty" form:"email,omitempty"` 34 | Offset int `json:"-" form:"offset,omitempty"` 35 | Limit int `json:"-" form:"limit,omitempty"` 36 | } 37 | 38 | // UserTokenInfo schema 39 | type UserTokenInfo struct { 40 | AccessToken string `json:"access_token"` 41 | RefreshToken string `json:"refresh_token"` 42 | TokenType string `json:"token_type"` 43 | } 44 | 45 | // UserUpdateBodyParam schema 46 | type UserUpdateBodyParam struct { 47 | Password string `json:"password,omitempty"` 48 | RoleID string `json:"role_id,omitempty"` 49 | RefreshToken string `json:"refresh_token,omitempty"` 50 | } 51 | -------------------------------------------------------------------------------- /app/services/dig.go: -------------------------------------------------------------------------------- 1 | package services 2 | 3 | import ( 4 | "go.uber.org/dig" 5 | ) 6 | 7 | // Inject services 8 | func Inject(container *dig.Container) error { 9 | _ = container.Provide(NewAuthService) 10 | _ = container.Provide(NewUserService) 11 | _ = container.Provide(NewRoleService) 12 | return nil 13 | } 14 | -------------------------------------------------------------------------------- /app/services/s_auth.go: -------------------------------------------------------------------------------- 1 | package services 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/jinzhu/copier" 7 | 8 | "github.com/quangdangfit/go-admin/app/interfaces" 9 | "github.com/quangdangfit/go-admin/app/models" 10 | "github.com/quangdangfit/go-admin/app/schema" 11 | "github.com/quangdangfit/go-admin/pkg/app" 12 | "github.com/quangdangfit/go-admin/pkg/errors" 13 | "github.com/quangdangfit/go-admin/pkg/jwt" 14 | ) 15 | 16 | // AuthService authentication service 17 | type AuthService struct { 18 | jwt jwt.IJWTAuth 19 | userRepo interfaces.IUserRepository 20 | roleRepo interfaces.IRoleRepository 21 | } 22 | 23 | // NewAuthService return new IAuthService interface 24 | func NewAuthService(jwt jwt.IJWTAuth, user interfaces.IUserRepository, 25 | role interfaces.IRoleRepository) interfaces.IAuthService { 26 | return &AuthService{ 27 | jwt: jwt, 28 | userRepo: user, 29 | roleRepo: role, 30 | } 31 | } 32 | 33 | // Login handle user login 34 | func (a *AuthService) Login(ctx context.Context, bodyParam *schema.LoginBodyParams) (*schema.UserTokenInfo, error) { 35 | user, err := a.userRepo.Login(bodyParam) 36 | if err != nil { 37 | return nil, err 38 | } 39 | 40 | token, err := a.jwt.GenerateToken(user.ID) 41 | if err != nil { 42 | return nil, err 43 | } 44 | 45 | values := schema.UserUpdateBodyParam{RefreshToken: token.GetRefreshToken()} 46 | _, err = a.userRepo.Update(user.ID, &values) 47 | if err != nil { 48 | return nil, err 49 | } 50 | 51 | tokenInfo := schema.UserTokenInfo{ 52 | AccessToken: token.GetAccessToken(), 53 | RefreshToken: token.GetRefreshToken(), 54 | TokenType: token.GetTokenType(), 55 | } 56 | 57 | return &tokenInfo, nil 58 | } 59 | 60 | // Register register user 61 | func (a *AuthService) Register(ctx context.Context, param *schema.RegisterBodyParams) (*schema.UserTokenInfo, error) { 62 | if param.RoleID == "" { 63 | role, err := a.roleRepo.GetByName("user") 64 | if err != nil { 65 | return nil, err 66 | } 67 | 68 | param.RoleID = role.ID 69 | } 70 | 71 | var user models.User 72 | copier.Copy(&user, ¶m) 73 | err := a.userRepo.Create(&user) 74 | if err != nil { 75 | return nil, err 76 | } 77 | 78 | token, _ := a.jwt.GenerateToken(user.ID) 79 | values := schema.UserUpdateBodyParam{RefreshToken: token.GetRefreshToken()} 80 | _, err = a.userRepo.Update(user.ID, &values) 81 | if err != nil { 82 | return nil, err 83 | } 84 | 85 | tokenInfo := schema.UserTokenInfo{ 86 | AccessToken: token.GetAccessToken(), 87 | RefreshToken: token.GetRefreshToken(), 88 | TokenType: token.GetTokenType(), 89 | } 90 | 91 | return &tokenInfo, nil 92 | } 93 | 94 | // Refresh refresh token for user 95 | func (a *AuthService) Refresh(ctx context.Context, bodyParam *schema.RefreshBodyParams) (*schema.UserTokenInfo, error) { 96 | user, err := a.userRepo.GetUserByToken(bodyParam.RefreshToken) 97 | if err != nil { 98 | return nil, errors.ErrorTokenInvalid.New() 99 | } 100 | 101 | token, err := a.jwt.RefreshToken(bodyParam.RefreshToken) 102 | if err != nil { 103 | return nil, err 104 | } 105 | 106 | if token.GetRefreshToken() != user.RefreshToken { 107 | values := schema.UserUpdateBodyParam{RefreshToken: token.GetRefreshToken()} 108 | _, err = a.userRepo.Update(user.ID, &values) 109 | } 110 | 111 | tokenInfo := schema.UserTokenInfo{ 112 | AccessToken: token.GetAccessToken(), 113 | RefreshToken: token.GetRefreshToken(), 114 | TokenType: token.GetTokenType(), 115 | } 116 | 117 | return &tokenInfo, nil 118 | } 119 | 120 | // Logout logout user 121 | func (a *AuthService) Logout(ctx context.Context) error { 122 | _, err := a.userRepo.RemoveToken(app.GetUserID(ctx)) 123 | if err != nil { 124 | return err 125 | } 126 | 127 | return nil 128 | } 129 | -------------------------------------------------------------------------------- /app/services/s_role.go: -------------------------------------------------------------------------------- 1 | package services 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/quangdangfit/go-admin/app/interfaces" 7 | "github.com/quangdangfit/go-admin/app/models" 8 | "github.com/quangdangfit/go-admin/app/schema" 9 | "github.com/quangdangfit/go-admin/pkg/utils" 10 | ) 11 | 12 | // RoleService role service 13 | type RoleService struct { 14 | repo interfaces.IRoleRepository 15 | } 16 | 17 | // NewRoleService return new IRoleService interface 18 | func NewRoleService(repo interfaces.IRoleRepository) interfaces.IRoleService { 19 | return &RoleService{repo: repo} 20 | } 21 | 22 | // CreateRole create new role 23 | func (r *RoleService) Create(ctx context.Context, item *schema.RoleBodyParams) (*models.Role, error) { 24 | var role models.Role 25 | err := utils.Copy(&role, &item) 26 | if err != nil { 27 | return nil, err 28 | } 29 | 30 | err = r.repo.Create(&role) 31 | if err != nil { 32 | return nil, err 33 | } 34 | 35 | return &role, nil 36 | } 37 | -------------------------------------------------------------------------------- /app/services/s_user.go: -------------------------------------------------------------------------------- 1 | package services 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/quangdangfit/go-admin/app/interfaces" 7 | "github.com/quangdangfit/go-admin/app/models" 8 | "github.com/quangdangfit/go-admin/app/schema" 9 | "github.com/quangdangfit/go-admin/config" 10 | "github.com/quangdangfit/go-admin/pkg/errors" 11 | ) 12 | 13 | // UserService user service 14 | type UserService struct { 15 | userRepo interfaces.IUserRepository 16 | roleRepo interfaces.IRoleRepository 17 | } 18 | 19 | // NewUserService return new IUserService interface 20 | func NewUserService(user interfaces.IUserRepository, role interfaces.IRoleRepository) interfaces.IUserService { 21 | return &UserService{ 22 | userRepo: user, 23 | roleRepo: role, 24 | } 25 | } 26 | 27 | func (u *UserService) checkPermission(id string, data map[string]interface{}) bool { 28 | return data["id"] == id 29 | } 30 | 31 | // GetByID get user by id 32 | func (u *UserService) GetByID(ctx context.Context, id string) (*models.User, error) { 33 | user, err := u.userRepo.GetByID(id) 34 | if err != nil { 35 | return nil, errors.Wrap(err, "UserService.GetByID") 36 | } 37 | 38 | return user, nil 39 | } 40 | 41 | // List users by query 42 | func (u *UserService) List(ctx context.Context, param *schema.UserQueryParam) (*[]models.User, error) { 43 | if param.Limit > config.Config.DefaultLimit { 44 | param.Limit = config.Config.MaxLimit 45 | } else if param.Limit <= 0 { 46 | param.Limit = config.Config.DefaultLimit 47 | } 48 | 49 | user, err := u.userRepo.List(param) 50 | if err != nil { 51 | return nil, err 52 | } 53 | 54 | return user, nil 55 | } 56 | -------------------------------------------------------------------------------- /cmd/admin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/quangdangfit/gocommon/logger" 5 | 6 | "github.com/quangdangfit/go-admin/app" 7 | "github.com/quangdangfit/go-admin/app/migration" 8 | ) 9 | 10 | func main() { 11 | container := app.BuildContainer() 12 | err := migration.CreateAdmin(container) 13 | if err != nil { 14 | logger.Error("Failed to create admin: ", err) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/spf13/viper" 8 | ) 9 | 10 | // Schema struct 11 | type Schema struct { 12 | Env string `mapstructure:"env"` 13 | DefaultLimit int `mapstructure:"default_limit"` 14 | MaxLimit int `mapstructure:"max_limit"` 15 | 16 | Database struct { 17 | Host string `mapstructure:"host"` 18 | Port int `mapstructure:"port"` 19 | Name string `mapstructure:"name"` 20 | User string `mapstructure:"user"` 21 | Password string `mapstructure:"password"` 22 | Env string `mapstructure:"env"` 23 | SSLMode string `mapstructure:"sslmode"` 24 | } `mapstructure:"database"` 25 | 26 | Redis struct { 27 | Host string `mapstructure:"host"` 28 | Port int `mapstructure:"port"` 29 | Password string `mapstructure:"password"` 30 | Database int `mapstructure:"database"` 31 | } `mapstructure:"redis"` 32 | 33 | Cache struct { 34 | Enable bool `mapstructure:"enable"` 35 | ExpiryTime int `mapstructure:"expiry_time"` 36 | } `mapstructure:"cache"` 37 | 38 | JWTAuth struct { 39 | SigningKey string `mapstructure:"signing_key"` 40 | Expired int `mapstructure:"expired"` 41 | SigningRefreshKey string `mapstructure:"signing_refresh_key"` 42 | ExpiredRefreshToken int `mapstructure:"expired_refresh_token"` 43 | } `mapstructure:"jwt_auth"` 44 | } 45 | 46 | // Config global parameter config 47 | var Config Schema 48 | 49 | func init() { 50 | config := viper.New() 51 | config.SetConfigName("config") 52 | config.AddConfigPath(".") // Look for config in current directory 53 | config.AddConfigPath("config/") // Optionally look for config in the working directory. 54 | config.AddConfigPath("../config/") // Look for config needed for tests. 55 | config.AddConfigPath("../") // Look for config needed for tests. 56 | config.AddConfigPath("../../config/") // Look for config needed for tests. 57 | config.AddConfigPath("../../") // Look for config needed for tests. 58 | 59 | config.SetEnvKeyReplacer(strings.NewReplacer(".", "__")) 60 | config.AutomaticEnv() 61 | 62 | err := config.ReadInConfig() // Find and read the config file 63 | if err != nil { // Handle errors reading the config file 64 | panic(fmt.Errorf("fatal error config file: %s", err)) 65 | } 66 | 67 | err = config.Unmarshal(&Config) 68 | if err != nil { // Handle errors reading the config file 69 | panic(fmt.Errorf("fatal error config file: %s", err)) 70 | } 71 | // fmt.Printf("Current Config: %+v", Config) 72 | } 73 | -------------------------------------------------------------------------------- /config/config.sample.yaml: -------------------------------------------------------------------------------- 1 | env: production 2 | default_limit: 25 3 | max_limit: 100 4 | 5 | database: 6 | host: localhost 7 | port: 5432 8 | name: database 9 | env: native 10 | user: ###### 11 | password: ###### 12 | sslmode: disable 13 | 14 | redis: 15 | enable: true 16 | host: localhost 17 | port: 18 | password: 19 | database: 0 20 | 21 | cache: 22 | enable: true 23 | expiry_time: 3600 24 | 25 | jwt_auth: 26 | signing_key: access 27 | expired: 900 28 | signing_refresh_key: refresh 29 | expired_refresh_token: 1 30 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | git config --global url.ssh://git@github.com/.insteadOf https://github.com/ 2 | git checkout master 3 | git pull 4 | 5 | go mod vendor 6 | sudo systemctl restart goadmin.service -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.8" 2 | services: 3 | go-admin: 4 | build: . 5 | image: "github.com/quangdangfit/go-admin" 6 | ports: 7 | - "8888:8888" 8 | environment: 9 | DATABASE__HOST: "postgres" 10 | depends_on: 11 | - postgres 12 | - redis 13 | 14 | redis: 15 | image: "redis:alpine" 16 | ports: 17 | - "6379:6379" 18 | volumes: 19 | - "/.storage/redis_data:/data" 20 | 21 | postgres: 22 | restart: always 23 | image: "postgres:latest" 24 | environment: 25 | DATABASE_USER: postgres 26 | POSTGRES_PASSWORD: 1234 27 | ports: 28 | - "5432:5432" 29 | volumes: 30 | - "./scripts/init.d:/docker-entrypoint-initdb.d" 31 | - "/.storage/postgres-data:/var/lib/postgresql/data" 32 | -------------------------------------------------------------------------------- /docs/docs.go: -------------------------------------------------------------------------------- 1 | // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT 2 | // This file was generated by swaggo/swag 3 | 4 | package docs 5 | 6 | import ( 7 | "bytes" 8 | "encoding/json" 9 | "strings" 10 | 11 | "github.com/alecthomas/template" 12 | "github.com/swaggo/swag" 13 | ) 14 | 15 | var doc = `{ 16 | "schemes": {{ marshal .Schemes }}, 17 | "swagger": "2.0", 18 | "info": { 19 | "description": "{{.Description}}", 20 | "title": "{{.Title}}", 21 | "contact": {}, 22 | "license": {}, 23 | "version": "{{.Version}}" 24 | }, 25 | "host": "{{.Host}}", 26 | "basePath": "{{.BasePath}}", 27 | "paths": { 28 | "/login": { 29 | "post": { 30 | "description": "api login", 31 | "consumes": [ 32 | "application/json" 33 | ], 34 | "produces": [ 35 | "application/json" 36 | ], 37 | "tags": [ 38 | "Auth" 39 | ], 40 | "summary": "api login", 41 | "parameters": [ 42 | { 43 | "description": "Body", 44 | "name": "body", 45 | "in": "body", 46 | "required": true, 47 | "schema": { 48 | "$ref": "#/definitions/schema.LoginBodyParam" 49 | } 50 | } 51 | ], 52 | "responses": { 53 | "200": { 54 | "description": "OK", 55 | "schema": { 56 | "$ref": "#/definitions/schema.BaseResponse" 57 | } 58 | } 59 | } 60 | } 61 | }, 62 | "/logout": { 63 | "post": { 64 | "security": [ 65 | { 66 | "ApiKeyAuth": [] 67 | } 68 | ], 69 | "description": "api logout", 70 | "consumes": [ 71 | "application/json" 72 | ], 73 | "produces": [ 74 | "application/json" 75 | ], 76 | "tags": [ 77 | "Auth" 78 | ], 79 | "summary": "api logout", 80 | "responses": { 81 | "200": { 82 | "description": "OK", 83 | "schema": { 84 | "$ref": "#/definitions/schema.BaseResponse" 85 | } 86 | } 87 | } 88 | } 89 | }, 90 | "/refresh": { 91 | "post": { 92 | "description": "api refresh token", 93 | "consumes": [ 94 | "application/json" 95 | ], 96 | "produces": [ 97 | "application/json" 98 | ], 99 | "tags": [ 100 | "Auth" 101 | ], 102 | "summary": "api refresh token", 103 | "parameters": [ 104 | { 105 | "description": "Body", 106 | "name": "body", 107 | "in": "body", 108 | "required": true, 109 | "schema": { 110 | "$ref": "#/definitions/schema.RefreshBodyParam" 111 | } 112 | } 113 | ], 114 | "responses": { 115 | "200": { 116 | "description": "OK", 117 | "schema": { 118 | "$ref": "#/definitions/schema.BaseResponse" 119 | } 120 | } 121 | } 122 | } 123 | }, 124 | "/register": { 125 | "post": { 126 | "description": "api register", 127 | "consumes": [ 128 | "application/json" 129 | ], 130 | "produces": [ 131 | "application/json" 132 | ], 133 | "tags": [ 134 | "Auth" 135 | ], 136 | "summary": "api register", 137 | "parameters": [ 138 | { 139 | "description": "Body", 140 | "name": "body", 141 | "in": "body", 142 | "required": true, 143 | "schema": { 144 | "$ref": "#/definitions/schema.RegisterBodyParam" 145 | } 146 | } 147 | ], 148 | "responses": { 149 | "200": { 150 | "description": "OK", 151 | "schema": { 152 | "$ref": "#/definitions/schema.BaseResponse" 153 | } 154 | } 155 | } 156 | } 157 | } 158 | }, 159 | "definitions": { 160 | "schema.BaseResponse": { 161 | "type": "object", 162 | "properties": { 163 | "code": { 164 | "type": "string" 165 | }, 166 | "data": { 167 | "type": "object" 168 | }, 169 | "message": { 170 | "type": "string" 171 | }, 172 | "status": { 173 | "type": "integer" 174 | } 175 | } 176 | }, 177 | "schema.LoginBodyParam": { 178 | "type": "object", 179 | "required": [ 180 | "password", 181 | "username" 182 | ], 183 | "properties": { 184 | "password": { 185 | "type": "string" 186 | }, 187 | "username": { 188 | "type": "string" 189 | } 190 | } 191 | }, 192 | "schema.RefreshBodyParam": { 193 | "type": "object", 194 | "required": [ 195 | "refresh_token" 196 | ], 197 | "properties": { 198 | "refresh_token": { 199 | "type": "string" 200 | } 201 | } 202 | }, 203 | "schema.RegisterBodyParam": { 204 | "type": "object", 205 | "required": [ 206 | "email", 207 | "password", 208 | "username" 209 | ], 210 | "properties": { 211 | "email": { 212 | "type": "string" 213 | }, 214 | "password": { 215 | "type": "string" 216 | }, 217 | "role_id": { 218 | "type": "string" 219 | }, 220 | "username": { 221 | "type": "string" 222 | } 223 | } 224 | } 225 | }, 226 | "securityDefinitions": { 227 | "ApiKeyAuth": { 228 | "type": "apiKey", 229 | "name": "Authorization", 230 | "in": "header" 231 | }, 232 | "BasicAuth": { 233 | "type": "basic" 234 | } 235 | } 236 | }` 237 | 238 | type swaggerInfo struct { 239 | Version string 240 | Host string 241 | BasePath string 242 | Schemes []string 243 | Title string 244 | Description string 245 | } 246 | 247 | // SwaggerInfo holds exported Swagger Info so clients can modify it 248 | var SwaggerInfo = swaggerInfo{ 249 | Version: "1.0", 250 | Host: "", 251 | BasePath: "", 252 | Schemes: []string{}, 253 | Title: "Go Admin API Documents", 254 | Description: "Swagger API for Golang Admin API.", 255 | } 256 | 257 | type s struct{} 258 | 259 | func (s *s) ReadDoc() string { 260 | sInfo := SwaggerInfo 261 | sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1) 262 | 263 | t, err := template.New("swagger_info").Funcs(template.FuncMap{ 264 | "marshal": func(v interface{}) string { 265 | a, _ := json.Marshal(v) 266 | return string(a) 267 | }, 268 | }).Parse(doc) 269 | if err != nil { 270 | return doc 271 | } 272 | 273 | var tpl bytes.Buffer 274 | if err := t.Execute(&tpl, sInfo); err != nil { 275 | return doc 276 | } 277 | 278 | return tpl.String() 279 | } 280 | 281 | func init() { 282 | swag.Register(swag.Name, &s{}) 283 | } 284 | -------------------------------------------------------------------------------- /docs/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "Swagger API for Golang Admin API.", 5 | "title": "Go Admin API Documents", 6 | "contact": {}, 7 | "license": {}, 8 | "version": "1.0" 9 | }, 10 | "paths": { 11 | "/login": { 12 | "post": { 13 | "description": "api login", 14 | "consumes": [ 15 | "application/json" 16 | ], 17 | "produces": [ 18 | "application/json" 19 | ], 20 | "tags": [ 21 | "Auth" 22 | ], 23 | "summary": "api login", 24 | "parameters": [ 25 | { 26 | "description": "Body", 27 | "name": "body", 28 | "in": "body", 29 | "required": true, 30 | "schema": { 31 | "$ref": "#/definitions/schema.LoginBodyParam" 32 | } 33 | } 34 | ], 35 | "responses": { 36 | "200": { 37 | "description": "OK", 38 | "schema": { 39 | "$ref": "#/definitions/schema.BaseResponse" 40 | } 41 | } 42 | } 43 | } 44 | }, 45 | "/logout": { 46 | "post": { 47 | "security": [ 48 | { 49 | "ApiKeyAuth": [] 50 | } 51 | ], 52 | "description": "api logout", 53 | "consumes": [ 54 | "application/json" 55 | ], 56 | "produces": [ 57 | "application/json" 58 | ], 59 | "tags": [ 60 | "Auth" 61 | ], 62 | "summary": "api logout", 63 | "responses": { 64 | "200": { 65 | "description": "OK", 66 | "schema": { 67 | "$ref": "#/definitions/schema.BaseResponse" 68 | } 69 | } 70 | } 71 | } 72 | }, 73 | "/refresh": { 74 | "post": { 75 | "description": "api refresh token", 76 | "consumes": [ 77 | "application/json" 78 | ], 79 | "produces": [ 80 | "application/json" 81 | ], 82 | "tags": [ 83 | "Auth" 84 | ], 85 | "summary": "api refresh token", 86 | "parameters": [ 87 | { 88 | "description": "Body", 89 | "name": "body", 90 | "in": "body", 91 | "required": true, 92 | "schema": { 93 | "$ref": "#/definitions/schema.RefreshBodyParam" 94 | } 95 | } 96 | ], 97 | "responses": { 98 | "200": { 99 | "description": "OK", 100 | "schema": { 101 | "$ref": "#/definitions/schema.BaseResponse" 102 | } 103 | } 104 | } 105 | } 106 | }, 107 | "/register": { 108 | "post": { 109 | "description": "api register", 110 | "consumes": [ 111 | "application/json" 112 | ], 113 | "produces": [ 114 | "application/json" 115 | ], 116 | "tags": [ 117 | "Auth" 118 | ], 119 | "summary": "api register", 120 | "parameters": [ 121 | { 122 | "description": "Body", 123 | "name": "body", 124 | "in": "body", 125 | "required": true, 126 | "schema": { 127 | "$ref": "#/definitions/schema.RegisterBodyParam" 128 | } 129 | } 130 | ], 131 | "responses": { 132 | "200": { 133 | "description": "OK", 134 | "schema": { 135 | "$ref": "#/definitions/schema.BaseResponse" 136 | } 137 | } 138 | } 139 | } 140 | } 141 | }, 142 | "definitions": { 143 | "schema.BaseResponse": { 144 | "type": "object", 145 | "properties": { 146 | "code": { 147 | "type": "string" 148 | }, 149 | "data": { 150 | "type": "object" 151 | }, 152 | "message": { 153 | "type": "string" 154 | }, 155 | "status": { 156 | "type": "integer" 157 | } 158 | } 159 | }, 160 | "schema.LoginBodyParam": { 161 | "type": "object", 162 | "required": [ 163 | "password", 164 | "username" 165 | ], 166 | "properties": { 167 | "password": { 168 | "type": "string" 169 | }, 170 | "username": { 171 | "type": "string" 172 | } 173 | } 174 | }, 175 | "schema.RefreshBodyParam": { 176 | "type": "object", 177 | "required": [ 178 | "refresh_token" 179 | ], 180 | "properties": { 181 | "refresh_token": { 182 | "type": "string" 183 | } 184 | } 185 | }, 186 | "schema.RegisterBodyParam": { 187 | "type": "object", 188 | "required": [ 189 | "email", 190 | "password", 191 | "username" 192 | ], 193 | "properties": { 194 | "email": { 195 | "type": "string" 196 | }, 197 | "password": { 198 | "type": "string" 199 | }, 200 | "role_id": { 201 | "type": "string" 202 | }, 203 | "username": { 204 | "type": "string" 205 | } 206 | } 207 | } 208 | }, 209 | "securityDefinitions": { 210 | "ApiKeyAuth": { 211 | "type": "apiKey", 212 | "name": "Authorization", 213 | "in": "header" 214 | }, 215 | "BasicAuth": { 216 | "type": "basic" 217 | } 218 | } 219 | } -------------------------------------------------------------------------------- /docs/swagger.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | schema.BaseResponse: 3 | properties: 4 | code: 5 | type: string 6 | data: 7 | type: object 8 | message: 9 | type: string 10 | status: 11 | type: integer 12 | type: object 13 | schema.LoginBodyParam: 14 | properties: 15 | password: 16 | type: string 17 | username: 18 | type: string 19 | required: 20 | - password 21 | - username 22 | type: object 23 | schema.RefreshBodyParam: 24 | properties: 25 | refresh_token: 26 | type: string 27 | required: 28 | - refresh_token 29 | type: object 30 | schema.RegisterBodyParam: 31 | properties: 32 | email: 33 | type: string 34 | password: 35 | type: string 36 | role_id: 37 | type: string 38 | username: 39 | type: string 40 | required: 41 | - email 42 | - password 43 | - username 44 | type: object 45 | info: 46 | contact: {} 47 | description: Swagger API for Golang Admin API. 48 | license: {} 49 | title: Go Admin API Documents 50 | version: "1.0" 51 | paths: 52 | /login: 53 | post: 54 | consumes: 55 | - application/json 56 | description: api login 57 | parameters: 58 | - description: Body 59 | in: body 60 | name: body 61 | required: true 62 | schema: 63 | $ref: '#/definitions/schema.LoginBodyParam' 64 | produces: 65 | - application/json 66 | responses: 67 | "200": 68 | description: OK 69 | schema: 70 | $ref: '#/definitions/schema.BaseResponse' 71 | summary: api login 72 | tags: 73 | - Auth 74 | /logout: 75 | post: 76 | consumes: 77 | - application/json 78 | description: api logout 79 | produces: 80 | - application/json 81 | responses: 82 | "200": 83 | description: OK 84 | schema: 85 | $ref: '#/definitions/schema.BaseResponse' 86 | security: 87 | - ApiKeyAuth: [] 88 | summary: api logout 89 | tags: 90 | - Auth 91 | /refresh: 92 | post: 93 | consumes: 94 | - application/json 95 | description: api refresh token 96 | parameters: 97 | - description: Body 98 | in: body 99 | name: body 100 | required: true 101 | schema: 102 | $ref: '#/definitions/schema.RefreshBodyParam' 103 | produces: 104 | - application/json 105 | responses: 106 | "200": 107 | description: OK 108 | schema: 109 | $ref: '#/definitions/schema.BaseResponse' 110 | summary: api refresh token 111 | tags: 112 | - Auth 113 | /register: 114 | post: 115 | consumes: 116 | - application/json 117 | description: api register 118 | parameters: 119 | - description: Body 120 | in: body 121 | name: body 122 | required: true 123 | schema: 124 | $ref: '#/definitions/schema.RegisterBodyParam' 125 | produces: 126 | - application/json 127 | responses: 128 | "200": 129 | description: OK 130 | schema: 131 | $ref: '#/definitions/schema.BaseResponse' 132 | summary: api register 133 | tags: 134 | - Auth 135 | securityDefinitions: 136 | ApiKeyAuth: 137 | in: header 138 | name: Authorization 139 | type: apiKey 140 | BasicAuth: 141 | type: basic 142 | swagger: "2.0" 143 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/quangdangfit/go-admin 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc 7 | github.com/dgrijalva/jwt-go v3.2.0+incompatible 8 | github.com/gin-gonic/gin v1.6.3 9 | github.com/go-redis/redis/v8 v8.7.1 10 | github.com/golang/mock v1.3.1 11 | github.com/google/uuid v1.1.1 12 | github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a 13 | github.com/jinzhu/gorm v1.9.14 14 | github.com/json-iterator/go v1.1.9 15 | github.com/lib/pq v1.1.1 16 | github.com/pkg/errors v0.9.1 17 | github.com/quangdangfit/gocommon v0.9.0 18 | github.com/spf13/viper v1.7.0 19 | github.com/stretchr/testify v1.7.0 20 | github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 21 | github.com/swaggo/gin-swagger v1.2.0 22 | github.com/swaggo/swag v1.5.1 23 | go.uber.org/dig v1.10.0 24 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 25 | ) 26 | -------------------------------------------------------------------------------- /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.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= 4 | cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= 5 | cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= 6 | cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= 7 | cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= 8 | cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= 9 | cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= 10 | cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= 11 | cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= 12 | cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= 13 | dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= 14 | github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= 15 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 16 | github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= 17 | github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= 18 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= 19 | github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= 20 | github.com/PuerkitoBio/purell v1.1.0 h1:rmGxhojJlM0tuKtfdvliR84CFHljx9ag64t2xmVkjK4= 21 | github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= 22 | github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= 23 | github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= 24 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU= 25 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 26 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 27 | github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= 28 | github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= 29 | github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= 30 | github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= 31 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 32 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 33 | github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= 34 | github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= 35 | github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= 36 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= 37 | github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= 38 | github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 39 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 40 | github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= 41 | github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= 42 | github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= 43 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= 44 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= 45 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 46 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 47 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 48 | github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM= 49 | github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= 50 | github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= 51 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 52 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= 53 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= 54 | github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= 55 | github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y= 56 | github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= 57 | github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= 58 | github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= 59 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 60 | github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= 61 | github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= 62 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 63 | github.com/gin-contrib/gzip v0.0.1 h1:ezvKOL6jH+jlzdHNE4h9h8q8uMpDQjyl0NN0Jd7jozc= 64 | github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w= 65 | github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= 66 | github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= 67 | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= 68 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 69 | github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y= 70 | github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM= 71 | github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= 72 | github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= 73 | github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= 74 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 75 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 76 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 77 | github.com/go-openapi/jsonpointer v0.17.0 h1:nH6xp8XdXHx8dqveo0ZuJBluCO2qGrPbDNZ0dwoRHP0= 78 | github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= 79 | github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= 80 | github.com/go-openapi/jsonreference v0.19.0 h1:BqWKpV1dFd+AuiKlgtddwVIFQsuMpxfBDBHGfM2yNpk= 81 | github.com/go-openapi/jsonreference v0.19.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= 82 | github.com/go-openapi/spec v0.19.0 h1:A4SZ6IWh3lnjH0rG0Z5lkxazMGBECtrZcbyYQi+64k4= 83 | github.com/go-openapi/spec v0.19.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= 84 | github.com/go-openapi/swag v0.17.0 h1:iqrgMg7Q7SvtbWLlltPrkMs0UBJI6oTSs79JFRUi880= 85 | github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= 86 | github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= 87 | github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 88 | github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= 89 | github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= 90 | github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= 91 | github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= 92 | github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= 93 | github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= 94 | github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= 95 | github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= 96 | github.com/go-redis/redis/v8 v8.7.1 h1:8IYi6RO83fNcG5amcUUYTN/qH2h4OjZHlim3KWGFSsA= 97 | github.com/go-redis/redis/v8 v8.7.1/go.mod h1:BRxHBWn3pO3CfjyX6vAoyeRmCquvxr6QG+2onGV2gYs= 98 | github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= 99 | github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= 100 | github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= 101 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 102 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 103 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= 104 | github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= 105 | github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= 106 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 107 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 108 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 109 | github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 110 | github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= 111 | github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= 112 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 113 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 114 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 115 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 116 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 117 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 118 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 119 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 120 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 121 | github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= 122 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 123 | github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 124 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 125 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 126 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 127 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 128 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 129 | github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= 130 | github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 131 | github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= 132 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 133 | github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= 134 | github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 135 | github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 136 | github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= 137 | github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= 138 | github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 139 | github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= 140 | github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= 141 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= 142 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= 143 | github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 144 | github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= 145 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= 146 | github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= 147 | github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= 148 | github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= 149 | github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= 150 | github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= 151 | github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= 152 | github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= 153 | github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= 154 | github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= 155 | github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= 156 | github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= 157 | github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= 158 | github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= 159 | github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= 160 | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 161 | github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 162 | github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= 163 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 164 | github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= 165 | github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= 166 | github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= 167 | github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= 168 | github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= 169 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= 170 | github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a h1:zPPuIq2jAWWPTrGt70eK/BSch+gFAGrNzecsoENgu2o= 171 | github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a/go.mod h1:yL958EeXv8Ylng6IfnvG4oflryUi3vgA3xPs9hmII1s= 172 | github.com/jinzhu/gorm v1.9.14 h1:Kg3ShyTPcM6nzVo148fRrcMO6MNKuqtOUwnzqMgVniM= 173 | github.com/jinzhu/gorm v1.9.14/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs= 174 | github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= 175 | github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= 176 | github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M= 177 | github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= 178 | github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= 179 | github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 180 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 181 | github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= 182 | github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 183 | github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= 184 | github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= 185 | github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= 186 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 187 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= 188 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 189 | github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= 190 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 191 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 192 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 193 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 194 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 195 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 196 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 197 | github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= 198 | github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= 199 | github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4= 200 | github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= 201 | github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= 202 | github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 203 | github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic= 204 | github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= 205 | github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= 206 | github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 207 | github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 208 | github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 209 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 210 | github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= 211 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 212 | github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA= 213 | github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= 214 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 215 | github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= 216 | github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= 217 | github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 218 | github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= 219 | github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= 220 | github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= 221 | github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 222 | github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= 223 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 224 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 225 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= 226 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 227 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 228 | github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= 229 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 230 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 231 | github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= 232 | github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= 233 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= 234 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 235 | github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= 236 | github.com/onsi/ginkgo v1.15.0 h1:1V1NfVQR87RtWAgp1lv9JZJ5Jap+XFGKPi00andXGi4= 237 | github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg= 238 | github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= 239 | github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= 240 | github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ= 241 | github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= 242 | github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= 243 | github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= 244 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 245 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 246 | github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= 247 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 248 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 249 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 250 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 251 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 252 | github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= 253 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 254 | github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= 255 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 256 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 257 | github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= 258 | github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 259 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 260 | github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 261 | github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= 262 | github.com/quangdangfit/gocommon v0.9.0 h1:6KyaQqv/Aq1u2LzSToamkCy0ynvOh6j1x7hMlxQWouE= 263 | github.com/quangdangfit/gocommon v0.9.0/go.mod h1:1PU2PmUQ1xmOXE6e/ULDiDMevFqj1hbXALTPACWziiw= 264 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= 265 | github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= 266 | github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= 267 | github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= 268 | github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo= 269 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 270 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= 271 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= 272 | github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= 273 | github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= 274 | github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= 275 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ= 276 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 277 | github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= 278 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 279 | github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= 280 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= 281 | github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= 282 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= 283 | github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= 284 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 285 | github.com/spf13/viper v1.7.0 h1:xVKxvI7ouOI5I+U9s2eeiUfMaWBVoXA3AWskkrqK0VM= 286 | github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= 287 | github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= 288 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 289 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 290 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 291 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 292 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 293 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 294 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 295 | github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= 296 | github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= 297 | github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 h1:PyYN9JH5jY9j6av01SpfRMb+1DWg/i3MbGOKPxJ2wjM= 298 | github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14/go.mod h1:gxQT6pBGRuIGunNf/+tSOB5OHvguWi8Tbt82WOkf35E= 299 | github.com/swaggo/gin-swagger v1.2.0 h1:YskZXEiv51fjOMTsXrOetAjrMDfFaXD79PEoQBOe2W0= 300 | github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05Nn6vPhc7OI= 301 | github.com/swaggo/swag v1.5.1 h1:2Agm8I4K5qb00620mHq0VJ05/KT4FtmALPIcQR9lEZM= 302 | github.com/swaggo/swag v1.5.1/go.mod h1:1Bl9F/ZBpVWh22nY0zmYyASPO1lI/zIwRDrpZU+tv8Y= 303 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= 304 | github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= 305 | github.com/ugorji/go v1.1.5-pre/go.mod h1:FwP/aQVg39TXzItUBMwnWp9T9gPQnXw4Poh4/oBQZ/0= 306 | github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= 307 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= 308 | github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= 309 | github.com/ugorji/go/codec v1.1.5-pre/go.mod h1:tULtS6Gy1AE1yCENaw4Vb//HLH5njI2tfCQDUqRd8fI= 310 | github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= 311 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= 312 | github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= 313 | github.com/vanng822/go-solr v0.10.0/go.mod h1:FSglzTPzoNVKTXP+SqEQiiz284cKzcKpeRXmwPa81wc= 314 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= 315 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 316 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= 317 | go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= 318 | go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= 319 | go.opentelemetry.io/otel v0.18.0 h1:d5Of7+Zw4ANFOJB+TIn2K3QWsgS2Ht7OU9DqZHI6qu8= 320 | go.opentelemetry.io/otel v0.18.0/go.mod h1:PT5zQj4lTsR1YeARt8YNKcFb88/c2IKoSABK9mX0r78= 321 | go.opentelemetry.io/otel/metric v0.18.0 h1:yuZCmY9e1ZTaMlZXLrrbAPmYW6tW1A5ozOZeOYGaTaY= 322 | go.opentelemetry.io/otel/metric v0.18.0/go.mod h1:kEH2QtzAyBy3xDVQfGZKIcok4ZZFvd5xyKPfPcuK6pE= 323 | go.opentelemetry.io/otel/oteltest v0.18.0 h1:FbKDFm/LnQDOHuGjED+fy3s5YMVg0z019GJ9Er66hYo= 324 | go.opentelemetry.io/otel/oteltest v0.18.0/go.mod h1:NyierCU3/G8DLTva7KRzGii2fdxdR89zXKH1bNWY7Bo= 325 | go.opentelemetry.io/otel/trace v0.18.0 h1:ilCfc/fptVKaDMK1vWk0elxpolurJbEgey9J6g6s+wk= 326 | go.opentelemetry.io/otel/trace v0.18.0/go.mod h1:FzdUu3BPwZSZebfQ1vl5/tAa8LyMLXSJN57AXIt/iDk= 327 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 328 | go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk= 329 | go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= 330 | go.uber.org/dig v1.10.0 h1:yLmDDj9/zuDjv3gz8GQGviXMs9TfysIUMUilCpgzUJY= 331 | go.uber.org/dig v1.10.0/go.mod h1:X34SnWGr8Fyla9zQNO2GSO2D+TIuqB14OS8JhYocIyw= 332 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= 333 | go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A= 334 | go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= 335 | go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= 336 | go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= 337 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= 338 | go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM= 339 | go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= 340 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 341 | golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 342 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 343 | golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 344 | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 345 | golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 346 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 347 | golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd h1:GGJVjV8waZKRHrgwvtH66z9ZGVurTD1MT0n1Bb+q4aM= 348 | golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 349 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= 350 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 351 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 352 | golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 353 | golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= 354 | golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= 355 | golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= 356 | golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= 357 | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 358 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 359 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 360 | golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 361 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 362 | golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 363 | golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 364 | golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= 365 | golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 366 | golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= 367 | golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= 368 | golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= 369 | golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= 370 | golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= 371 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 372 | golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 373 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 374 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 375 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 376 | golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 377 | golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 378 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 379 | golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 380 | golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 381 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 382 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 383 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 384 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 385 | golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 386 | golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 387 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 388 | golang.org/x/net v0.0.0-20190611141213-3f473d35a33a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 389 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 390 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 391 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= 392 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 393 | golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 394 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 395 | golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U= 396 | golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 397 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 398 | golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 399 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 400 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 401 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 402 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 403 | golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 404 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 405 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 406 | golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 407 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 408 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 409 | golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 410 | golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 411 | golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 412 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 413 | golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 414 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 415 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 416 | golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 417 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 418 | golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 419 | golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 420 | golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 421 | golang.org/x/sys v0.0.0-20190610200419-93c9922d18ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 422 | golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 423 | golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 424 | golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 425 | golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 426 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 427 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= 428 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 429 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 430 | golang.org/x/sys v0.0.0-20210112080510-489259a85091 h1:DMyOG0U+gKfu8JZzg2UQe9MeaC1X+xQWlAKcRnjxjCw= 431 | golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 432 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 433 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 434 | golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= 435 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 436 | golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= 437 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 438 | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 439 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 440 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 441 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 442 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 443 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 444 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 445 | golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 446 | golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 447 | golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 448 | golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 449 | golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 450 | golang.org/x/tools v0.0.0-20190606050223-4d9ae51c2468/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 451 | golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 452 | golang.org/x/tools v0.0.0-20190611222205-d73e1c7e250b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 453 | golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 454 | golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 455 | golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 456 | golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 457 | golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 458 | golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 459 | golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 460 | golang.org/x/tools v0.0.0-20191030062658-86caa796c7ab/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 461 | golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 462 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 463 | golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e h1:4nW4NLDYnU28ojHaHO8OVxFHk/aQ33U01a9cjED+pzE= 464 | golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= 465 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 466 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 467 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= 468 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 469 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= 470 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 471 | google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= 472 | google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= 473 | google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 474 | google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 475 | google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 476 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 477 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 478 | google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 479 | google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= 480 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 481 | google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 482 | google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 483 | google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 484 | google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 485 | google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 486 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 487 | google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= 488 | google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a h1:Ob5/580gVHBJZgXnff1cZDbG+xLtMVE5mDRTe+nIsX4= 489 | google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 490 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 491 | google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= 492 | google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 493 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 494 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 495 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 496 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 497 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 498 | google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= 499 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 500 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 501 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 502 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 503 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 504 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 505 | gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= 506 | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= 507 | gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= 508 | gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= 509 | gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= 510 | gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 511 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= 512 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= 513 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= 514 | gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= 515 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 516 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 517 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 518 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 519 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 520 | gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= 521 | gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 522 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 523 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 524 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 525 | honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 526 | honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 527 | honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= 528 | honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= 529 | rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= 530 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "net/http" 6 | "os" 7 | "os/signal" 8 | "syscall" 9 | "time" 10 | 11 | _ "github.com/jinzhu/gorm/dialects/postgres" 12 | _ "github.com/lib/pq" 13 | "github.com/quangdangfit/gocommon/logger" 14 | 15 | "github.com/quangdangfit/go-admin/app" 16 | "github.com/quangdangfit/go-admin/app/migration" 17 | _ "github.com/quangdangfit/go-admin/docs" 18 | ) 19 | 20 | // @title Go Admin API Documents 21 | // @version 1.0 22 | // @description Swagger API for Golang Admin API. 23 | 24 | // @securityDefinitions.basic BasicAuth 25 | // @in header 26 | // @name Authorization 27 | 28 | // @securityDefinitions.apikey ApiKeyAuth 29 | // @in header 30 | // @name Authorization 31 | 32 | const ( 33 | ProductionEnv = "production" 34 | ) 35 | 36 | func main() { 37 | logger.Initialize(ProductionEnv) 38 | container := app.BuildContainer() 39 | engine := app.InitGinEngine(container) 40 | 41 | err := migration.Migrate(container) 42 | if err != nil { 43 | logger.Warn("Failed to migrate data: ", err) 44 | } 45 | 46 | server := &http.Server{ 47 | Addr: ":8888", 48 | Handler: engine, 49 | } 50 | 51 | go func() { 52 | // service connections 53 | logger.Info("Listen at:", server.Addr) 54 | if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { 55 | logger.Fatalf("Error: %s\n", err) 56 | } 57 | }() 58 | 59 | // Wait for interrupt signal to gracefully shutdown the server with 60 | // a timeout of 1 seconds. 61 | quit := make(chan os.Signal) 62 | // kill (no param) default send syscanll.SIGTERM 63 | // kill -2 is syscall.SIGINT 64 | // kill -9 is syscall. SIGKILL but can"t be catch, so don't need add it 65 | signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) 66 | <-quit 67 | logger.Info("Shutdown Server ...") 68 | 69 | ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) 70 | defer cancel() 71 | if err := server.Shutdown(ctx); err != nil { 72 | logger.Fatal("Server Shutdown: ", err) 73 | } 74 | // catching ctx.Done(). timeout of 1 seconds. 75 | select { 76 | case <-ctx.Done(): 77 | logger.Info("Timeout of 1 seconds.") 78 | } 79 | logger.Info("Server exiting") 80 | } 81 | -------------------------------------------------------------------------------- /pkg/app/request.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "context" 5 | "strings" 6 | 7 | "github.com/gin-gonic/gin" 8 | ) 9 | 10 | // constants app request 11 | const ( 12 | prefix = "gin-go" 13 | // UserIDKey 14 | UserIDKey = prefix + "/user-id" 15 | ReqBodyKey = prefix + "/req-body" 16 | ResBodyKey = prefix + "/res-body" 17 | LoggerReqBodyKey = prefix + "/logger-req-body" 18 | ) 19 | 20 | // GetToken from header 21 | func GetToken(c *gin.Context) string { 22 | var token string 23 | auth := c.GetHeader("Authorization") 24 | prefix := "Bearer " 25 | if auth != "" && strings.HasPrefix(auth, prefix) { 26 | token = auth[len(prefix):] 27 | } 28 | return token 29 | } 30 | 31 | // GetUserID get user id from context 32 | func GetUserID(c context.Context) string { 33 | userID := c.Value(UserIDKey) 34 | if userID == nil { 35 | return "" 36 | } 37 | return userID.(string) 38 | } 39 | 40 | // SetUserID to context 41 | func SetUserID(c *gin.Context, userID string) { 42 | c.Set(UserIDKey, userID) 43 | } 44 | -------------------------------------------------------------------------------- /pkg/errors/code.go: -------------------------------------------------------------------------------- 1 | package errors 2 | 3 | // ErrorCodeMap define map error and error message 4 | var ErrorCodeMap = map[ErrorType]string{ 5 | Success: "SUCCESS", 6 | Error: "ERROR", 7 | InvalidParams: "INVALID_PARAMS", 8 | ErrorAuthCheckTokenFail: "ERROR_AUTH_CHECK_TOKEN_FAIL", 9 | ErrorAuthCheckTokenTimeout: "ERROR_AUTH_CHECK_TOKEN_TIMEOUT", 10 | ErrorAuthToken: "ERROR_AUTH_TOKEN", 11 | ErrorAuth: "ERROR_AUTH", 12 | ErrorInternalServer: "ERROR_INTERNAL_SERVER", 13 | ErrorExistEmail: "ERROR_EXIST_EMAIL", 14 | ErrorBadRequest: "ERROR_BAD_REQUEST", 15 | ErrorInvalidParent: "ERROR_INVALID_PARENT", 16 | ErrorAllowDeleteWithChild: "ERROR_ALLOW_DELETE_WITH_CHILD", 17 | ErrorNotAllowDelete: "ERROR_NOT_ALLOW_DELETE", 18 | ErrorInvalidOldPass: "ERROR_INVALID_OLD_PASS", 19 | ErrorNotFound: "ERROR_NOT_FOUND", 20 | ErrorPasswordRequired: "ERROR_PASSWORD_REQUIRED", 21 | ErrorExistMenuName: "ERROR_EXIST_MENU_NAME", 22 | ErrorUserDisabled: "ERROR_USER_DISABLED", 23 | ErrorNoPermission: "ERROR_NO_PERMISSION", 24 | ErrorMethodNotAllow: "ERROR_METHOD_NOT_ALLOW", 25 | ErrorTooManyRequest: "ERROR_TOO_MANY_REQUEST", 26 | ErrorLoginFailed: "ERROR_LOGIN_FAILED", 27 | ErrorExistRole: "ERROR_EXIST_ROLE", 28 | ErrorNotExistUser: "ERROR_NOT_EXIST_USER", 29 | ErrorExistRoleUser: "ERROR_EXIST_ROLE_USER", 30 | ErrorNotExistRole: "ERROR_NOT_EXIST_ROLE", 31 | ErrorTokenExpired: "ERROR_TOKEN_EXPIRED", 32 | ErrorTokenInvalid: "ERROR_TOKEN_INVALID", 33 | ErrorTokenMalformed: "ERROR_TOKEN_MALFORMED", 34 | } 35 | 36 | // GetCode get error code 37 | func GetCode(status int) string { 38 | msg, ok := ErrorCodeMap[ErrorType(status)] 39 | if ok { 40 | return msg 41 | } 42 | return ErrorCodeMap[Error] 43 | } 44 | -------------------------------------------------------------------------------- /pkg/errors/context.go: -------------------------------------------------------------------------------- 1 | package errors 2 | 3 | type errorContext struct { 4 | Field string 5 | Message string 6 | } 7 | 8 | // AddErrorContext adds a context to an error 9 | func AddErrorContext(err error, field, message string) error { 10 | context := errorContext{Field: field, Message: message} 11 | if customErr, ok := err.(CustomError); ok { 12 | return CustomError{ 13 | errType: customErr.errType, 14 | wrappedError: customErr.wrappedError, 15 | context: context, 16 | } 17 | } 18 | 19 | return CustomError{ 20 | errType: Error, 21 | wrappedError: err, 22 | context: context, 23 | } 24 | } 25 | 26 | // GetErrorContext returns the error context 27 | func GetErrorContext(err error) map[string]string { 28 | emptyContext := errorContext{} 29 | if customErr, ok := err.(CustomError); ok || customErr.context != emptyContext { 30 | 31 | return map[string]string{ 32 | "field": customErr.context.Field, 33 | "message": customErr.context.Message, 34 | } 35 | } 36 | 37 | return nil 38 | } 39 | 40 | // GetType returns the error type 41 | func GetType(err error) ErrorType { 42 | if customErr, ok := err.(CustomError); ok { 43 | return customErr.errType 44 | } 45 | 46 | return Error 47 | } 48 | -------------------------------------------------------------------------------- /pkg/errors/errors.go: -------------------------------------------------------------------------------- 1 | package errors 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/pkg/errors" 7 | ) 8 | 9 | //Reference article: 10 | //https://hackernoon.com/golang-handling-errors-gracefully-8e27f1db729f 11 | 12 | // CustomError struct 13 | type CustomError struct { 14 | errType ErrorType 15 | wrappedError error 16 | context errorContext 17 | } 18 | 19 | // Error return error message 20 | func (err CustomError) Error() string { 21 | return err.wrappedError.Error() 22 | } 23 | 24 | // Stacktrace return error stacktrace message 25 | func (err CustomError) Stacktrace() string { 26 | return fmt.Sprintf("%+v\n", err.wrappedError) 27 | } 28 | 29 | // New creates a no type error 30 | func New(msg string) error { 31 | return CustomError{errType: Error, wrappedError: errors.New(msg)} 32 | } 33 | 34 | // Newf creates a no type error with formatted message 35 | func Newf(msg string, args ...interface{}) error { 36 | return CustomError{errType: Error, wrappedError: errors.New(fmt.Sprintf(msg, args...))} 37 | } 38 | 39 | // Wrap wrans an error with a string 40 | func Wrap(err error, msg string) error { 41 | return Wrapf(err, msg) 42 | } 43 | 44 | // Cause gives the original error 45 | func Cause(err error) error { 46 | return errors.Cause(err) 47 | } 48 | 49 | // Wrapf wraps an error with format string 50 | func Wrapf(err error, msg string, args ...interface{}) error { 51 | wrappedError := errors.Wrapf(err, msg, args...) 52 | if customErr, ok := err.(CustomError); ok { 53 | return CustomError{ 54 | errType: customErr.errType, 55 | wrappedError: wrappedError, 56 | context: customErr.context, 57 | } 58 | } 59 | 60 | return CustomError{errType: Error, wrappedError: wrappedError} 61 | } 62 | 63 | // Stack get stacktrace of error 64 | func Stack(err error) string { 65 | if customErr, ok := err.(CustomError); ok { 66 | return fmt.Sprintf("%+v\n", customErr.wrappedError) 67 | } 68 | return fmt.Sprintf("%+v\n", errors.WithStack(err)) 69 | } 70 | -------------------------------------------------------------------------------- /pkg/errors/message.go: -------------------------------------------------------------------------------- 1 | package errors 2 | 3 | // MsgMap message map 4 | var MsgMap = map[ErrorType]string{ 5 | Success: "OK", 6 | InvalidParams: "Request parameter error - %s", 7 | ErrorAuthCheckTokenFail: "Token authentication failed", 8 | ErrorAuthCheckTokenTimeout: "Token time out", 9 | ErrorAuthToken: "Token build failed", 10 | ErrorAuth: "Token error", 11 | Error: "Error occurred", 12 | ErrorInternalServer: "Server error", 13 | ErrorExistEmail: "The Email Address entered already exists in the system", 14 | ErrorBadRequest: "Request error", 15 | ErrorInvalidParent: "Invalid parent node", 16 | ErrorAllowDeleteWithChild: "Contains children, cannot be deleted", 17 | ErrorNotAllowDelete: "Resources are not allowed to be deleted", 18 | ErrorInvalidOldPass: "Old password is incorrect", 19 | ErrorNotFound: "Resource does not exist", 20 | ErrorPasswordRequired: "Password is required", 21 | ErrorExistMenuName: "Menu name already exists", 22 | ErrorUserDisabled: "User is disabled, please contact administrator", 23 | ErrorNoPermission: "No access", 24 | ErrorMethodNotAllow: "Method is not allowed", 25 | ErrorTooManyRequest: "Requests are too frequent", 26 | ErrorLoginFailed: "Email or password is invalid", 27 | ErrorExistRole: "Role name already exists", 28 | ErrorNotExistUser: "Account is invalid", 29 | ErrorExistRoleUser: "The role has been given to the user and is not allowed to be deleted", 30 | ErrorNotExistRole: "Role user is disabled, please contact administrator", 31 | ErrorTokenExpired: "Token is expired", 32 | ErrorTokenInvalid: "Token is invalid", 33 | ErrorTokenMalformed: "That's not even a token", 34 | } 35 | 36 | // GetMsg from status 37 | func GetMsg(status int) string { 38 | msg, ok := MsgMap[ErrorType(status)] 39 | if ok { 40 | return msg 41 | } 42 | return MsgMap[Error] 43 | } 44 | -------------------------------------------------------------------------------- /pkg/errors/types.go: -------------------------------------------------------------------------------- 1 | package errors 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/pkg/errors" 7 | ) 8 | 9 | // constants define error types 10 | const ( 11 | Success ErrorType = 200 12 | Error ErrorType = 500 13 | InvalidParams ErrorType = 400 14 | ErrorBadRequest ErrorType = 421 15 | ErrorNoPermission ErrorType = 403 16 | ErrorNotFound ErrorType = 404 17 | ErrorMethodNotAllow ErrorType = 405 18 | ErrorInvalidParent ErrorType = 409 19 | ErrorAllowDeleteWithChild ErrorType = 410 20 | ErrorNotAllowDelete ErrorType = 411 21 | ErrorUserDisabled ErrorType = 412 22 | ErrorExistMenuName ErrorType = 413 23 | ErrorExistRole ErrorType = 414 24 | ErrorExistRoleUser ErrorType = 415 25 | ErrorNotExistUser ErrorType = 416 26 | ErrorLoginFailed ErrorType = 422 27 | ErrorInvalidOldPass ErrorType = 423 28 | ErrorPasswordRequired ErrorType = 424 29 | ErrorTooManyRequest ErrorType = 429 30 | ErrorInternalServer ErrorType = 512 31 | ErrorAuthCheckTokenFail ErrorType = 401 32 | ErrorAuthCheckTokenTimeout ErrorType = 402 33 | ErrorAuthToken ErrorType = 408 34 | ErrorAuth ErrorType = 407 35 | ErrorExistEmail ErrorType = 430 36 | ErrorNotExistRole ErrorType = 431 37 | ErrorTokenExpired ErrorType = 461 38 | ErrorTokenInvalid ErrorType = 462 39 | ErrorTokenMalformed ErrorType = 463 40 | 41 | // System errors 42 | ErrorMarshal ErrorType = iota + 1000 43 | ErrorUnmarshal 44 | ErrorDatabaseGet 45 | ErrorDatabaseCreate 46 | ErrorDatabaseUpdate 47 | ErrorDatabaseDelete 48 | 49 | ErrorInvalidPassword 50 | ) 51 | 52 | // ErrorType type 53 | type ErrorType int 54 | 55 | // New error 56 | func (errType ErrorType) New() error { 57 | return CustomError{ 58 | errType: errType, 59 | wrappedError: fmt.Errorf(GetMsg(int(errType))), 60 | } 61 | } 62 | 63 | // Newm new error with message 64 | func (errType ErrorType) Newm(msg string) error { 65 | return CustomError{ 66 | errType: errType, 67 | wrappedError: errors.New(msg), 68 | } 69 | } 70 | 71 | // Newf creates a new CustomError with formatted message 72 | func (errType ErrorType) Newf(msg string, args ...interface{}) error { 73 | err := fmt.Errorf(msg, args...) 74 | 75 | return CustomError{ 76 | errType: errType, 77 | wrappedError: err, 78 | } 79 | } 80 | 81 | // Wrap creates a new wrapped error 82 | func (errType ErrorType) Wrap(err error, msg string) error { 83 | return errType.Wrapf(err, msg) 84 | } 85 | 86 | // Wrapf creates a new wrapped error with formatted message 87 | func (errType ErrorType) Wrapf(err error, msg string, args ...interface{}) error { 88 | newErr := errors.Wrapf(err, msg, args...) 89 | 90 | return CustomError{ 91 | errType: errType, 92 | wrappedError: newErr, 93 | } 94 | } 95 | 96 | // Define some template errors 97 | var ( 98 | ErrMethodNotAllow = ErrorMethodNotAllow.New() 99 | ErrNoPermission = ErrorNoPermission.New() 100 | ErrNotFound = ErrorNotFound.New() 101 | ErrTokenExpired = ErrorTokenExpired.New() 102 | ErrTokenInvalid = ErrorTokenInvalid.New() 103 | ErrTokenMalformed = ErrorTokenMalformed.New() 104 | ) 105 | -------------------------------------------------------------------------------- /pkg/http/model.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | // Response body 4 | type Response struct { 5 | Error error 6 | Data interface{} 7 | } 8 | 9 | // BaseResponse body 10 | type BaseResponse struct { 11 | Status int `json:"status"` 12 | Code string `json:"code"` 13 | Message string `json:"message"` 14 | } 15 | -------------------------------------------------------------------------------- /pkg/http/wrapper/gin.go: -------------------------------------------------------------------------------- 1 | package wrapper 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gin-gonic/gin" 7 | 8 | "github.com/quangdangfit/go-admin/pkg/errors" 9 | gohttp "github.com/quangdangfit/go-admin/pkg/http" 10 | ) 11 | 12 | // constants wrapper http 13 | const ( 14 | DataField = "data" 15 | TraceIDField = "trace_id" 16 | StatusField = "status" 17 | CodeField = "code" 18 | MessageField = "message" 19 | ) 20 | 21 | // GinHandlerFn gin handler function 22 | type GinHandlerFn func(c *gin.Context) gohttp.Response 23 | 24 | // Wrap return new gin.HandlerFunc by GinHandlerFn 25 | func Wrap(fn GinHandlerFn) gin.HandlerFunc { 26 | return func(c *gin.Context) { 27 | // handle req 28 | res := fn(c) 29 | 30 | Translate(c, res) 31 | } 32 | } 33 | 34 | // Translate gohttp.Response to response 35 | func Translate(c *gin.Context, res gohttp.Response) { 36 | result := gin.H{} 37 | if _, ok := res.Error.(errors.CustomError); ok { 38 | status := int(errors.GetType(res.Error)) 39 | result[StatusField] = status 40 | result[MessageField] = errors.GetMsg(status) 41 | result[CodeField] = errors.GetCode(status) 42 | } 43 | 44 | // get data 45 | if res.Data != nil { 46 | result[DataField] = res.Data 47 | } 48 | 49 | c.JSON(http.StatusOK, result) 50 | } 51 | -------------------------------------------------------------------------------- /pkg/jwt/jwt_auth.go: -------------------------------------------------------------------------------- 1 | package jwt 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/dgrijalva/jwt-go" 7 | 8 | "github.com/quangdangfit/go-admin/pkg/errors" 9 | ) 10 | 11 | // IJWTAuth interface 12 | type IJWTAuth interface { 13 | GenerateToken(userID string) (TokenInfo, error) 14 | RefreshToken(refreshToken string) (TokenInfo, error) 15 | ParseUserID(accessToken string, refresh bool) (string, error) 16 | } 17 | 18 | const defaultKey = "gin-go" 19 | const defaultRefreshKey = "refresh-gin-go" 20 | 21 | var defaultOptions = options{ 22 | tokenType: "Bearer", 23 | expired: 7200, 24 | signingMethod: jwt.SigningMethodHS512, 25 | signingKey: []byte(defaultKey), 26 | keyFunc: func(t *jwt.Token) (interface{}, error) { 27 | if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok { 28 | return nil, errors.ErrTokenInvalid 29 | } 30 | return []byte(defaultKey), nil 31 | }, 32 | keyFuncRefresh: func(t *jwt.Token) (interface{}, error) { 33 | if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok { 34 | return nil, errors.ErrTokenInvalid 35 | } 36 | return []byte(defaultRefreshKey), nil 37 | }, 38 | expiredRefresh: 24, 39 | signingRefreshKey: []byte(defaultKey), 40 | } 41 | 42 | // NewJWTAuth return new Auth pointer 43 | func NewJWTAuth(opts ...Option) *Auth { 44 | o := defaultOptions 45 | for _, opt := range opts { 46 | opt(&o) 47 | } 48 | return &Auth{ 49 | opts: &o, 50 | } 51 | } 52 | 53 | // Auth struct 54 | type Auth struct { 55 | opts *options 56 | } 57 | type options struct { 58 | signingMethod jwt.SigningMethod 59 | signingKey interface{} 60 | keyFunc jwt.Keyfunc 61 | expired int 62 | tokenType string 63 | keyFuncRefresh jwt.Keyfunc 64 | expiredRefresh int 65 | signingRefreshKey interface{} 66 | } 67 | 68 | // Option jwt option 69 | type Option func(*options) 70 | 71 | // WithExpired set expired time 72 | func WithExpired(expired int) Option { 73 | return func(o *options) { 74 | o.expired = expired 75 | } 76 | } 77 | 78 | // WithKeyFunc set key function 79 | func WithKeyFunc(keyFunc jwt.Keyfunc) Option { 80 | return func(o *options) { 81 | o.keyFunc = keyFunc 82 | } 83 | } 84 | 85 | // WithSigningKey set signing key 86 | func WithSigningKey(key interface{}) Option { 87 | return func(o *options) { 88 | o.signingKey = key 89 | } 90 | } 91 | 92 | // WithExpiredRefresh set expired for refresh token 93 | func WithExpiredRefresh(expired int) Option { 94 | return func(o *options) { 95 | o.expiredRefresh = expired 96 | } 97 | } 98 | 99 | // WithKeyFuncRefresh set key function for refresh token 100 | func WithKeyFuncRefresh(keyFunc jwt.Keyfunc) Option { 101 | return func(o *options) { 102 | o.keyFuncRefresh = keyFunc 103 | } 104 | } 105 | 106 | // WithSigningKeyRefresh set signing key for refresh token 107 | func WithSigningKeyRefresh(key interface{}) Option { 108 | return func(o *options) { 109 | o.signingRefreshKey = key 110 | } 111 | } 112 | 113 | // GenerateToken return new TokenInfo, generate new access and refresh token 114 | func (a *Auth) GenerateToken(userID string) (TokenInfo, error) { 115 | accessToken, err := a.generateAccess(userID) 116 | if err != nil { 117 | return nil, err 118 | } 119 | 120 | refreshToken, err := a.generateRefresh(userID) 121 | if err != nil { 122 | return nil, err 123 | } 124 | tokenInfo := &tokenInfo{ 125 | TokenType: a.opts.tokenType, 126 | AccessToken: accessToken, 127 | RefreshToken: refreshToken, 128 | } 129 | return tokenInfo, nil 130 | } 131 | 132 | // parseToken parse claims from token 133 | func (a *Auth) parseToken(tokenString string, refresh bool) (*jwt.StandardClaims, error) { 134 | option := a.opts.keyFunc 135 | if refresh == true { 136 | option = a.opts.keyFuncRefresh 137 | } 138 | token, err := jwt.ParseWithClaims(tokenString, &jwt.StandardClaims{}, option) 139 | 140 | if err != nil { 141 | if ve, ok := err.(*jwt.ValidationError); ok { 142 | if ve.Errors&jwt.ValidationErrorMalformed != 0 { 143 | return nil, errors.ErrTokenMalformed 144 | } else if ve.Errors&jwt.ValidationErrorExpired != 0 { 145 | // Token is expired 146 | return nil, errors.ErrTokenExpired 147 | } else if ve.Errors&jwt.ValidationErrorNotValidYet != 0 { 148 | return nil, errors.ErrTokenInvalid 149 | } else { 150 | return nil, errors.ErrTokenInvalid 151 | } 152 | } 153 | } else if !token.Valid { 154 | return nil, errors.ErrTokenInvalid 155 | } 156 | 157 | return token.Claims.(*jwt.StandardClaims), nil 158 | } 159 | 160 | // ParseUserID parse user_id from token 161 | func (a *Auth) ParseUserID(tokenString string, refresh bool) (string, error) { 162 | claims, err := a.parseToken(tokenString, refresh) 163 | if err != nil { 164 | return "", err 165 | } 166 | return claims.Subject, nil 167 | } 168 | 169 | // RefreshToken refresh token, return new TokenInfo 170 | func (a *Auth) RefreshToken(refreshToken string) (TokenInfo, error) { 171 | userID, err := a.ParseUserID(refreshToken, true) 172 | if err != nil { 173 | if err == errors.ErrTokenExpired { 174 | return a.GenerateToken(userID) 175 | } 176 | return nil, err 177 | } 178 | 179 | accessToken, err := a.generateAccess(userID) 180 | if err != nil { 181 | return nil, err 182 | } 183 | 184 | tokenInfo := &tokenInfo{ 185 | TokenType: a.opts.tokenType, 186 | AccessToken: accessToken, 187 | RefreshToken: refreshToken, 188 | } 189 | return tokenInfo, nil 190 | } 191 | 192 | // generateAccess generate access token 193 | func (a *Auth) generateAccess(userID string) (string, error) { 194 | now := time.Now() 195 | token := jwt.NewWithClaims(a.opts.signingMethod, jwt.StandardClaims{ 196 | IssuedAt: now.Unix(), 197 | ExpiresAt: now.Add(time.Duration(a.opts.expired) * time.Second).Unix(), 198 | NotBefore: now.Unix(), 199 | Subject: userID, 200 | }) 201 | tokenString, err := token.SignedString(a.opts.signingKey) 202 | if err != nil { 203 | return "", errors.New("generate token fail") 204 | } 205 | 206 | return tokenString, nil 207 | } 208 | 209 | // generateRefresh generate refresh token 210 | func (a *Auth) generateRefresh(userID string) (string, error) { 211 | now := time.Now() 212 | token := jwt.NewWithClaims(a.opts.signingMethod, jwt.StandardClaims{ 213 | IssuedAt: now.Unix(), 214 | ExpiresAt: now.Add(time.Duration(a.opts.expiredRefresh) * time.Hour).Unix(), 215 | NotBefore: now.Unix(), 216 | Subject: userID, 217 | }) 218 | tokenString, err := token.SignedString(a.opts.signingRefreshKey) 219 | if err != nil { 220 | return "", errors.New("generate token fail") 221 | } 222 | 223 | return tokenString, nil 224 | } 225 | -------------------------------------------------------------------------------- /pkg/jwt/token.go: -------------------------------------------------------------------------------- 1 | package jwt 2 | 3 | import ( 4 | "encoding/json" 5 | ) 6 | 7 | // TokenInfo interface 8 | type TokenInfo interface { 9 | GetAccessToken() string 10 | GetRefreshToken() string 11 | GetTokenType() string 12 | EncodeToJSON() ([]byte, error) 13 | } 14 | 15 | type tokenInfo struct { 16 | AccessToken string `json:"access_token"` 17 | RefreshToken string `json:"refresh_token"` 18 | TokenType string `json:"token_type"` 19 | } 20 | 21 | // GetAccessToken return access token 22 | func (t *tokenInfo) GetAccessToken() string { 23 | return t.AccessToken 24 | } 25 | 26 | // GetRefreshToken return refresh token 27 | func (t *tokenInfo) GetRefreshToken() string { 28 | return t.RefreshToken 29 | } 30 | 31 | // GetTokenType return token type 32 | func (t *tokenInfo) GetTokenType() string { 33 | return t.TokenType 34 | } 35 | 36 | func (t *tokenInfo) EncodeToJSON() ([]byte, error) { 37 | return json.Marshal(t) 38 | } 39 | -------------------------------------------------------------------------------- /pkg/utils/copy.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "github.com/quangdangfit/go-admin/pkg/errors" 5 | ) 6 | 7 | // Copy by marshal json data 8 | func Copy(dest interface{}, src interface{}) error { 9 | data, err := json.Marshal(src) 10 | if err != nil { 11 | return errors.ErrorMarshal.Newm(err.Error()) 12 | } 13 | 14 | err = json.Unmarshal(data, dest) 15 | if err != nil { 16 | return errors.ErrorUnmarshal.Newm(err.Error()) 17 | } 18 | 19 | return nil 20 | } 21 | -------------------------------------------------------------------------------- /pkg/utils/generator.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "strings" 7 | "time" 8 | ) 9 | 10 | // constants generator 11 | const ( 12 | Charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" 13 | RandLength = 5 14 | ) 15 | 16 | var seededRand *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano())) 17 | 18 | // GenerateCode generate code by prefix, datetime 19 | func GenerateCode(prefix string) string { 20 | t := time.Now() 21 | y := "" 22 | if t.Year()%100 < 10 { 23 | y = fmt.Sprintf("0%d", t.Year()%100) 24 | } else { 25 | y = fmt.Sprintf("%d", t.Year()%100) 26 | } 27 | m := "" 28 | if t.Month() < 10 { 29 | m = fmt.Sprintf("0%d", t.Month()) 30 | } else { 31 | m = fmt.Sprintf("%d", t.Month()) 32 | } 33 | d := "" 34 | if t.Day() < 10 { 35 | d = fmt.Sprintf("0%d", t.Day()) 36 | } else { 37 | d = fmt.Sprintf("%d", t.Day()) 38 | } 39 | code := fmt.Sprintf("%s%s%s%s%s", prefix, y, m, d, RandomString(RandLength)) 40 | return strings.ToUpper(code) 41 | } 42 | 43 | // stringWithCharset random string in charset 44 | func stringWithCharset(length int) string { 45 | b := make([]byte, length) 46 | for i := range b { 47 | b[i] = Charset[seededRand.Intn(len(Charset))] 48 | } 49 | return string(b) 50 | } 51 | 52 | // RandomString random string by charset and length 53 | func RandomString(length int) string { 54 | return stringWithCharset(length) 55 | } 56 | -------------------------------------------------------------------------------- /pkg/utils/json.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | jsoniter "github.com/json-iterator/go" 5 | ) 6 | 7 | // JSON 8 | var ( 9 | json = jsoniter.ConfigCompatibleWithStandardLibrary 10 | JSONMarshal = json.Marshal 11 | JSONUnmarshal = json.Unmarshal 12 | JSONMarshalIndent = json.MarshalIndent 13 | JSONNewDecoder = json.NewDecoder 14 | JSONNewEncoder = json.NewEncoder 15 | ) 16 | 17 | // JSONMarshalToString JSON 18 | func JSONMarshalToString(v interface{}) string { 19 | s, err := jsoniter.MarshalToString(v) 20 | if err != nil { 21 | return "" 22 | } 23 | return s 24 | } 25 | -------------------------------------------------------------------------------- /pkg/utils/response.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | // constants responses 4 | const ( 5 | Success = "200" 6 | Error = "500" 7 | InvalidParams = "400" 8 | 9 | ErrorGetDatabase = "1001" 10 | 11 | ErrorExistProduct = "10001" 12 | ErrorExistProductFail = "10002" 13 | ErrorNotExistProduct = "10003" 14 | ErrorGetProductsFail = "10004" 15 | ErrorCountProductFail = "10005" 16 | ErrorAddProductFail = "10006" 17 | ErrorEditProductFail = "10007" 18 | ErrorDeleteProductFail = "10008" 19 | ErrorExportProductFail = "10009" 20 | ErrorImportProductFail = "10010" 21 | 22 | ErrorNotExistUser = "20001" 23 | ErrorCheckExistUserFail = "20002" 24 | ErrorAddUserFail = "20003" 25 | ErrorDeleteUserFail = "20004" 26 | ErrorEditUserFail = "20005" 27 | ErrorCountUserFail = "20006" 28 | ErrorGetUsersFail = "20007" 29 | ErrorGetUserFail = "20008" 30 | ErrorGenUserPosterFail = "20009" 31 | 32 | ErrorAuthCheckTokenFail = "30001" 33 | ErrorAuthCheckTokenTimeout = "30002" 34 | ErrorAuthToken = "30003" 35 | ErrorAuth = "30004" 36 | ) 37 | 38 | // PrepareResponse return new response body type map 39 | func PrepareResponse(data interface{}, message string, code string) map[string]interface{} { 40 | result := map[string]interface{}{ 41 | "data": data, 42 | "message": message, 43 | "code": code, 44 | } 45 | 46 | return result 47 | } 48 | -------------------------------------------------------------------------------- /pkg/utils/token.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "github.com/quangdangfit/gocommon/logger" 5 | "golang.org/x/crypto/bcrypt" 6 | 7 | "github.com/quangdangfit/go-admin/pkg/errors" 8 | ) 9 | 10 | // HashPassword hash password 11 | func HashPassword(pass []byte) (string, error) { 12 | hashed, err := bcrypt.GenerateFromPassword(pass, bcrypt.MinCost) 13 | if err != nil { 14 | logger.Error("Failed to generate password: ", err) 15 | return "", errors.Wrap(err, "utils.HashPassword") 16 | } 17 | 18 | return string(hashed), nil 19 | } 20 | -------------------------------------------------------------------------------- /pkg/utils/validation.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "regexp" 5 | ) 6 | 7 | // Validation struct 8 | type Validation struct { 9 | Value string 10 | Valid string 11 | } 12 | 13 | // Validate by key and value 14 | func Validate(values []Validation) bool { 15 | username := regexp.MustCompile("[A-Za-z0-9]") 16 | email := regexp.MustCompile("^[A-Za-z0-9]+[@]+[A-Za-z0-9]+[.]+[A-Za-z]+$") 17 | 18 | for i := 0; i < len(values); i++ { 19 | switch values[i].Valid { 20 | case "username": 21 | if !username.MatchString(values[i].Value) { 22 | return false 23 | } 24 | case "email": 25 | if !email.MatchString(values[i].Value) { 26 | return false 27 | } 28 | case "password": 29 | if len(values[i].Value) < 5 { 30 | return false 31 | } 32 | } 33 | } 34 | return true 35 | } 36 | -------------------------------------------------------------------------------- /scripts/golint.sh: -------------------------------------------------------------------------------- 1 | golint $(ls -d1 */ | sed s/\\//\\/.../g | grep -v -E "^vendor/" | tr "\n" " ") -------------------------------------------------------------------------------- /scripts/init.d/postgres-init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL 5 | CREATE DATABASE goadmin; 6 | GRANT ALL PRIVILEGES ON DATABASE goadmin TO postgres; 7 | EOSQL 8 | -------------------------------------------------------------------------------- /scripts/startup.sh: -------------------------------------------------------------------------------- 1 | FILE=config/config.yaml 2 | if [ -f "$FILE" ]; then 3 | echo "$FILE exist" 4 | else 5 | echo "$FILE does not exist" 6 | cp config/config.sample.yaml $FILE 7 | fi -------------------------------------------------------------------------------- /test/main_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "io" 8 | "net/http" 9 | "os" 10 | "testing" 11 | "time" 12 | 13 | "github.com/gin-gonic/gin" 14 | _ "github.com/jinzhu/gorm/dialects/postgres" 15 | "github.com/quangdangfit/gocommon/logger" 16 | "go.uber.org/dig" 17 | 18 | "github.com/quangdangfit/go-admin/app" 19 | "github.com/quangdangfit/go-admin/app/interfaces" 20 | "github.com/quangdangfit/go-admin/app/migration" 21 | "github.com/quangdangfit/go-admin/app/models" 22 | "github.com/quangdangfit/go-admin/pkg/jwt" 23 | ) 24 | 25 | const ( 26 | AuthTokenType = "Bearer" 27 | ) 28 | 29 | var ( 30 | engine *gin.Engine 31 | container *dig.Container 32 | token string 33 | 34 | apiKey = "testAPIkey" 35 | 36 | roles = []*models.Role{ 37 | { 38 | Model: models.Model{ 39 | ID: "test-role-id-1", 40 | CreatedAt: time.Now(), 41 | UpdatedAt: time.Now(), 42 | }, 43 | Name: "test1", 44 | Description: "test1", 45 | }, 46 | } 47 | ) 48 | 49 | func TestMain(m *testing.M) { 50 | logger.Initialize("testing") 51 | container = app.BuildContainer() 52 | engine = app.InitGinEngine(container) 53 | 54 | setup() 55 | code := m.Run() 56 | teardown() 57 | 58 | os.Exit(code) 59 | } 60 | 61 | func setup() { 62 | logger.Info("============> Setup for testing") 63 | removeUserData() 64 | 65 | migrate() 66 | createRoleData() 67 | createUserData() 68 | setupToken() 69 | } 70 | 71 | func teardown() { 72 | logger.Info("============> Teardown") 73 | removeUserData() 74 | } 75 | 76 | func migrate() { 77 | migration.Migrate(container) 78 | } 79 | 80 | func createRoleData() { 81 | container.Invoke(func( 82 | userRepo interfaces.IRoleRepository, 83 | jwtauth jwt.IJWTAuth, 84 | ) error { 85 | for _, r := range roles { 86 | if err := userRepo.Create(r); err != nil { 87 | return err 88 | } 89 | } 90 | 91 | return nil 92 | }) 93 | } 94 | 95 | func createUserData() { 96 | container.Invoke(func( 97 | userRepo interfaces.IUserRepository, 98 | jwtauth jwt.IJWTAuth, 99 | ) error { 100 | for _, u := range users { 101 | if err := userRepo.Create(u); err != nil { 102 | continue 103 | } 104 | } 105 | 106 | return nil 107 | }) 108 | } 109 | 110 | func setupToken() { 111 | container.Invoke(func( 112 | jwtauth jwt.IJWTAuth, 113 | ) error { 114 | tokenInfo, err := jwtauth.GenerateToken(user.ID) 115 | if err != nil { 116 | return err 117 | } 118 | 119 | token = tokenInfo.GetAccessToken() 120 | 121 | return nil 122 | }) 123 | } 124 | 125 | func removeUserData() { 126 | //container.Invoke(func( 127 | // userRepo repositories.IUserRepository, 128 | //) error { 129 | // for _, u := range users { 130 | // err := userRepo.Delete(u.ID) 131 | // if err != nil { 132 | // return err 133 | // } 134 | // } 135 | // return nil 136 | //}) 137 | } 138 | 139 | //func clearRedis() { 140 | // container.Invoke(func( 141 | // redis redis.IRedis, 142 | // ) error { 143 | // err := redis.Remove(utils.GenAPIKeyRedis("", apiKey)) 144 | // if err != nil { 145 | // return err 146 | // } 147 | // return nil 148 | // }) 149 | //} 150 | 151 | func toReader(v interface{}) io.Reader { 152 | buf := new(bytes.Buffer) 153 | _ = json.NewEncoder(buf).Encode(v) 154 | return buf 155 | } 156 | 157 | func parseReader(r io.Reader, v interface{}) error { 158 | return json.NewDecoder(r).Decode(v) 159 | } 160 | 161 | func newGetRequest(formatRouter string, v interface{}, args ...interface{}) *http.Request { 162 | req, _ := http.NewRequest("GET", fmt.Sprintf(formatRouter, args...), toReader(v)) 163 | req.Header.Add("Authorization", fmt.Sprintf("%s %s", AuthTokenType, token)) 164 | return req 165 | } 166 | 167 | func newPostRequest(formatRouter string, v interface{}, args ...interface{}) *http.Request { 168 | req, _ := http.NewRequest("POST", fmt.Sprintf(formatRouter, args...), toReader(v)) 169 | return req 170 | } 171 | 172 | func newPostAuthRequest(formatRouter string, v interface{}, args ...interface{}) *http.Request { 173 | req, _ := http.NewRequest("POST", fmt.Sprintf(formatRouter, args...), toReader(v)) 174 | req.Header.Add("Authorization", fmt.Sprintf("%s %s", AuthTokenType, token)) 175 | return req 176 | } 177 | 178 | func newInternalPostRequest(formatRouter string, v interface{}, args ...interface{}) *http.Request { 179 | req, _ := http.NewRequest("POST", fmt.Sprintf(formatRouter, args...), toReader(v)) 180 | req.Header.Add("api-key", apiKey) 181 | return req 182 | } 183 | 184 | func newPutRequest(formatRouter string, v interface{}, args ...interface{}) *http.Request { 185 | req, _ := http.NewRequest("PUT", fmt.Sprintf(formatRouter, args...), toReader(v)) 186 | req.Header.Add("Authorization", fmt.Sprintf("%s %s", AuthTokenType, token)) 187 | return req 188 | } 189 | 190 | func newDeleteRequest(formatRouter string, args ...interface{}) *http.Request { 191 | req, _ := http.NewRequest("DELETE", fmt.Sprintf(formatRouter, args...), nil) 192 | req.Header.Add("Authorization", fmt.Sprintf("%s %s", AuthTokenType, token)) 193 | return req 194 | } 195 | -------------------------------------------------------------------------------- /test/user_repository_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | 7 | "github.com/golang/mock/gomock" 8 | "github.com/stretchr/testify/suite" 9 | 10 | "github.com/quangdangfit/go-admin/app/dbs" 11 | "github.com/quangdangfit/go-admin/app/interfaces" 12 | "github.com/quangdangfit/go-admin/app/models" 13 | "github.com/quangdangfit/go-admin/app/repositories" 14 | "github.com/quangdangfit/go-admin/app/schema" 15 | ) 16 | 17 | var ( 18 | users = []*models.User{ 19 | { 20 | Model: models.Model{ 21 | ID: "test-user-id-1", 22 | CreatedAt: time.Now(), 23 | UpdatedAt: time.Now(), 24 | }, 25 | Username: "test-username-1", 26 | Email: "testuseremail1@tokoin.io", 27 | Password: "test-user-pwd-1", 28 | RefreshToken: "test-user-refresh-token-1", 29 | RoleID: roles[0].ID, 30 | }, 31 | { 32 | Model: models.Model{ 33 | ID: "test-user-id-2", 34 | CreatedAt: time.Now(), 35 | UpdatedAt: time.Now(), 36 | }, 37 | Username: "test-username-2", 38 | Email: "testuseremail2@tokoin.io", 39 | Password: "test-user-pwd-2", 40 | RefreshToken: "test-user-refresh-token-2", 41 | RoleID: roles[0].ID, 42 | }, 43 | { 44 | Model: models.Model{ 45 | ID: "test-user-id-3", 46 | CreatedAt: time.Now(), 47 | UpdatedAt: time.Now(), 48 | }, 49 | Username: "test-username-3", 50 | Email: "testuseremail3@tokoin.io", 51 | Password: "test-user-pwd-3", 52 | RefreshToken: "test-user-refresh-token-3", 53 | RoleID: roles[0].ID, 54 | }, 55 | } 56 | 57 | user = users[0] 58 | ) 59 | 60 | type UserRepositoryTestSuite struct { 61 | suite.Suite 62 | 63 | db interfaces.IDatabase 64 | repo interfaces.IUserRepository 65 | } 66 | 67 | func (s *UserRepositoryTestSuite) SetupTest() { 68 | mockCtrl := gomock.NewController(s.T()) 69 | defer mockCtrl.Finish() 70 | 71 | s.db = dbs.NewDatabase() 72 | s.repo = repositories.NewUserRepository(s.db) 73 | } 74 | 75 | func (s *UserRepositoryTestSuite) TestGetByIDSuccess() { 76 | u, err := s.repo.GetByID(user.ID) 77 | s.Nil(err) 78 | s.NotNil(u) 79 | s.Equal(user.ID, u.ID) 80 | } 81 | 82 | func (s *UserRepositoryTestSuite) TestGetByIDNotFound() { 83 | u, err := s.repo.GetByID("not-found-id") 84 | s.NotNil(err) 85 | s.Nil(u) 86 | } 87 | 88 | func (s *UserRepositoryTestSuite) TestGetByTokenSuccess() { 89 | u, err := s.repo.GetUserByToken(user.RefreshToken) 90 | s.Nil(err) 91 | s.NotNil(u) 92 | s.Equal(user.ID, u.ID) 93 | } 94 | 95 | func (s *UserRepositoryTestSuite) TestGetByTokenNotFound() { 96 | u, err := s.repo.GetUserByToken("not-found-token") 97 | s.NotNil(err) 98 | s.Nil(u) 99 | } 100 | 101 | func (s *UserRepositoryTestSuite) TestListFull() { 102 | usrs, err := s.repo.List(&schema.UserQueryParam{ 103 | Offset: 0, 104 | Limit: 100000, 105 | }) 106 | s.Nil(err) 107 | s.NotNil(usrs) 108 | s.Equal(len(users), len(*usrs)) 109 | } 110 | 111 | func (s *UserRepositoryTestSuite) TestLoginSuccess() { 112 | item := &schema.LoginBodyParams{ 113 | Username: "test-username-1", 114 | Password: "test-user-pwd-1", 115 | } 116 | 117 | user, err := s.repo.Login(item) 118 | s.Nil(err) 119 | s.NotNil(user) 120 | } 121 | 122 | func (s *UserRepositoryTestSuite) TestLoginFailed() { 123 | item := &schema.LoginBodyParams{ 124 | Username: "test-username-1", 125 | Password: "wrong-password", 126 | } 127 | 128 | user, err := s.repo.Login(item) 129 | s.NotNil(err) 130 | s.Nil(user) 131 | } 132 | 133 | func (s *UserRepositoryTestSuite) TestRemoveTokenSuccess() { 134 | u, err := s.repo.RemoveToken(users[1].ID) 135 | s.Nil(err) 136 | s.NotNil(u) 137 | 138 | u, err = s.repo.GetByID(users[1].ID) 139 | s.Nil(err) 140 | s.NotNil(u) 141 | s.Equal("", u.RefreshToken) 142 | } 143 | 144 | func (s *UserRepositoryTestSuite) TestRemoveTokenNotFound() { 145 | _, err := s.repo.RemoveToken("not-found-id") 146 | s.Nil(err) 147 | } 148 | 149 | func TestUserServiceTestSuite(t *testing.T) { 150 | suite.Run(t, new(UserRepositoryTestSuite)) 151 | } 152 | --------------------------------------------------------------------------------