├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
└── workflows
│ ├── build-lastest.yml
│ └── release-channels.yml
├── .gitignore
├── .run
├── api_Dockerfile.run.xml
└── core-api.run.xml
├── Makefile
├── README.md
├── app
└── admin
│ ├── cmd
│ └── api
│ │ ├── Dockerfile
│ │ ├── desc
│ │ ├── admin.api
│ │ ├── apis
│ │ │ └── apis.api
│ │ ├── authority
│ │ │ └── authority.api
│ │ ├── base.api
│ │ ├── captcha
│ │ │ └── captcha.api
│ │ ├── core
│ │ │ └── core.api
│ │ ├── dictionary
│ │ │ └── dictionary.api
│ │ ├── menu
│ │ │ └── menu.api
│ │ ├── oauth
│ │ │ └── oauth.api
│ │ ├── role
│ │ │ └── role.api
│ │ ├── token
│ │ │ └── token.api
│ │ └── user
│ │ │ └── user.api
│ │ ├── etc
│ │ └── core.yaml
│ │ └── internal
│ │ ├── config
│ │ └── config.go
│ │ ├── converter
│ │ ├── converter.go
│ │ ├── converter_test.go
│ │ ├── generated
│ │ │ └── generated.go
│ │ └── goverter.go
│ │ ├── globalkey
│ │ ├── cacheKey.go
│ │ ├── jwt.go
│ │ └── roleKey.go
│ │ ├── handler
│ │ ├── api
│ │ │ ├── createApiHandler.go
│ │ │ ├── deleteApiHandler.go
│ │ │ ├── getApiListHandler.go
│ │ │ └── updateApiHandler.go
│ │ ├── authority
│ │ │ ├── createApiAuthorityHandler.go
│ │ │ ├── createMenuAuthorityHandler.go
│ │ │ ├── getApiAuthorityHandler.go
│ │ │ ├── getMenuAuthorityHandler.go
│ │ │ ├── updateApiAuthorityHandler.go
│ │ │ └── updateMenuAuthorityHandler.go
│ │ ├── captcha
│ │ │ └── getCaptchaHandler.go
│ │ ├── core
│ │ │ ├── healthCheckHandler.go
│ │ │ └── initDatabaseHandler.go
│ │ ├── dictionary
│ │ │ ├── createDictionaryDetailHandler.go
│ │ │ ├── createDictionaryHandler.go
│ │ │ ├── deleteDictionaryDetailHandler.go
│ │ │ ├── deleteDictionaryHandler.go
│ │ │ ├── getDetailByDictionaryNameHandler.go
│ │ │ ├── getDictionaryListHandler.go
│ │ │ ├── updateDictionaryDetailHandler.go
│ │ │ └── updateDictionaryHandler.go
│ │ ├── menu
│ │ │ ├── createOrUpdateMenuHandler.go
│ │ │ ├── createOrUpdateMenuParamHandler.go
│ │ │ ├── deleteMenuHandler.go
│ │ │ ├── deleteMenuParamHandler.go
│ │ │ ├── getMenuByRoleHandler.go
│ │ │ ├── getMenuListHandler.go
│ │ │ └── getMenuParamListByMenuIdHandler.go
│ │ ├── oauth
│ │ │ ├── createProviderHandler.go
│ │ │ ├── deleteProviderHandler.go
│ │ │ ├── getProviderListHandler.go
│ │ │ ├── oauthCallbackHandler.go
│ │ │ ├── oauthLoginHandler.go
│ │ │ └── updateProviderHandler.go
│ │ ├── routes.go
│ │ ├── token
│ │ │ ├── createTokenHandler.go
│ │ │ ├── deleteTokenHandler.go
│ │ │ ├── getTokenListHandler.go
│ │ │ ├── logoutHandler.go
│ │ │ ├── setTokenStatusHandler.go
│ │ │ └── updateTokenHandler.go
│ │ └── user
│ │ │ ├── changePasswordHandler.go
│ │ │ ├── createUserHandler.go
│ │ │ ├── deleteUserHandler.go
│ │ │ ├── getUserInfoHandler.go
│ │ │ ├── getUserListHandler.go
│ │ │ ├── getUserPermCodeHandler.go
│ │ │ ├── getUserProfileHandler.go
│ │ │ ├── loginHandler.go
│ │ │ ├── logoutHandler.go
│ │ │ ├── registerHandler.go
│ │ │ ├── updateUserHandler.go
│ │ │ └── updateUserProfileHandler.go
│ │ ├── logic
│ │ ├── api
│ │ │ ├── createApiLogic.go
│ │ │ ├── deleteApiLogic.go
│ │ │ ├── getApiListLogic.go
│ │ │ └── updateApiLogic.go
│ │ ├── authority
│ │ │ ├── createApiAuthorityLogic.go
│ │ │ ├── createMenuAuthorityLogic.go
│ │ │ ├── getApiAuthorityLogic.go
│ │ │ ├── getMenuAuthorityLogic.go
│ │ │ ├── updateApiAuthorityLogic.go
│ │ │ └── updateMenuAuthorityLogic.go
│ │ ├── captcha
│ │ │ └── getCaptchaLogic.go
│ │ ├── core
│ │ │ ├── healthCheckLogic.go
│ │ │ └── initDatabaseLogic.go
│ │ ├── dictionary
│ │ │ ├── createDictionaryDetailLogic.go
│ │ │ ├── createDictionaryLogic.go
│ │ │ ├── deleteDictionaryDetailLogic.go
│ │ │ ├── deleteDictionaryLogic.go
│ │ │ ├── getDetailByDictionaryNameLogic.go
│ │ │ ├── getDictionaryListLogic.go
│ │ │ ├── updateDictionaryDetailLogic.go
│ │ │ └── updateDictionaryLogic.go
│ │ ├── menu
│ │ │ ├── createOrUpdateMenuLogic.go
│ │ │ ├── createOrUpdateMenuParamLogic.go
│ │ │ ├── deleteMenuLogic.go
│ │ │ ├── deleteMenuParamLogic.go
│ │ │ ├── getMenuByRoleLogic.go
│ │ │ ├── getMenuListLogic.go
│ │ │ └── getMenuParamListByMenuIdLogic.go
│ │ ├── oauth
│ │ │ ├── createProviderLogic.go
│ │ │ ├── deleteProviderLogic.go
│ │ │ ├── getProviderListLogic.go
│ │ │ ├── oauthCallbackLogic.go
│ │ │ ├── oauthLoginLogic.go
│ │ │ └── updateProviderLogic.go
│ │ ├── role
│ │ │ ├── createRoleLogic.go
│ │ │ ├── deleteRoleLogic.go
│ │ │ ├── getRoleListLogic.go
│ │ │ ├── setRoleStatusLogic.go
│ │ │ └── updateRoleLogic.go
│ │ ├── token
│ │ │ ├── createTokenLogic.go
│ │ │ ├── deleteTokenLogic.go
│ │ │ ├── getTokenListLogic.go
│ │ │ ├── logoutLogic.go
│ │ │ ├── setTokenStatusLogic.go
│ │ │ └── updateTokenLogic.go
│ │ └── user
│ │ │ ├── changePasswordLogic.go
│ │ │ ├── createUserLogic.go
│ │ │ ├── deleteUserLogic.go
│ │ │ ├── getUserInfoLogic.go
│ │ │ ├── getUserListLogic.go
│ │ │ ├── getUserPermCodeLogic.go
│ │ │ ├── getUserProfileLogic.go
│ │ │ ├── loginLogic.go
│ │ │ ├── logoutLogic.go
│ │ │ ├── registerLogic.go
│ │ │ ├── updateUserLogic.go
│ │ │ └── updateUserProfileLogic.go
│ │ ├── middleware
│ │ └── authorityMiddleware.go
│ │ ├── svc
│ │ └── serviceContext.go
│ │ └── types
│ │ └── types.go
│ └── ent
│ ├── casbin
│ └── adaptor.go
│ ├── casbinrule.go
│ ├── casbinrule
│ ├── casbinrule.go
│ └── where.go
│ ├── casbinrule_create.go
│ ├── casbinrule_delete.go
│ ├── casbinrule_query.go
│ ├── casbinrule_update.go
│ ├── client.go
│ ├── config.go
│ ├── context.go
│ ├── ent.go
│ ├── entc.go
│ ├── enttest
│ ├── client.go
│ ├── enttest.go
│ └── user_query_test.go
│ ├── extension_mutation_create.go
│ ├── extension_object.go
│ ├── extension_object_nillable.go
│ ├── extension_pagination.go
│ ├── gql_transaction.go
│ ├── hook
│ └── hook.go
│ ├── migrate
│ ├── migrate.go
│ └── schema.go
│ ├── mutation.go
│ ├── predicate
│ └── predicate.go
│ ├── runtime.go
│ ├── runtime
│ └── runtime.go
│ ├── schema
│ ├── casbin_rule.go
│ ├── sys_api.go
│ ├── sys_dictonary.go
│ ├── sys_dictonary_detail.go
│ ├── sys_menu.go
│ ├── sys_menu_param.go
│ ├── sys_oauth_provider.go
│ ├── sys_role.go
│ ├── sys_token.go
│ └── sys_user.go
│ ├── sysapi.go
│ ├── sysapi
│ ├── sysapi.go
│ └── where.go
│ ├── sysapi_create.go
│ ├── sysapi_delete.go
│ ├── sysapi_query.go
│ ├── sysapi_update.go
│ ├── sysdictionary.go
│ ├── sysdictionary
│ ├── sysdictionary.go
│ └── where.go
│ ├── sysdictionary_create.go
│ ├── sysdictionary_delete.go
│ ├── sysdictionary_query.go
│ ├── sysdictionary_update.go
│ ├── sysdictionarydetail.go
│ ├── sysdictionarydetail
│ ├── sysdictionarydetail.go
│ └── where.go
│ ├── sysdictionarydetail_create.go
│ ├── sysdictionarydetail_delete.go
│ ├── sysdictionarydetail_query.go
│ ├── sysdictionarydetail_update.go
│ ├── sysmenu.go
│ ├── sysmenu
│ ├── sysmenu.go
│ └── where.go
│ ├── sysmenu_create.go
│ ├── sysmenu_delete.go
│ ├── sysmenu_query.go
│ ├── sysmenu_update.go
│ ├── sysmenuparam.go
│ ├── sysmenuparam
│ ├── sysmenuparam.go
│ └── where.go
│ ├── sysmenuparam_create.go
│ ├── sysmenuparam_delete.go
│ ├── sysmenuparam_query.go
│ ├── sysmenuparam_update.go
│ ├── sysoauthprovider.go
│ ├── sysoauthprovider
│ ├── sysoauthprovider.go
│ └── where.go
│ ├── sysoauthprovider_create.go
│ ├── sysoauthprovider_delete.go
│ ├── sysoauthprovider_query.go
│ ├── sysoauthprovider_update.go
│ ├── sysrole.go
│ ├── sysrole
│ ├── sysrole.go
│ └── where.go
│ ├── sysrole_create.go
│ ├── sysrole_delete.go
│ ├── sysrole_query.go
│ ├── sysrole_update.go
│ ├── systoken.go
│ ├── systoken
│ ├── systoken.go
│ └── where.go
│ ├── systoken_create.go
│ ├── systoken_delete.go
│ ├── systoken_query.go
│ ├── systoken_update.go
│ ├── sysuser.go
│ ├── sysuser
│ ├── sysuser.go
│ └── where.go
│ ├── sysuser_create.go
│ ├── sysuser_delete.go
│ ├── sysuser_query.go
│ ├── sysuser_update.go
│ ├── template
│ ├── extension_mutation_create.tmpl
│ ├── extension_object.tmpl
│ ├── extension_object_nillable.tmpl
│ └── extension_pagination.tmpl
│ └── tx.go
├── deployment
└── docker-compose
│ └── docker-compose.yaml
├── docs
├── .nojekyll
├── README.md
├── _navbar.md
├── _sidebar.md
├── index.html
└── slash-admin
│ ├── assets
│ ├── add_example_api.png
│ ├── add_example_api_authority.png
│ ├── add_example_api_zh.png
│ ├── add_example_authority.png
│ ├── add_example_authority_zh.png
│ ├── add_example_menu.png
│ ├── api_en.png
│ ├── api_zh_cn.png
│ ├── authority_en.png
│ ├── authority_zh_cn.png
│ ├── consul.png
│ ├── consul_kv.png
│ ├── copy_translation_path.png
│ ├── dashboard_en.png
│ ├── dashboard_zh_cn.png
│ ├── edit_menu_en.png
│ ├── example-struct.png
│ ├── example_api_desc_title_en.png
│ ├── example_api_desc_title_zh.png
│ ├── example_en_title.png
│ ├── example_page.png
│ ├── example_rpc_struct.png
│ ├── example_validator_message_mode.png
│ ├── example_validator_modal_mode.png
│ ├── example_zh_title.png
│ ├── file_list_en.png
│ ├── file_list_zh_cn.png
│ ├── file_preview_en.png
│ ├── file_preview_zh.png
│ ├── get_token.png
│ ├── i18n_ext.png
│ ├── init_en.png
│ ├── init_zh_cn.png
│ ├── kibana.png
│ ├── login_en.png
│ ├── login_zh_cn.png
│ ├── menu_en.png
│ ├── menu_zh_cn.png
│ ├── oauth_add_provider.png
│ ├── oauth_add_provider_en.png
│ ├── prometheus.png
│ ├── register_en.png
│ ├── register_zh_cn.png
│ ├── role_en.png
│ ├── role_zh_cn.png
│ ├── swagger.png
│ ├── swagger_authority.png
│ ├── user_en.png
│ └── user_zh_cn.png
│ ├── en
│ ├── README.md
│ ├── _navbar.md
│ ├── _sidebar.md
│ └── docs
│ │ ├── FAQ.md
│ │ ├── api_example.md
│ │ ├── authorization.md
│ │ ├── env_setting.md
│ │ ├── error_handling.md
│ │ ├── file_manager.md
│ │ ├── global_vars.md
│ │ ├── gorm.md
│ │ ├── k8s-deploy.md
│ │ ├── log-collection.md
│ │ ├── minikube.md
│ │ ├── oauth.md
│ │ ├── prometheus.md
│ │ ├── quick_develop_example.md
│ │ ├── rpc_example.md
│ │ ├── screenshot.md
│ │ ├── simple-admin-tools.md
│ │ ├── swagger.md
│ │ ├── validator.md
│ │ ├── web-setting.md
│ │ └── web_develop_example.md
│ └── zh-cn
│ ├── README.md
│ ├── _navbar.md
│ ├── _sidebar.md
│ └── docs
│ ├── FAQ.md
│ ├── api_example.md
│ ├── authorization.md
│ ├── env_setting.md
│ ├── error_handling.md
│ ├── file_manager.md
│ ├── global_vars.md
│ ├── gorm.md
│ ├── k8s-deploy.md
│ ├── log-collection.md
│ ├── minikube.md
│ ├── oauth.md
│ ├── prometheus.md
│ ├── quick_develop_example.md
│ ├── rpc_example.md
│ ├── screenshot.md
│ ├── simple-admin-tools.md
│ ├── swagger.md
│ ├── validator.md
│ ├── web-setting.md
│ └── web_develop_example.md
├── go.mod
├── go.sum
├── modd.conf
├── pkg
├── captcha
│ └── store.go
├── message
│ └── message.go
├── slconfig
│ ├── captcha.go
│ ├── casbin.go
│ ├── database.go
│ └── redis.go
├── types
│ ├── menu.go
│ ├── oauth.go
│ ├── status.go
│ └── utils.go
└── utils
│ ├── avatar.go
│ ├── encrypt.go
│ ├── encrypt_test.go
│ ├── tx.go
│ └── wrap.go
└── user.json
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/workflows/build-lastest.yml:
--------------------------------------------------------------------------------
1 | name: Build Latest Image
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | release-version:
7 | description: 'Release version to test'
8 | required: true
9 | default: 'latest'
10 |
11 | jobs:
12 | build-slash-admin:
13 | runs-on: ubuntu-20.04
14 | env:
15 | IMAGE_REGISTRY: registry.cn-shenzhen.aliyuncs.com/go-slash/slash-admin
16 | DOCKER_BUILDKIT: 1
17 | steps:
18 | - name: Checkout repo
19 | uses: actions/checkout@v2
20 |
21 |
22 | - name: Set up QEMU
23 | uses: docker/setup-qemu-action@v1
24 |
25 | - name: Set up Docker Buildx
26 | uses: docker/setup-buildx-action@v1
27 |
28 | - name: Login to Aliyun Container Registry
29 | uses: docker/login-action@v2
30 | with:
31 | registry: registry.cn-shenzhen.aliyuncs.com
32 | username: "${{ secrets.REGISTRY_USERNAME }}"
33 | password: "${{ secrets.REGISTRY_PASSWORD }}"
34 |
35 | - name: Build and push
36 | id: docker_build
37 | uses: docker/build-push-action@v2
38 | with:
39 | file: app/admin/cmd/api/Dockerfile
40 | push: true
41 | tags: registry.cn-shenzhen.aliyuncs.com/go-slash/slash-admin:${{ github.event.inputs.release-version }}
42 |
43 | - name: Image digest
44 | run: echo ${{ steps.docker_build.outputs.digest }}
--------------------------------------------------------------------------------
/.github/workflows/release-channels.yml:
--------------------------------------------------------------------------------
1 | name: Release tags
2 |
3 | on:
4 | push:
5 | branches:
6 | - "main"
7 | paths:
8 | - 'release-channels.yaml'
9 | workflow_dispatch:
10 |
11 |
12 | jobs:
13 | Build:
14 | runs-on: ubuntu-20.04
15 | env:
16 | DOCKER_BUILDKIT: 1
17 | steps:
18 | - name: Source checkout
19 | uses: actions/checkout@v2
20 | with:
21 | fetch-depth: 0
22 | - name: get stable tag
23 | run: echo STABLE_RELEASE=$(yq eval '.stable' release-channels.yaml) >> $GITHUB_ENV
24 | - name: checkout stable tag
25 | uses: actions/checkout@v2
26 | with:
27 | fetch-depth: 0
28 | ref: ${{ env.STABLE_RELEASE }}
29 |
30 | - name: Set up Docker Buildx
31 | uses: docker/setup-buildx-action@v1
32 |
33 | - name: Login to Aliyun Container Registry
34 | uses: docker/login-action@v2
35 | with:
36 | registry: registry.cn-shenzhen.aliyuncs.com
37 | username: "${{ secrets.REGISTRY_USERNAME }}"
38 | password: "${{ secrets.REGISTRY_PASSWORD }}"
39 |
40 | - name: Build and push
41 | id: docker_build
42 | uses: docker/build-push-action@v2
43 | with:
44 | file: app/admin/cmd/api/Dockerfile
45 | push: true
46 | tags: registry.cn-shenzhen.aliyuncs.com/go-slash/slash-admin:stable
47 |
48 | - name: Image digest
49 | run: echo ${{ steps.docker_build.outputs.digest }}
50 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore all
2 | *
3 |
4 | # Unignore all with extensions
5 | !*.*
6 | !**/Dockerfile
7 | !**/Makefile
8 |
9 | # Unignore all dirs
10 | !*/
11 | !api
12 |
13 | # ignore
14 | .idea
15 | **/.DS_Store
16 | **/logs
17 |
18 | # for test purpose
19 | **/adhoc
20 | go.work
21 | go.work.sum
22 |
23 | # gitlab ci
24 | .cache
25 | .golangci.yml
26 |
27 | # vim auto backup file
28 | *~
29 | !OWNERS
30 |
31 | data
32 | release
--------------------------------------------------------------------------------
/.run/api_Dockerfile.run.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.run/core-api.run.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | HASH=$(shell git rev-parse --short HEAD)
2 | VERSION=$(shell git describe --tags --always)
3 |
4 | APP = slash-admin
5 | RELEASE_ROOT = release
6 | RELEASE_TAG = $(VERSION).$(GIT_HASH)
7 |
8 | RED = "\e[31;1m"
9 | GREEN = "\e[32;1m"
10 | YELLOW = "\e[33;1m"
11 | BLUE = "\e[34;1m"
12 | PURPLE = "\e[35;1m"
13 | CYAN = "\e[36;1m"
14 |
15 | goctl-admin-api:
16 | goctls api go --swagger --api ./app/admin/cmd/api/desc/admin.api --dir ./app/admin/cmd/api -style=goZero
17 | @printf $(GREEN)"[SUCCESS] generate goctl-admin-api success"
18 |
19 | scan-admin-swagger:
20 | swagger generate spec --output=./core.yml --scan-models
21 | @printf $(GREEN)"[SUCCESS] scan-admin-swagger success"
22 |
23 | start-admin-api:
24 | lsof -i:9100 | awk 'NR!=1 {print $2}' | xargs killall -9 || true
25 | @printf $(GREEN)"[SUCCESS] kill admin-api success"
26 | modd
27 |
28 | ent-admin-orm:
29 | cd app/admin/ent && go run -mod=mod ./entc.go
30 | @printf $(GREEN)"[SUCCESS] generate ent-admin-orm success"
31 |
32 | goverter-admin:
33 | cd app/admin/cmd/api/internal/converter && go run ./goverter.go
34 | @printf $(GREEN)"[SUCCESS] generate goverter-admin success"
35 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # slash-admin
2 |
3 | ---
4 | [](https://go-zero.dev/)
5 | [](https://vvbin.cn/doc-next/)
6 | [](https://ent.io/)
7 | [](https://github.com/casbin/casbin)
8 |
9 | ## 简介
10 |
11 | Slash Admin 是一个开箱即用的分布式微服务后端管理系统,基于go-zero开发,提供丰富的功能如服务发现,权限管理等。
12 | 该框架可以帮助您快速开发具有RPC服务的后台管理系统。
13 |
14 | ## 特性
15 |
16 | - **最新技术栈**:使用 ent, casbin, kafka 等前沿技术开发
17 | - **完全支持go-swagger**: 直接在api文件内编写注释即可直接生成swagger文档
18 | - **统一的错误处理**: 整个系统拥有国际化的统一错误处理
19 | - **国际化**:内置完善的国际化方案
20 | - **服务注册发现**: 完善的服务注册发现机制,原生支持K8s
21 | - **权限**: 内置完善的动态路由权限生成方案, 集成RBAC权限控制
22 | - **其他**: 流量控制, ES服务
23 |
24 |
25 | ## 维护者
26 |
27 | [@waltcow](https://github.com/waltcow)
28 |
29 | ## License
30 |
31 | [MIT](./LICENSE)
32 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM golang:1.19-alpine AS builder
2 |
3 | LABEL stage=gobuilder
4 |
5 | ENV CGO_ENABLED 0
6 | ENV GOPROXY https://goproxy.cn,direct
7 | RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
8 |
9 | RUN apk update --no-cache && apk add --no-cache tzdata
10 |
11 | WORKDIR /build
12 |
13 | ADD go.mod .
14 | RUN go mod download
15 | COPY . .
16 | COPY app/admin/cmd/api/etc /app/etc
17 |
18 | RUN go build -ldflags="-s -w" -o /app/core ./app/admin/cmd/api/core.go
19 |
20 | FROM golang:1.19-alpine
21 |
22 | RUN apk update --no-cache && apk add --no-cache tzdata
23 |
24 | COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
25 | COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
26 |
27 | ENV TZ Asia/Shanghai
28 |
29 | WORKDIR /app
30 | COPY --from=builder /app/core /app/core
31 | COPY --from=builder /app/etc /app/etc
32 |
33 | CMD ["./core", "-f", "etc/core.yaml"]
34 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/desc/admin.api:
--------------------------------------------------------------------------------
1 | syntax = "v1"
2 |
3 | info(
4 | title: "slash admin"
5 | desc: "slash admin backend service"
6 | author: "waltcow"
7 | email: "waltcow@gmail.com"
8 | version: "v1.0"
9 | )
10 |
11 | import "base.api"
12 |
13 | import "core/core.api"
14 | import "role/role.api"
15 | import "captcha/captcha.api"
16 | import "user/user.api"
17 | import "menu/menu.api"
18 |
19 | import "apis/apis.api"
20 | import "authority/authority.api"
21 | import "dictionary/dictionary.api"
22 | import "oauth/oauth.api"
23 | import "token/token.api"
--------------------------------------------------------------------------------
/app/admin/cmd/api/desc/captcha/captcha.api:
--------------------------------------------------------------------------------
1 | syntax = "v1"
2 |
3 | info(
4 | title: "captcha api"
5 | desc: "captcha api"
6 | author: "waltcow"
7 | email: "waltcow@gmail.com"
8 | version: "v1.0"
9 | )
10 |
11 | import "base.api"
12 |
13 | // The response data of captcha | 验证码返回数据
14 | type CaptchaInfoResp {
15 | CaptchaId string `json:"captchaId"`
16 | ImgPath string `json:"imgPath"`
17 | }
18 |
19 | @server(
20 | group: captcha
21 | )
22 | service core {
23 | @doc("Get captcha | 获取验证码")
24 | @handler getCaptcha
25 | get /captcha returns (CaptchaInfoResp)
26 | }
--------------------------------------------------------------------------------
/app/admin/cmd/api/desc/core/core.api:
--------------------------------------------------------------------------------
1 | syntax = "v1"
2 |
3 | info(
4 | title: "core service"
5 | desc: "this is the api describe file for core services"
6 | author: "waltcow"
7 | email: "waltcow@gmail.com"
8 | version: "v1.0"
9 | )
10 |
11 | import "base.api"
12 |
13 | @server(
14 | group: core
15 | )
16 |
17 | service core {
18 |
19 | @doc("Check the system status | 检查系统状态")
20 | @handler healthCheck
21 | get /core/health
22 |
23 | @doc("Initialize database | 初始化数据库")
24 | @handler initDatabase
25 | get /core/init/database returns (SimpleMsgResp)
26 | }
--------------------------------------------------------------------------------
/app/admin/cmd/api/etc/core.yaml:
--------------------------------------------------------------------------------
1 | Name: core
2 | Host: 0.0.0.0
3 | Port: 9100
4 | Timeout: 30000
5 | Mode: dev
6 |
7 | Auth:
8 | AccessSecret: jS6VKDtsJf3z1n2VKDtsJf3z1n2
9 | AccessExpire: 259200
10 |
11 | Log:
12 | ServiceName: core-api
13 | Mode: console
14 | Level: info
15 | Compress: false
16 | KeepDays: 7
17 | StackCoolDownMillis: 100
18 |
19 | Captcha:
20 | KeyLong: 5
21 | ImgWidth: 240
22 | ImgHeight: 80
23 |
24 | Redis:
25 | Host: 127.0.0.1
26 | Port: 6379
27 | Pass:
28 | Type: node
29 | TLS: false
30 |
31 | Database:
32 | User: root
33 | Password: "123456"
34 | DbName: slash_admin_enhance
35 | SSLMode: false
36 | Host: 127.0.0.1
37 | Port: 3306
38 | DbPath:
39 | Type: mysql
40 | MaxOpenConns: 100
41 | Debug: true
42 | AutoMigrate: true
43 |
44 |
45 | Casbin:
46 | ModelText: |
47 | [request_definition]
48 | r = sub, obj, act
49 | [policy_definition]
50 | p = sub, obj, act
51 | [role_definition]
52 | g = _, _
53 | [policy_effect]
54 | e = some(where (p.eft == allow))
55 | [matchers]
56 | m = r.sub == p.sub && keyMatch2(r.obj,p.obj) && r.act == p.act
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/config/config.go:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | import (
4 | "github.com/zeromicro/go-zero/rest"
5 | "slash-admin/pkg/slconfig"
6 | )
7 |
8 | type Config struct {
9 | rest.RestConf
10 |
11 | Auth struct {
12 | AccessSecret string
13 | AccessExpire int64
14 | }
15 |
16 | //redis config
17 | Redis slconfig.RedisConf
18 |
19 | // database config
20 | Database slconfig.DatabaseConf
21 |
22 | // captcha config
23 | Captcha slconfig.CaptchaConf
24 |
25 | // casbin config
26 | Casbin slconfig.CasbinConf
27 | }
28 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/converter/converter.go:
--------------------------------------------------------------------------------
1 | package converter
2 |
3 | import (
4 | "slash-admin/app/admin/cmd/api/internal/types"
5 | "slash-admin/app/admin/ent"
6 | pType "slash-admin/pkg/types"
7 | "time"
8 | )
9 |
10 | // goverter:converter
11 | // goverter:extend StatusToUint8
12 | // goverter:extend TimeToUnixMilli
13 | type Converter interface {
14 | ConvertPagination(input *ent.PageDetails) (output *types.Pagination)
15 |
16 | ConvertSysUser(input *ent.SysUser) (output *types.UserInfo)
17 | ConvertSysUserList(input []*ent.SysUser) (output []*types.UserInfo)
18 |
19 | ConvertSysRoleToRoleInfo(input *ent.SysRole) (output *types.RoleInfo)
20 | ConvertSysRoleToRoleInfoList(input []*ent.SysRole) (output []*types.RoleInfo)
21 |
22 | ConvertSysToken(input *ent.SysToken) (output *types.TokenInfo)
23 | ConvertSysTokenList(input []*ent.SysToken) (output []*types.TokenInfo)
24 |
25 | ConvertSysOauthProvider(input *ent.SysOauthProvider) (output *types.OauthProviderInfo)
26 | ConvertSysOauthProviderList(input []*ent.SysOauthProvider) (output []*types.OauthProviderInfo)
27 |
28 | // goverter:map Desc Description
29 | ConvertSysDictionary(input *ent.SysDictionary) (output *types.DictionaryInfo)
30 | ConvertSysDictionaryList(input []*ent.SysDictionary) (output []*types.DictionaryInfo)
31 |
32 | ConvertSysDictionaryDetail(input *ent.SysDictionaryDetail) (output *types.DictionaryDetailInfo)
33 | ConvertSysDictionaryDetailList(input []*ent.SysDictionaryDetail) (output []*types.DictionaryDetailInfo)
34 |
35 | // goverter:map APIGroup Group
36 | ConvertSysApi(input *ent.SysApi) (output *types.ApiInfo)
37 | ConvertSysApiList(input []*ent.SysApi) (output []*types.ApiInfo)
38 | }
39 |
40 | func StatusToUint8(v pType.Status) uint8 {
41 | return uint8(v)
42 | }
43 |
44 | func TimeToUnixMilli(v time.Time) int64 {
45 | return v.UnixMilli()
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/converter/converter_test.go:
--------------------------------------------------------------------------------
1 | package converter
2 |
3 | import (
4 | _ "github.com/jmattheis/goverter/cmd/goverter"
5 | "testing"
6 | )
7 |
8 | func Test_NewConverter(t *testing.T) {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/converter/goverter.go:
--------------------------------------------------------------------------------
1 | //go:build ignore
2 | // +build ignore
3 |
4 | package main
5 |
6 | import (
7 | "fmt"
8 | goverter "github.com/jmattheis/goverter"
9 | "os"
10 | )
11 |
12 | func main() {
13 |
14 | err := goverter.GenerateConverterFile("./generated/generated.go", goverter.GenerateConfig{
15 | PackageName: "generated",
16 | ScanDir: "slash-admin/app/admin/cmd/api/internal/converter",
17 | ExtendMethods: []string{},
18 | PackagePath: "",
19 | WrapErrors: false,
20 | IgnoredUnexportedFields: true,
21 | })
22 | if err != nil {
23 | _, _ = fmt.Fprintln(os.Stderr, err)
24 | os.Exit(1)
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/globalkey/cacheKey.go:
--------------------------------------------------------------------------------
1 | package globalkey
2 |
3 | import "fmt"
4 |
5 | const (
6 | InitDatabaseLock = "init_database_lock"
7 | InitDatabaseState = "init_database_state"
8 | InitDatabaseErrorMsg = "init_database_error_msg"
9 | )
10 |
11 | const (
12 | RoleList = "role_list"
13 | RoleListItemID = "%d_rl_id"
14 | RoleListItemValue = "%d_rl_value"
15 | RoleListItemStatus = "%d_rl_status"
16 | )
17 |
18 | func GetRoleListID(id uint64) string {
19 | return fmt.Sprintf(RoleListItemID, id)
20 | }
21 | func GetRoleListValue(id uint64) string {
22 | return fmt.Sprintf(RoleListItemValue, id)
23 | }
24 | func GetRoleListStatus(id uint64) string {
25 | return fmt.Sprintf(RoleListItemStatus, id)
26 | }
27 |
28 | const (
29 | TokenBlackList = "b_token_%s"
30 | )
31 |
32 | func GetBlackListToken(token string) string {
33 | return fmt.Sprintf(TokenBlackList, token)
34 | }
35 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/globalkey/jwt.go:
--------------------------------------------------------------------------------
1 | package globalkey
2 |
3 | const (
4 | JWTUserId = "userId"
5 | JWTRoleId = "roleId"
6 | )
7 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/globalkey/roleKey.go:
--------------------------------------------------------------------------------
1 | package globalkey
2 |
3 | const (
4 | RoleAdminID = 1
5 | RoleStuffID = 2
6 | RoleMemberID = 3
7 | )
8 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/api/createApiHandler.go:
--------------------------------------------------------------------------------
1 | package api
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/api"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /api api CreateApi
13 | //
14 | // Create API information | 创建或更新API
15 | //
16 | // Create API information | 创建或更新API
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: CreateApiReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func CreateApiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.CreateApiReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := api.NewCreateApiLogic(r.Context(), svcCtx)
39 | resp, err := l.CreateApi(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/api/deleteApiHandler.go:
--------------------------------------------------------------------------------
1 | package api
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/api"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route delete /api api DeleteApi
13 | //
14 | // Delete API information | 删除API信息
15 | //
16 | // Delete API information | 删除API信息
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: IDReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func DeleteApiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.IDReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := api.NewDeleteApiLogic(r.Context(), svcCtx)
39 | resp, err := l.DeleteApi(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/api/getApiListHandler.go:
--------------------------------------------------------------------------------
1 | package api
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/api"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /api/list api GetApiList
13 | //
14 | // Get API list | 获取API列表
15 | //
16 | // Get API list | 获取API列表
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: ApiListReq
23 | //
24 | //
25 | // Responses:
26 | // 200: ApiListResp
27 | //
28 | //
29 |
30 | func GetApiListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.ApiListReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := api.NewGetApiListLogic(r.Context(), svcCtx)
39 | resp, err := l.GetApiList(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/api/updateApiHandler.go:
--------------------------------------------------------------------------------
1 | package api
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/api"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route put /api api UpdateApi
13 | //
14 | // Update API information | 创建或更新API
15 | //
16 | // Update API information | 创建或更新API
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: UpdateApiReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func UpdateApiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.UpdateApiReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := api.NewUpdateApiLogic(r.Context(), svcCtx)
39 | resp, err := l.UpdateApi(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/authority/createApiAuthorityHandler.go:
--------------------------------------------------------------------------------
1 | package authority
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/authority"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /authority/api authority CreateApiAuthority
13 | //
14 | // Create or update API authorization information | 创建或更新API权限
15 | //
16 | // Create or update API authorization information | 创建或更新API权限
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: CreateApiAuthorityReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func CreateApiAuthorityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.CreateApiAuthorityReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := authority.NewCreateApiAuthorityLogic(r.Context(), svcCtx)
39 | resp, err := l.CreateApiAuthority(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/authority/createMenuAuthorityHandler.go:
--------------------------------------------------------------------------------
1 | package authority
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/authority"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /authority/menu authority CreateMenuAuthority
13 | //
14 | // "Create menu authorization information | 创建菜单权限"
15 | //
16 | // "Create menu authorization information | 创建菜单权限"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: CreateMenuAuthorityReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func CreateMenuAuthorityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.CreateMenuAuthorityReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := authority.NewCreateMenuAuthorityLogic(r.Context(), svcCtx)
39 | resp, err := l.CreateMenuAuthority(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/authority/getApiAuthorityHandler.go:
--------------------------------------------------------------------------------
1 | package authority
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/authority"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /authority/api/role authority GetApiAuthority
13 | //
14 | // Get role's API authorization list | 获取角色api权限列表
15 | //
16 | // Get role's API authorization list | 获取角色api权限列表
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: IDReq
23 | //
24 | //
25 | // Responses:
26 | // 200: ApiAuthorityListResp
27 | //
28 | //
29 |
30 | func GetApiAuthorityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.IDReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := authority.NewGetApiAuthorityLogic(r.Context(), svcCtx)
39 | resp, err := l.GetApiAuthority(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/authority/getMenuAuthorityHandler.go:
--------------------------------------------------------------------------------
1 | package authority
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/authority"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /authority/menu/role authority GetMenuAuthority
13 | //
14 | // Get role's menu authorization list | 获取角色菜单权限列表
15 | //
16 | // Get role's menu authorization list | 获取角色菜单权限列表
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: IDReq
23 | //
24 | //
25 | // Responses:
26 | // 200: MenuAuthorityInfoResp
27 | //
28 | //
29 |
30 | func GetMenuAuthorityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.IDReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := authority.NewGetMenuAuthorityLogic(r.Context(), svcCtx)
39 | resp, err := l.GetMenuAuthority(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/authority/updateApiAuthorityHandler.go:
--------------------------------------------------------------------------------
1 | package authority
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/authority"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route put /authority/api authority UpdateApiAuthority
13 | //
14 | // Get API authorization information | 获取API权限
15 | //
16 | // Get API authorization information | 获取API权限
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: UpdateApiAuthorityReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func UpdateApiAuthorityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.UpdateApiAuthorityReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := authority.NewUpdateApiAuthorityLogic(r.Context(), svcCtx)
39 | resp, err := l.UpdateApiAuthority(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/authority/updateMenuAuthorityHandler.go:
--------------------------------------------------------------------------------
1 | package authority
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/authority"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route put /authority/menu authority UpdateMenuAuthority
13 | //
14 | // "Update menu authorization information | 更新菜单权限"
15 | //
16 | // "Update menu authorization information | 更新菜单权限"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: UpdateMenuAuthorityReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func UpdateMenuAuthorityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.UpdateMenuAuthorityReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := authority.NewUpdateMenuAuthorityLogic(r.Context(), svcCtx)
39 | resp, err := l.UpdateMenuAuthority(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/captcha/getCaptchaHandler.go:
--------------------------------------------------------------------------------
1 | package captcha
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/captcha"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | )
10 |
11 | // swagger:route get /captcha captcha GetCaptcha
12 | //
13 | // Get captcha | 获取验证码
14 | //
15 | // Get captcha | 获取验证码
16 | //
17 | // Responses:
18 | // 200: CaptchaInfoResp
19 | //
20 | //
21 |
22 | func GetCaptchaHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
23 | return func(w http.ResponseWriter, r *http.Request) {
24 | l := captcha.NewGetCaptchaLogic(r.Context(), svcCtx)
25 | resp, err := l.GetCaptcha()
26 | if err != nil {
27 | httpx.Error(w, err)
28 | } else {
29 | httpx.OkJson(w, resp)
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/core/healthCheckHandler.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/core"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | )
10 |
11 | // swagger:route get /core/health core HealthCheck
12 | //
13 | // "Check the system status | 检查系统状态"
14 | //
15 | // "Check the system status | 检查系统状态"
16 | //
17 |
18 | func HealthCheckHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
19 | return func(w http.ResponseWriter, r *http.Request) {
20 | l := core.NewHealthCheckLogic(r.Context(), svcCtx)
21 | err := l.HealthCheck()
22 | if err != nil {
23 | httpx.Error(w, err)
24 | } else {
25 | httpx.Ok(w)
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/core/initDatabaseHandler.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/core"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | )
10 |
11 | // swagger:route get /core/init/database core InitDatabase
12 | //
13 | // "Initialize database | 初始化数据库"
14 | //
15 | // "Initialize database | 初始化数据库"
16 | //
17 | // Responses:
18 | // 200: SimpleMsgResp
19 | //
20 | //
21 |
22 | func InitDatabaseHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
23 | return func(w http.ResponseWriter, r *http.Request) {
24 | l := core.NewInitDatabaseLogic(r.Context(), svcCtx)
25 | resp, err := l.InitDatabase()
26 | if err != nil {
27 | httpx.Error(w, err)
28 | } else {
29 | httpx.OkJson(w, resp)
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/dictionary/createDictionaryDetailHandler.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/dictionary"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /dict/detail dictionary CreateDictionaryDetail
13 | //
14 | // "Create dictionary KV information | 创建字典键值信息"
15 | //
16 | // "Create dictionary KV information | 创建字典键值信息"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: CreateDictionaryDetailReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func CreateDictionaryDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.CreateDictionaryDetailReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := dictionary.NewCreateDictionaryDetailLogic(r.Context(), svcCtx)
39 | resp, err := l.CreateDictionaryDetail(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/dictionary/createDictionaryHandler.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/dictionary"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /dict dictionary CreateDictionary
13 | //
14 | // "Create dictionary information | 创建字典信息"
15 | //
16 | // "Create dictionary information | 创建字典信息"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: CreateDictionaryReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func CreateDictionaryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.CreateDictionaryReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := dictionary.NewCreateDictionaryLogic(r.Context(), svcCtx)
39 | resp, err := l.CreateDictionary(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/dictionary/deleteDictionaryDetailHandler.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/dictionary"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route delete /dict/detail dictionary DeleteDictionaryDetail
13 | //
14 | // "Delete dictionary KV information | 删除字典键值信息"
15 | //
16 | // "Delete dictionary KV information | 删除字典键值信息"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: IDReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func DeleteDictionaryDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.IDReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := dictionary.NewDeleteDictionaryDetailLogic(r.Context(), svcCtx)
39 | resp, err := l.DeleteDictionaryDetail(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/dictionary/deleteDictionaryHandler.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/dictionary"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route delete /dict dictionary DeleteDictionary
13 | //
14 | // "Delete dictionary information | 删除字典信息"
15 | //
16 | // "Delete dictionary information | 删除字典信息"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: IDReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func DeleteDictionaryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.IDReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := dictionary.NewDeleteDictionaryLogic(r.Context(), svcCtx)
39 | resp, err := l.DeleteDictionary(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/dictionary/getDetailByDictionaryNameHandler.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/dictionary"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /dict/detail/list dictionary GetDetailByDictionaryName
13 | //
14 | // "Get dictionary detail list by dictionary name | 根据字典名获取字典键值列表"
15 | //
16 | // "Get dictionary detail list by dictionary name | 根据字典名获取字典键值列表"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: DictionaryDetailReq
23 | //
24 | //
25 | // Responses:
26 | // 200: DictionaryDetailListResp
27 | //
28 | //
29 |
30 | func GetDetailByDictionaryNameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.DictionaryDetailReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := dictionary.NewGetDetailByDictionaryNameLogic(r.Context(), svcCtx)
39 | resp, err := l.GetDetailByDictionaryName(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/dictionary/getDictionaryListHandler.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/dictionary"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /dict/list dictionary GetDictionaryList
13 | //
14 | // "Get dictionary list | 获取字典列表"
15 | //
16 | // "Get dictionary list | 获取字典列表"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: DictionaryListReq
23 | //
24 | //
25 | // Responses:
26 | // 200: DictionaryListResp
27 | //
28 | //
29 |
30 | func GetDictionaryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.DictionaryListReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := dictionary.NewGetDictionaryListLogic(r.Context(), svcCtx)
39 | resp, err := l.GetDictionaryList(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/dictionary/updateDictionaryDetailHandler.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/dictionary"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route put /dict/detail dictionary UpdateDictionaryDetail
13 | //
14 | // "Update dictionary KV information | 更新字典键值信息"
15 | //
16 | // "Update dictionary KV information | 更新字典键值信息"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: UpdateDictionaryDetailReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func UpdateDictionaryDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.UpdateDictionaryDetailReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := dictionary.NewUpdateDictionaryDetailLogic(r.Context(), svcCtx)
39 | resp, err := l.UpdateDictionaryDetail(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/dictionary/updateDictionaryHandler.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/dictionary"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route put /dict dictionary UpdateDictionary
13 | //
14 | // "Update dictionary information | 更新字典信息"
15 | //
16 | // "Update dictionary information | 更新字典信息"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: UpdateDictionaryReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func UpdateDictionaryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.UpdateDictionaryReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := dictionary.NewUpdateDictionaryLogic(r.Context(), svcCtx)
39 | resp, err := l.UpdateDictionary(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/menu/createOrUpdateMenuHandler.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/menu"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /menu menu CreateOrUpdateMenu
13 | //
14 | // "Create or update menu information | 创建或更新菜单"
15 | //
16 | // "Create or update menu information | 创建或更新菜单"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: CreateOrUpdateMenuReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func CreateOrUpdateMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.CreateOrUpdateMenuReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := menu.NewCreateOrUpdateMenuLogic(r.Context(), svcCtx)
39 | resp, err := l.CreateOrUpdateMenu(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/menu/createOrUpdateMenuParamHandler.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/menu"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /menu/param menu CreateOrUpdateMenuParam
13 | //
14 | // "Create or update menu parameters | 创建或更新菜单参数"
15 | //
16 | // "Create or update menu parameters | 创建或更新菜单参数"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: CreateOrUpdateMenuParamsReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func CreateOrUpdateMenuParamHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.CreateOrUpdateMenuParamsReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := menu.NewCreateOrUpdateMenuParamLogic(r.Context(), svcCtx)
39 | resp, err := l.CreateOrUpdateMenuParam(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/menu/deleteMenuHandler.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/menu"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route delete /menu menu DeleteMenu
13 | //
14 | // "Delete menu information | 删除菜单信息"
15 | //
16 | // "Delete menu information | 删除菜单信息"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: IDReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func DeleteMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.IDReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := menu.NewDeleteMenuLogic(r.Context(), svcCtx)
39 | resp, err := l.DeleteMenu(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/menu/deleteMenuParamHandler.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/menu"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route delete /menu/param menu DeleteMenuParam
13 | //
14 | // "Delete menu extra parameters | 删除菜单额外参数"
15 | //
16 | // "Delete menu extra parameters | 删除菜单额外参数"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: IDReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func DeleteMenuParamHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.IDReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := menu.NewDeleteMenuParamLogic(r.Context(), svcCtx)
39 | resp, err := l.DeleteMenuParam(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/menu/getMenuByRoleHandler.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/menu"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | )
10 |
11 | // swagger:route get /menu/role menu GetMenuByRole
12 | //
13 | // "Get role's menu list API | 获取角色菜单列表"
14 | //
15 | // "Get role's menu list API | 获取角色菜单列表"
16 | //
17 | // Responses:
18 | // 200: GetMenuListBase
19 | //
20 | //
21 |
22 | func GetMenuByRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
23 | return func(w http.ResponseWriter, r *http.Request) {
24 | l := menu.NewGetMenuByRoleLogic(r.Context(), svcCtx)
25 | resp, err := l.GetMenuByRole()
26 | if err != nil {
27 | httpx.Error(w, err)
28 | } else {
29 | httpx.OkJson(w, resp)
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/menu/getMenuListHandler.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/menu"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | )
10 |
11 | // swagger:route get /menu/list menu GetMenuList
12 | //
13 | // "Get menu list | 获取菜单列表"
14 | //
15 | // "Get menu list | 获取菜单列表"
16 | //
17 | // Responses:
18 | // 200: MenuListResp
19 | //
20 | //
21 |
22 | func GetMenuListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
23 | return func(w http.ResponseWriter, r *http.Request) {
24 | l := menu.NewGetMenuListLogic(r.Context(), svcCtx)
25 | resp, err := l.GetMenuList()
26 | if err != nil {
27 | httpx.Error(w, err)
28 | } else {
29 | httpx.OkJson(w, resp)
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/menu/getMenuParamListByMenuIdHandler.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/menu"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /menu/param/list menu GetMenuParamListByMenuId
13 | //
14 | // "Get menu extra parameters by menu ID | 获取某个菜单的额外参数列表"
15 | //
16 | // "Get menu extra parameters by menu ID | 获取某个菜单的额外参数列表"
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: IDReq
23 | //
24 | //
25 | // Responses:
26 | // 200: MenuParamListByMenuIdResp
27 | //
28 | //
29 |
30 | func GetMenuParamListByMenuIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.IDReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := menu.NewGetMenuParamListByMenuIdLogic(r.Context(), svcCtx)
39 | resp, err := l.GetMenuParamListByMenuId(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/oauth/createProviderHandler.go:
--------------------------------------------------------------------------------
1 | package oauth
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/oauth"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /oauth/provider oauth CreateProvider
13 | //
14 | // Create provider information | 创建提供商信息
15 | //
16 | // Create provider information | 创建提供商信息
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: CreateProviderReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func CreateProviderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.CreateProviderReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := oauth.NewCreateProviderLogic(r.Context(), svcCtx)
39 | resp, err := l.CreateProvider(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/oauth/deleteProviderHandler.go:
--------------------------------------------------------------------------------
1 | package oauth
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/oauth"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route delete /oauth/provider oauth DeleteProvider
13 | //
14 | // Delete provider information | 删除提供商信息
15 | //
16 | // Delete provider information | 删除提供商信息
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: IDReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func DeleteProviderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.IDReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := oauth.NewDeleteProviderLogic(r.Context(), svcCtx)
39 | resp, err := l.DeleteProvider(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/oauth/getProviderListHandler.go:
--------------------------------------------------------------------------------
1 | package oauth
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/oauth"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /oauth/provider/list oauth GetProviderList
13 | //
14 | // Get provider list | 获取提供商列表
15 | //
16 | // Get provider list | 获取提供商列表
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: PageReq
23 | //
24 | //
25 | // Responses:
26 | // 200: ProviderListResp
27 | //
28 | //
29 |
30 | func GetProviderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.PageReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := oauth.NewGetProviderListLogic(r.Context(), svcCtx)
39 | resp, err := l.GetProviderList(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/oauth/oauthCallbackHandler.go:
--------------------------------------------------------------------------------
1 | package oauth
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/oauth"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route get /oauth/login/callback oauth OauthCallback
13 | //
14 | // Oauth log in callback route | Oauth 登录回调接口
15 | //
16 | // Oauth log in callback route | Oauth 登录回调接口
17 | //
18 | // Responses:
19 | // 200: CallbackResp
20 | //
21 | //
22 |
23 | func OauthCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
24 | return func(w http.ResponseWriter, r *http.Request) {
25 | var req types.OauthCallbackParamReq
26 | if err := httpx.Parse(r, &req); err != nil {
27 | httpx.Error(w, err)
28 | return
29 | }
30 |
31 | l := oauth.NewOauthCallbackLogic(r.Context(), svcCtx)
32 | resp, err := l.OauthCallback(&req)
33 | if err != nil {
34 | httpx.Error(w, err)
35 | } else {
36 | httpx.OkJson(w, resp)
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/oauth/oauthLoginHandler.go:
--------------------------------------------------------------------------------
1 | package oauth
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/oauth"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /oauth/login oauth OauthLogin
13 | //
14 | // Oauth log in | Oauth 登录
15 | //
16 | // Oauth log in | Oauth 登录
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: OauthLoginReq
23 | //
24 | //
25 | // Responses:
26 | // 200: RedirectResp
27 | //
28 | //
29 |
30 | func OauthLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.OauthLoginReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := oauth.NewOauthLoginLogic(r.Context(), svcCtx)
39 | resp, err := l.OauthLogin(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/oauth/updateProviderHandler.go:
--------------------------------------------------------------------------------
1 | package oauth
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/oauth"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route put /oauth/provider oauth UpdateProvider
13 | //
14 | // Update provider information | 更新提供商信息
15 | //
16 | // Update provider information | 更新提供商信息
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: UpdateProviderReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func UpdateProviderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.UpdateProviderReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := oauth.NewUpdateProviderLogic(r.Context(), svcCtx)
39 | resp, err := l.UpdateProvider(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/token/createTokenHandler.go:
--------------------------------------------------------------------------------
1 | package token
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/token"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /token token CreateToken
13 | //
14 | // Create Token information | 创建Token
15 | //
16 | // Create Token information | 创建Token
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: CreateTokenReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func CreateTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.CreateTokenReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := token.NewCreateTokenLogic(r.Context(), svcCtx)
39 | resp, err := l.CreateToken(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/token/deleteTokenHandler.go:
--------------------------------------------------------------------------------
1 | package token
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/token"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route delete /token token DeleteToken
13 | //
14 | // Delete token information | 删除token信息
15 | //
16 | // Delete token information | 删除token信息
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: IDReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func DeleteTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.IDReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := token.NewDeleteTokenLogic(r.Context(), svcCtx)
39 | resp, err := l.DeleteToken(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/token/getTokenListHandler.go:
--------------------------------------------------------------------------------
1 | package token
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/token"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /token/list token GetTokenList
13 | //
14 | // Get Token list | 获取token列表
15 | //
16 | // Get Token list | 获取token列表
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: TokenListReq
23 | //
24 | //
25 | // Responses:
26 | // 200: TokenListResp
27 | //
28 | //
29 |
30 | func GetTokenListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.TokenListReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := token.NewGetTokenListLogic(r.Context(), svcCtx)
39 | resp, err := l.GetTokenList(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/token/logoutHandler.go:
--------------------------------------------------------------------------------
1 | package token
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/token"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /token/logout token Logout
13 | //
14 | // Force logging out by user UUID | 根据UUID强制用户退出
15 | //
16 | // Force logging out by user UUID | 根据UUID强制用户退出
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: UUIDReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func LogoutHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.UUIDReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := token.NewLogoutLogic(r.Context(), svcCtx)
39 | resp, err := l.Logout(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/token/setTokenStatusHandler.go:
--------------------------------------------------------------------------------
1 | package token
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/token"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /token/status token SetTokenStatus
13 | //
14 | // Set token status | 设置token状态
15 | //
16 | // Set token status | 设置token状态
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: SetBooleanStatusReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func SetTokenStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.SetBooleanStatusReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := token.NewSetTokenStatusLogic(r.Context(), svcCtx)
39 | resp, err := l.SetTokenStatus(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/token/updateTokenHandler.go:
--------------------------------------------------------------------------------
1 | package token
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/token"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route put /token token UpdateToken
13 | //
14 | // Update Token information | 更新Token
15 | //
16 | // Update Token information | 更新Token
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: UpdateTokenReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func UpdateTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.UpdateTokenReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := token.NewUpdateTokenLogic(r.Context(), svcCtx)
39 | resp, err := l.UpdateToken(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/user/changePasswordHandler.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/user"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /user/change-password user ChangePassword
13 | //
14 | // Change Password | 修改密码
15 | //
16 | // Change Password | 修改密码
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: ChangePasswordReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func ChangePasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.ChangePasswordReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := user.NewChangePasswordLogic(r.Context(), svcCtx)
39 | resp, err := l.ChangePassword(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/user/createUserHandler.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/user"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /user user CreateUser
13 | //
14 | // Create user's information | 新增用户
15 | //
16 | // Create user's information | 新增用户
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: CreateUserReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func CreateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.CreateUserReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := user.NewCreateUserLogic(r.Context(), svcCtx)
39 | resp, err := l.CreateUser(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/user/deleteUserHandler.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/user"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route delete /user user DeleteUser
13 | //
14 | // "Delete user information | 删除用户信息
15 | //
16 | // "Delete user information | 删除用户信息
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: IDReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func DeleteUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.IDReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := user.NewDeleteUserLogic(r.Context(), svcCtx)
39 | resp, err := l.DeleteUser(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/user/getUserInfoHandler.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/user"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | )
10 |
11 | // swagger:route get /user/info user GetUserInfo
12 | //
13 | // Get user basic information | 获取用户基本信息
14 | //
15 | // Get user basic information | 获取用户基本信息
16 | //
17 | // Responses:
18 | // 200: GetUserInfoResp
19 | //
20 | //
21 |
22 | func GetUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
23 | return func(w http.ResponseWriter, r *http.Request) {
24 | l := user.NewGetUserInfoLogic(r.Context(), svcCtx)
25 | resp, err := l.GetUserInfo()
26 | if err != nil {
27 | httpx.Error(w, err)
28 | } else {
29 | httpx.OkJson(w, resp)
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/user/getUserListHandler.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/user"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /user/list user GetUserList
13 | //
14 | // Get user list | 获取用户列表
15 | //
16 | // Get user list | 获取用户列表
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: GetUserListReq
23 | //
24 | //
25 | // Responses:
26 | // 200: UserListResp
27 | //
28 | //
29 |
30 | func GetUserListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.GetUserListReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := user.NewGetUserListLogic(r.Context(), svcCtx)
39 | resp, err := l.GetUserList(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/user/getUserPermCodeHandler.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/user"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | )
10 |
11 | // swagger:route get /user/perm user GetUserPermCode
12 | //
13 | // Get user's permission code | 获取用户权限码
14 | //
15 | // Get user's permission code | 获取用户权限码
16 | //
17 | // Responses:
18 | // 200: PermCodeResp
19 | //
20 | //
21 |
22 | func GetUserPermCodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
23 | return func(w http.ResponseWriter, r *http.Request) {
24 | l := user.NewGetUserPermCodeLogic(r.Context(), svcCtx)
25 | resp, err := l.GetUserPermCode()
26 | if err != nil {
27 | httpx.Error(w, err)
28 | } else {
29 | httpx.OkJson(w, resp)
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/user/getUserProfileHandler.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/user"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | )
10 |
11 | // swagger:route get /user/profile user GetUserProfile
12 | //
13 | // Get user's profile | 获取用户个人信息
14 | //
15 | // Get user's profile | 获取用户个人信息
16 | //
17 | // Responses:
18 | // 200: ProfileResp
19 | //
20 | //
21 |
22 | func GetUserProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
23 | return func(w http.ResponseWriter, r *http.Request) {
24 | l := user.NewGetUserProfileLogic(r.Context(), svcCtx)
25 | resp, err := l.GetUserProfile()
26 | if err != nil {
27 | httpx.Error(w, err)
28 | } else {
29 | httpx.OkJson(w, resp)
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/user/loginHandler.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/user"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /user/login user Login
13 | //
14 | // Login | 登录
15 | //
16 | // Login | 登录
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: LoginReq
23 | //
24 | //
25 | // Responses:
26 | // 200: LoginResp
27 | //
28 | //
29 |
30 | func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.LoginReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := user.NewLoginLogic(r.Context(), svcCtx)
39 | resp, err := l.Login(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/user/logoutHandler.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/user"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | )
10 |
11 | // swagger:route get /user/logout user Logout
12 | //
13 | // Log out | 退出登陆
14 | //
15 | // Log out | 退出登陆
16 | //
17 | // Responses:
18 | // 200: SimpleMsgResp
19 | //
20 | //
21 |
22 | func LogoutHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
23 | return func(w http.ResponseWriter, r *http.Request) {
24 | l := user.NewLogoutLogic(r.Context(), svcCtx)
25 | resp, err := l.Logout()
26 | if err != nil {
27 | httpx.Error(w, err)
28 | } else {
29 | httpx.OkJson(w, resp)
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/user/registerHandler.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/user"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /user/register user Register
13 | //
14 | // Register | 注册
15 | //
16 | // Register | 注册
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: RegisterReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func RegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.RegisterReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := user.NewRegisterLogic(r.Context(), svcCtx)
39 | resp, err := l.Register(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/user/updateUserHandler.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/user"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route put /user user UpdateUser
13 | //
14 | // Update user's information | 更新用户
15 | //
16 | // Update user's information | 更新用户
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: UpdateUserReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func UpdateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.UpdateUserReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := user.NewUpdateUserLogic(r.Context(), svcCtx)
39 | resp, err := l.UpdateUser(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/handler/user/updateUserProfileHandler.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/zeromicro/go-zero/rest/httpx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/user"
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 | )
11 |
12 | // swagger:route post /user/profile user UpdateUserProfile
13 | //
14 | // Update user's profile | 更新用户个人信息
15 | //
16 | // Update user's profile | 更新用户个人信息
17 | //
18 | // Parameters:
19 | // + name: body
20 | // require: true
21 | // in: body
22 | // type: UpdateProfileReq
23 | //
24 | //
25 | // Responses:
26 | // 200: SimpleMsgResp
27 | //
28 | //
29 |
30 | func UpdateUserProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
31 | return func(w http.ResponseWriter, r *http.Request) {
32 | var req types.UpdateProfileReq
33 | if err := httpx.Parse(r, &req); err != nil {
34 | httpx.Error(w, err)
35 | return
36 | }
37 |
38 | l := user.NewUpdateUserProfileLogic(r.Context(), svcCtx)
39 | resp, err := l.UpdateUserProfile(&req)
40 | if err != nil {
41 | httpx.Error(w, err)
42 | } else {
43 | httpx.OkJson(w, resp)
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/api/createApiLogic.go:
--------------------------------------------------------------------------------
1 | package api
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/pkg/message"
7 |
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 |
11 | "github.com/zeromicro/go-zero/core/logx"
12 | )
13 |
14 | type CreateApiLogic struct {
15 | logx.Logger
16 | ctx context.Context
17 | svcCtx *svc.ServiceContext
18 | }
19 |
20 | func NewCreateApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateApiLogic {
21 | return &CreateApiLogic{
22 | Logger: logx.WithContext(ctx),
23 | ctx: ctx,
24 | svcCtx: svcCtx,
25 | }
26 | }
27 |
28 | func (l *CreateApiLogic) CreateApi(req *types.CreateApiReq) (resp *types.SimpleMsgResp, err error) {
29 |
30 | err = l.svcCtx.EntClient.SysApi.Create().
31 | SetPath(req.Path).
32 | SetDescription(req.Description).
33 | SetAPIGroup(req.Group).
34 | SetMethod(req.Method).
35 | Exec(l.ctx)
36 |
37 | if err != nil {
38 | l.Errorw("create api error", logx.Field("detail", err.Error()))
39 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
40 | }
41 |
42 | l.Infow("create api success",
43 | logx.Field("path", req.Path),
44 | logx.Field("desc", req.Description),
45 | logx.Field("group", req.Group),
46 | logx.Field("method", req.Method),
47 | )
48 |
49 | return &types.SimpleMsgResp{Msg: errorx.CreateSuccess}, nil
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/api/deleteApiLogic.go:
--------------------------------------------------------------------------------
1 | package api
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/ent"
7 | "slash-admin/pkg/message"
8 |
9 | "slash-admin/app/admin/cmd/api/internal/svc"
10 | "slash-admin/app/admin/cmd/api/internal/types"
11 |
12 | "github.com/zeromicro/go-zero/core/logx"
13 | )
14 |
15 | type DeleteApiLogic struct {
16 | logx.Logger
17 | ctx context.Context
18 | svcCtx *svc.ServiceContext
19 | }
20 |
21 | func NewDeleteApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteApiLogic {
22 | return &DeleteApiLogic{
23 | Logger: logx.WithContext(ctx),
24 | ctx: ctx,
25 | svcCtx: svcCtx,
26 | }
27 | }
28 |
29 | func (l *DeleteApiLogic) DeleteApi(req *types.IDReq) (resp *types.SimpleMsgResp, err error) {
30 | err = l.svcCtx.EntClient.SysApi.DeleteOneID(req.ID).Exec(l.ctx)
31 |
32 | if err != nil {
33 | if ent.IsNotFound(err) {
34 | l.Errorw("delete api error", logx.Field("detail", err.Error()))
35 | return nil, errorx.NewApiBadRequestError(message.ApiNotExists)
36 | }
37 | l.Errorw("delete api error", logx.Field("detail", err.Error()))
38 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
39 | }
40 |
41 | return &types.SimpleMsgResp{Msg: errorx.Success}, nil
42 | }
43 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/api/getApiListLogic.go:
--------------------------------------------------------------------------------
1 | package api
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/cmd/api/internal/svc"
7 | "slash-admin/app/admin/cmd/api/internal/types"
8 | "slash-admin/app/admin/ent/predicate"
9 | "slash-admin/app/admin/ent/sysapi"
10 | "slash-admin/pkg/message"
11 |
12 | "github.com/zeromicro/go-zero/core/logx"
13 | )
14 |
15 | type GetApiListLogic struct {
16 | logx.Logger
17 | ctx context.Context
18 | svcCtx *svc.ServiceContext
19 | }
20 |
21 | func NewGetApiListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiListLogic {
22 | return &GetApiListLogic{
23 | Logger: logx.WithContext(ctx),
24 | ctx: ctx,
25 | svcCtx: svcCtx,
26 | }
27 | }
28 |
29 | func (l *GetApiListLogic) GetApiList(req *types.ApiListReq) (resp *types.ApiListResp, err error) {
30 | var predicates []predicate.SysApi
31 |
32 | if req.Path != nil {
33 | predicates = append(predicates, sysapi.PathContains(*req.Path))
34 | }
35 |
36 | if req.Method != nil {
37 | predicates = append(predicates, sysapi.Method(*req.Method))
38 | }
39 |
40 | if req.Group != nil {
41 | predicates = append(predicates, sysapi.APIGroup(*req.Group))
42 | }
43 |
44 | if req.Description != nil {
45 | predicates = append(predicates, sysapi.DescriptionContains(*req.Description))
46 | }
47 |
48 | page, err := l.svcCtx.EntClient.SysApi.Query().
49 | Where(predicates...).
50 | Page(l.ctx, req.PageNo, req.PageSize)
51 |
52 | if err != nil {
53 | logx.Errorw(message.DatabaseError, logx.Field("detail", err.Error()))
54 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
55 | }
56 |
57 | return &types.ApiListResp{
58 | Pagination: l.svcCtx.Converter.ConvertPagination(page.PageDetails),
59 | List: l.svcCtx.Converter.ConvertSysApiList(page.List),
60 | }, nil
61 | }
62 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/api/updateApiLogic.go:
--------------------------------------------------------------------------------
1 | package api
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/cmd/api/internal/svc"
7 | "slash-admin/app/admin/cmd/api/internal/types"
8 | "slash-admin/app/admin/ent/sysapi"
9 | "slash-admin/pkg/message"
10 |
11 | "github.com/zeromicro/go-zero/core/logx"
12 | )
13 |
14 | type UpdateApiLogic struct {
15 | logx.Logger
16 | ctx context.Context
17 | svcCtx *svc.ServiceContext
18 | }
19 |
20 | func NewUpdateApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateApiLogic {
21 | return &UpdateApiLogic{
22 | Logger: logx.WithContext(ctx),
23 | ctx: ctx,
24 | svcCtx: svcCtx,
25 | }
26 | }
27 |
28 | func (l *UpdateApiLogic) UpdateApi(req *types.UpdateApiReq) (resp *types.SimpleMsgResp, err error) {
29 | exist, err := l.svcCtx.EntClient.SysApi.Query().Where(sysapi.ID(req.ID)).Exist(l.ctx)
30 |
31 | if err != nil {
32 | l.Errorw("update api error", logx.Field("detail", err.Error()))
33 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
34 | }
35 |
36 | if !exist {
37 | l.Errorw("update api error", logx.Field("detail", "api not exist"))
38 | return nil, errorx.NewApiInternalServerError(message.ApiNotExists)
39 | }
40 |
41 | err = l.svcCtx.EntClient.SysApi.UpdateOneID(req.ID).
42 | SetNillablePath(req.Path).
43 | SetNillableDescription(req.Description).
44 | SetNillableAPIGroup(req.Group).
45 | SetNillableMethod(req.Method).
46 | Exec(l.ctx)
47 |
48 | if err != nil {
49 | l.Errorw("update api error", logx.Field("detail", err.Error()))
50 | return nil, errorx.NewApiBadRequestError(message.DatabaseError)
51 | }
52 |
53 | return &types.SimpleMsgResp{
54 | Msg: errorx.UpdateSuccess,
55 | }, nil
56 | }
57 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/authority/createApiAuthorityLogic.go:
--------------------------------------------------------------------------------
1 | package authority
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "net/http"
7 | "strconv"
8 |
9 | "slash-admin/app/admin/cmd/api/internal/svc"
10 | "slash-admin/app/admin/cmd/api/internal/types"
11 |
12 | "github.com/zeromicro/go-zero/core/logx"
13 | )
14 |
15 | type CreateApiAuthorityLogic struct {
16 | logx.Logger
17 | ctx context.Context
18 | svcCtx *svc.ServiceContext
19 | }
20 |
21 | func NewCreateApiAuthorityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateApiAuthorityLogic {
22 | return &CreateApiAuthorityLogic{
23 | Logger: logx.WithContext(ctx),
24 | ctx: ctx,
25 | svcCtx: svcCtx,
26 | }
27 | }
28 |
29 | func (l *CreateApiAuthorityLogic) CreateApiAuthority(req *types.CreateApiAuthorityReq) (resp *types.SimpleMsgResp, err error) {
30 | // clear old policies
31 | roleIdString := strconv.Itoa(int(req.RoleId))
32 | var oldPolicies [][]string
33 | oldPolicies = l.svcCtx.Casbin.GetFilteredPolicy(0, roleIdString)
34 | if len(oldPolicies) != 0 {
35 | removeResult, err := l.svcCtx.Casbin.RemoveFilteredPolicy(0, roleIdString)
36 | if err != nil {
37 | return nil, &errorx.ApiError{
38 | Code: http.StatusInternalServerError,
39 | Msg: err.Error(),
40 | }
41 | }
42 | if !removeResult {
43 | return nil, errorx.NewApiError(http.StatusInternalServerError, "cannot clear old policies")
44 | }
45 | }
46 | // add new policies
47 | var policies [][]string
48 | for _, v := range req.Data {
49 | policies = append(policies, []string{roleIdString, v.Path, v.Method})
50 | }
51 | addResult, err := l.svcCtx.Casbin.AddPolicies(policies)
52 | if err != nil {
53 | return nil, err
54 | }
55 | if addResult {
56 | return &types.SimpleMsgResp{Msg: errorx.UpdateSuccess}, nil
57 | } else {
58 | return nil, errorx.NewApiError(http.StatusBadRequest, errorx.UpdateFailed)
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/authority/getApiAuthorityLogic.go:
--------------------------------------------------------------------------------
1 | package authority
2 |
3 | import (
4 | "context"
5 | "strconv"
6 |
7 | "slash-admin/app/admin/cmd/api/internal/svc"
8 | "slash-admin/app/admin/cmd/api/internal/types"
9 |
10 | "github.com/zeromicro/go-zero/core/logx"
11 | )
12 |
13 | type GetApiAuthorityLogic struct {
14 | logx.Logger
15 | ctx context.Context
16 | svcCtx *svc.ServiceContext
17 | }
18 |
19 | func NewGetApiAuthorityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiAuthorityLogic {
20 | return &GetApiAuthorityLogic{
21 | Logger: logx.WithContext(ctx),
22 | ctx: ctx,
23 | svcCtx: svcCtx,
24 | }
25 | }
26 |
27 | func (l *GetApiAuthorityLogic) GetApiAuthority(req *types.IDReq) (resp *types.ApiAuthorityListResp, err error) {
28 | roleId := strconv.Itoa(int(req.ID))
29 | data := l.svcCtx.Casbin.GetFilteredPolicy(0, roleId)
30 | resp = &types.ApiAuthorityListResp{}
31 | resp.Pagination = &types.Pagination{
32 | Total: len(data),
33 | }
34 | for _, v := range data {
35 | resp.List = append(resp.List, &types.ApiAuthorityInfo{
36 | Path: v[1],
37 | Method: v[2],
38 | })
39 | }
40 | return resp, nil
41 | }
42 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/authority/getMenuAuthorityLogic.go:
--------------------------------------------------------------------------------
1 | package authority
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/ent"
7 | "slash-admin/app/admin/ent/sysrole"
8 | "slash-admin/pkg/message"
9 |
10 | "slash-admin/app/admin/cmd/api/internal/svc"
11 | "slash-admin/app/admin/cmd/api/internal/types"
12 |
13 | "github.com/zeromicro/go-zero/core/logx"
14 | )
15 |
16 | type GetMenuAuthorityLogic struct {
17 | logx.Logger
18 | ctx context.Context
19 | svcCtx *svc.ServiceContext
20 | }
21 |
22 | func NewGetMenuAuthorityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuAuthorityLogic {
23 | return &GetMenuAuthorityLogic{
24 | Logger: logx.WithContext(ctx),
25 | ctx: ctx,
26 | svcCtx: svcCtx,
27 | }
28 | }
29 |
30 | func (l *GetMenuAuthorityLogic) GetMenuAuthority(req *types.IDReq) (resp *types.MenuAuthorityInfoResp, err error) {
31 | role, err := l.svcCtx.EntClient.SysRole.Query().Where(sysrole.IDEQ(req.ID)).WithMenus().First(l.ctx)
32 |
33 | if err != nil {
34 | if ent.IsNotFound(err) {
35 | l.Errorf("query role by id %d not found", req.ID)
36 | return nil, errorx.NewApiBadRequestError(message.RoleNotExists)
37 | }
38 | return nil, errorx.NewApiBadRequestError(message.DatabaseError)
39 | }
40 |
41 | resp = &types.MenuAuthorityInfoResp{
42 | RoleId: req.ID,
43 | MenuIds: []uint64{},
44 | }
45 |
46 | if role.Edges.Menus != nil {
47 | for _, v := range role.Edges.Menus {
48 | resp.MenuIds = append(resp.MenuIds, v.ID)
49 | }
50 | }
51 | return
52 | }
53 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/authority/updateApiAuthorityLogic.go:
--------------------------------------------------------------------------------
1 | package authority
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "net/http"
7 | "strconv"
8 |
9 | "slash-admin/app/admin/cmd/api/internal/svc"
10 | "slash-admin/app/admin/cmd/api/internal/types"
11 |
12 | "github.com/zeromicro/go-zero/core/logx"
13 | )
14 |
15 | type UpdateApiAuthorityLogic struct {
16 | logx.Logger
17 | ctx context.Context
18 | svcCtx *svc.ServiceContext
19 | }
20 |
21 | func NewUpdateApiAuthorityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateApiAuthorityLogic {
22 | return &UpdateApiAuthorityLogic{
23 | Logger: logx.WithContext(ctx),
24 | ctx: ctx,
25 | svcCtx: svcCtx,
26 | }
27 | }
28 |
29 | func (l *UpdateApiAuthorityLogic) UpdateApiAuthority(req *types.UpdateApiAuthorityReq) (resp *types.SimpleMsgResp, err error) {
30 | // clear old policies
31 | roleIdString := strconv.Itoa(int(req.RoleId))
32 | var oldPolicies [][]string
33 | oldPolicies = l.svcCtx.Casbin.GetFilteredPolicy(0, roleIdString)
34 | if len(oldPolicies) != 0 {
35 | removeResult, err := l.svcCtx.Casbin.RemoveFilteredPolicy(0, roleIdString)
36 | if err != nil {
37 | return nil, &errorx.ApiError{
38 | Code: http.StatusInternalServerError,
39 | Msg: err.Error(),
40 | }
41 | }
42 | if !removeResult {
43 | return nil, errorx.NewApiError(http.StatusInternalServerError, "cannot clear old policies")
44 | }
45 | }
46 | // add new policies
47 | var policies [][]string
48 | for _, v := range req.Data {
49 | policies = append(policies, []string{roleIdString, v.Path, v.Method})
50 | }
51 | addResult, err := l.svcCtx.Casbin.AddPolicies(policies)
52 | if err != nil {
53 | return nil, err
54 | }
55 | if addResult {
56 | return &types.SimpleMsgResp{Msg: errorx.UpdateSuccess}, nil
57 | } else {
58 | return nil, errorx.NewApiError(http.StatusBadRequest, errorx.UpdateFailed)
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/captcha/getCaptchaLogic.go:
--------------------------------------------------------------------------------
1 | package captcha
2 |
3 | import (
4 | "context"
5 | "github.com/mojocn/base64Captcha"
6 | "github.com/zeromicro/go-zero/core/errorx"
7 | "github.com/zeromicro/go-zero/core/stores/redis"
8 | "net/http"
9 | "slash-admin/app/admin/cmd/api/internal/config"
10 | "slash-admin/app/admin/cmd/api/internal/svc"
11 | "slash-admin/app/admin/cmd/api/internal/types"
12 | "slash-admin/pkg/captcha"
13 | "slash-admin/pkg/message"
14 | "sync"
15 |
16 | "github.com/zeromicro/go-zero/core/logx"
17 | )
18 |
19 | type GetCaptchaLogic struct {
20 | logx.Logger
21 | ctx context.Context
22 | svcCtx *svc.ServiceContext
23 | }
24 |
25 | var (
26 | once sync.Once
27 | store *captcha.RedisStore
28 | driver *base64Captcha.DriverDigit
29 | )
30 |
31 | func NewGetCaptchaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCaptchaLogic {
32 | return &GetCaptchaLogic{
33 | Logger: logx.WithContext(ctx),
34 | ctx: ctx,
35 | svcCtx: svcCtx,
36 | }
37 | }
38 |
39 | func (l *GetCaptchaLogic) GetCaptcha() (resp *types.CaptchaInfoResp, err error) {
40 | captchaStore, digit := GetCaptchaStore(l.svcCtx.Config, l.svcCtx.Redis)
41 | gen := base64Captcha.NewCaptcha(digit, captchaStore)
42 |
43 | id, b64s, err := gen.Generate()
44 |
45 | if err != nil {
46 | logx.Errorw("fail to generate captcha", logx.Field("detail", err.Error()))
47 | return nil, errorx.NewApiError(http.StatusInternalServerError, message.CaptchaCreateFail)
48 | }
49 |
50 | return &types.CaptchaInfoResp{
51 | CaptchaId: id,
52 | ImgPath: b64s,
53 | }, nil
54 | }
55 |
56 | func GetCaptchaStore(c config.Config, r *redis.Redis) (*captcha.RedisStore, *base64Captcha.DriverDigit) {
57 | once.Do(func() {
58 | driver = base64Captcha.NewDriverDigit(
59 | c.Captcha.ImgHeight,
60 | c.Captcha.ImgWidth,
61 | c.Captcha.KeyLong,
62 | 0.7,
63 | 80,
64 | )
65 | store = captcha.NewCaptchaStoreWithRedis(r)
66 | logx.Info("once: init captcha store")
67 | })
68 | return store, driver
69 | }
70 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/core/healthCheckLogic.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | import (
4 | "context"
5 |
6 | "github.com/zeromicro/go-zero/core/logx"
7 | "slash-admin/app/admin/cmd/api/internal/svc"
8 | )
9 |
10 | type HealthCheckLogic struct {
11 | logx.Logger
12 | ctx context.Context
13 | svcCtx *svc.ServiceContext
14 | }
15 |
16 | func NewHealthCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HealthCheckLogic {
17 | return &HealthCheckLogic{
18 | Logger: logx.WithContext(ctx),
19 | ctx: ctx,
20 | svcCtx: svcCtx,
21 | }
22 | }
23 |
24 | func (l *HealthCheckLogic) HealthCheck() error {
25 | // todo: add your logic here and delete this line
26 |
27 | return nil
28 | }
29 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/dictionary/createDictionaryLogic.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/pkg/message"
7 | pType "slash-admin/pkg/types"
8 |
9 | "slash-admin/app/admin/cmd/api/internal/svc"
10 | "slash-admin/app/admin/cmd/api/internal/types"
11 |
12 | "github.com/zeromicro/go-zero/core/logx"
13 | )
14 |
15 | type CreateDictionaryLogic struct {
16 | logx.Logger
17 | ctx context.Context
18 | svcCtx *svc.ServiceContext
19 | }
20 |
21 | func NewCreateDictionaryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateDictionaryLogic {
22 | return &CreateDictionaryLogic{
23 | Logger: logx.WithContext(ctx),
24 | ctx: ctx,
25 | svcCtx: svcCtx,
26 | }
27 | }
28 |
29 | func (l *CreateDictionaryLogic) CreateDictionary(req *types.CreateDictionaryReq) (resp *types.SimpleMsgResp, err error) {
30 |
31 | details, err := l.svcCtx.EntClient.SysDictionary.Create().
32 | SetTitle(req.Title).
33 | SetName(req.Name).
34 | SetStatus(pType.Status(req.Status)).
35 | SetDesc(req.Description).
36 | Save(l.ctx)
37 |
38 | if err != nil {
39 | l.Errorw("create dictionary error", logx.Field("detail", err.Error()))
40 | return nil, errorx.NewApiBadRequestError(message.DatabaseError)
41 | }
42 |
43 | l.Infow("create dictionary success", logx.Field("detail", details))
44 |
45 | return &types.SimpleMsgResp{Msg: message.CreateSuccess}, nil
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/dictionary/deleteDictionaryDetailLogic.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/ent"
7 | "slash-admin/pkg/message"
8 |
9 | "slash-admin/app/admin/cmd/api/internal/svc"
10 | "slash-admin/app/admin/cmd/api/internal/types"
11 |
12 | "github.com/zeromicro/go-zero/core/logx"
13 | )
14 |
15 | type DeleteDictionaryDetailLogic struct {
16 | logx.Logger
17 | ctx context.Context
18 | svcCtx *svc.ServiceContext
19 | }
20 |
21 | func NewDeleteDictionaryDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDictionaryDetailLogic {
22 | return &DeleteDictionaryDetailLogic{
23 | Logger: logx.WithContext(ctx),
24 | ctx: ctx,
25 | svcCtx: svcCtx,
26 | }
27 | }
28 |
29 | func (l *DeleteDictionaryDetailLogic) DeleteDictionaryDetail(req *types.IDReq) (resp *types.SimpleMsgResp, err error) {
30 |
31 | err = l.svcCtx.EntClient.SysDictionaryDetail.DeleteOneID(req.ID).Exec(l.ctx)
32 |
33 | if err != nil {
34 | if ent.IsNotFound(err) {
35 | l.Errorw("Delete dictionary detail failed, check the id", logx.Field("DetailId", req.ID))
36 | return nil, errorx.NewApiBadRequestError(message.DeleteFailed)
37 | }
38 |
39 | l.Errorw("Delete dictionary detail failed", logx.Field("DetailId", req.ID))
40 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
41 | }
42 |
43 | l.Infow("Delete dictionary detail success", logx.Field("DetailId", req.ID))
44 |
45 | return &types.SimpleMsgResp{Msg: message.DeleteSuccess}, nil
46 | }
47 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/dictionary/deleteDictionaryLogic.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/ent"
7 | "slash-admin/app/admin/ent/sysdictionarydetail"
8 | "slash-admin/pkg/message"
9 | "slash-admin/pkg/utils"
10 |
11 | "slash-admin/app/admin/cmd/api/internal/svc"
12 | "slash-admin/app/admin/cmd/api/internal/types"
13 |
14 | "github.com/zeromicro/go-zero/core/logx"
15 | )
16 |
17 | type DeleteDictionaryLogic struct {
18 | logx.Logger
19 | ctx context.Context
20 | svcCtx *svc.ServiceContext
21 | }
22 |
23 | func NewDeleteDictionaryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDictionaryLogic {
24 | return &DeleteDictionaryLogic{
25 | Logger: logx.WithContext(ctx),
26 | ctx: ctx,
27 | svcCtx: svcCtx,
28 | }
29 | }
30 |
31 | func (l *DeleteDictionaryLogic) DeleteDictionary(req *types.IDReq) (resp *types.SimpleMsgResp, err error) {
32 | err = utils.WithTx(l.ctx, l.svcCtx.EntClient, func(tx *ent.Tx) error {
33 | tx.SysDictionaryDetail.Delete().Where(sysdictionarydetail.DictionaryIDEQ(req.ID)).ExecX(l.ctx)
34 | tx.SysDictionary.DeleteOneID(req.ID).ExecX(l.ctx)
35 | return nil
36 | })
37 |
38 | if err != nil {
39 | l.Errorw("Delete dictionary failed", logx.Field("DictionaryId", req.ID))
40 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
41 | }
42 |
43 | l.Infow("Delete dictionary success", logx.Field("DictionaryId", req.ID))
44 | return &types.SimpleMsgResp{Msg: message.DeleteSuccess}, nil
45 | }
46 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/dictionary/getDetailByDictionaryNameLogic.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/ent/sysdictionary"
7 | "slash-admin/pkg/message"
8 |
9 | "slash-admin/app/admin/cmd/api/internal/svc"
10 | "slash-admin/app/admin/cmd/api/internal/types"
11 |
12 | "github.com/zeromicro/go-zero/core/logx"
13 | )
14 |
15 | type GetDetailByDictionaryNameLogic struct {
16 | logx.Logger
17 | ctx context.Context
18 | svcCtx *svc.ServiceContext
19 | }
20 |
21 | func NewGetDetailByDictionaryNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDetailByDictionaryNameLogic {
22 | return &GetDetailByDictionaryNameLogic{
23 | Logger: logx.WithContext(ctx),
24 | ctx: ctx,
25 | svcCtx: svcCtx,
26 | }
27 | }
28 |
29 | func (l *GetDetailByDictionaryNameLogic) GetDetailByDictionaryName(req *types.DictionaryDetailReq) (resp *types.DictionaryDetailListResp, err error) {
30 |
31 | dict, err := l.svcCtx.EntClient.SysDictionary.Query().
32 | Where(sysdictionary.NameEQ(req.Name)).
33 | WithDetails().
34 | First(l.ctx)
35 |
36 | if err != nil {
37 | l.Errorw("query dictionary detail error", logx.Field("details", err.Error()))
38 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
39 | }
40 |
41 | return &types.DictionaryDetailListResp{
42 | Pagination: &types.Pagination{
43 | Total: len(dict.Edges.Details),
44 | },
45 | List: l.svcCtx.Converter.ConvertSysDictionaryDetailList(dict.Edges.Details),
46 | }, nil
47 | }
48 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/dictionary/getDictionaryListLogic.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/cmd/api/internal/svc"
7 | "slash-admin/app/admin/cmd/api/internal/types"
8 | "slash-admin/app/admin/ent/predicate"
9 | "slash-admin/app/admin/ent/sysdictionary"
10 | "slash-admin/pkg/message"
11 |
12 | "github.com/zeromicro/go-zero/core/logx"
13 | )
14 |
15 | type GetDictionaryListLogic struct {
16 | logx.Logger
17 | ctx context.Context
18 | svcCtx *svc.ServiceContext
19 | }
20 |
21 | func NewGetDictionaryListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDictionaryListLogic {
22 | return &GetDictionaryListLogic{
23 | Logger: logx.WithContext(ctx),
24 | ctx: ctx,
25 | svcCtx: svcCtx,
26 | }
27 | }
28 |
29 | func (l *GetDictionaryListLogic) GetDictionaryList(req *types.DictionaryListReq) (resp *types.DictionaryListResp, err error) {
30 | var predicates []predicate.SysDictionary
31 |
32 | if req.Name != nil {
33 | predicates = append(predicates, sysdictionary.NameContains(*req.Name))
34 | }
35 |
36 | if req.Title != nil {
37 | predicates = append(predicates, sysdictionary.TitleContains(*req.Title))
38 | }
39 |
40 | pageResult, err := l.svcCtx.EntClient.SysDictionary.Query().
41 | Where(predicates...).
42 | Page(l.ctx, req.PageNo, req.PageSize)
43 |
44 | if err != nil {
45 | l.Errorw("query dictionary list error", logx.Field("details", err.Error()))
46 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
47 | }
48 |
49 | return &types.DictionaryListResp{
50 | Pagination: l.svcCtx.Converter.ConvertPagination(pageResult.PageDetails),
51 | List: l.svcCtx.Converter.ConvertSysDictionaryList(pageResult.List),
52 | }, nil
53 | }
54 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/dictionary/updateDictionaryLogic.go:
--------------------------------------------------------------------------------
1 | package dictionary
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/ent/sysdictionary"
7 | "slash-admin/pkg/message"
8 | pType "slash-admin/pkg/types"
9 |
10 | "slash-admin/app/admin/cmd/api/internal/svc"
11 | "slash-admin/app/admin/cmd/api/internal/types"
12 |
13 | "github.com/zeromicro/go-zero/core/logx"
14 | )
15 |
16 | type UpdateDictionaryLogic struct {
17 | logx.Logger
18 | ctx context.Context
19 | svcCtx *svc.ServiceContext
20 | }
21 |
22 | func NewUpdateDictionaryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateDictionaryLogic {
23 | return &UpdateDictionaryLogic{
24 | Logger: logx.WithContext(ctx),
25 | ctx: ctx,
26 | svcCtx: svcCtx,
27 | }
28 | }
29 |
30 | func (l *UpdateDictionaryLogic) UpdateDictionary(req *types.UpdateDictionaryReq) (resp *types.SimpleMsgResp, err error) {
31 |
32 | exist, err := l.svcCtx.EntClient.SysDictionary.Query().Where(sysdictionary.IDEQ(req.ID)).Exist(l.ctx)
33 |
34 | if err != nil {
35 | l.Errorw("update dictionary error", logx.Field("detail", err.Error()))
36 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
37 | }
38 |
39 | if !exist {
40 | l.Errorw("update dictionary error", logx.Field("detail", "dictionary not exist"))
41 | return nil, errorx.NewApiInternalServerError(message.TargetNotExist)
42 | }
43 |
44 | details, err := l.svcCtx.EntClient.SysDictionary.UpdateOneID(req.ID).
45 | SetNillableTitle(req.Title).
46 | SetNillableName(req.Name).
47 | SetNillableStatus((*pType.Status)(req.Status)).
48 | SetNillableDesc(req.Description).
49 | Save(l.ctx)
50 |
51 | if err != nil {
52 | l.Errorw("update dictionary error", logx.Field("detail", err.Error()))
53 | return nil, errorx.NewApiBadRequestError(message.DatabaseError)
54 | }
55 |
56 | l.Infow("update dictionary success", logx.Field("detail", details))
57 |
58 | return &types.SimpleMsgResp{Msg: message.UpdateSuccess}, nil
59 | }
60 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/menu/createOrUpdateMenuLogic.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "context"
5 |
6 | "slash-admin/app/admin/cmd/api/internal/svc"
7 | "slash-admin/app/admin/cmd/api/internal/types"
8 |
9 | "github.com/zeromicro/go-zero/core/logx"
10 | )
11 |
12 | type CreateOrUpdateMenuLogic struct {
13 | logx.Logger
14 | ctx context.Context
15 | svcCtx *svc.ServiceContext
16 | }
17 |
18 | func NewCreateOrUpdateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrUpdateMenuLogic {
19 | return &CreateOrUpdateMenuLogic{
20 | Logger: logx.WithContext(ctx),
21 | ctx: ctx,
22 | svcCtx: svcCtx,
23 | }
24 | }
25 |
26 | func (l *CreateOrUpdateMenuLogic) CreateOrUpdateMenu(req *types.CreateOrUpdateMenuReq) (resp *types.SimpleMsgResp, err error) {
27 | // todo: add your logic here and delete this line
28 |
29 | return
30 | }
31 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/menu/createOrUpdateMenuParamLogic.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "context"
5 |
6 | "slash-admin/app/admin/cmd/api/internal/svc"
7 | "slash-admin/app/admin/cmd/api/internal/types"
8 |
9 | "github.com/zeromicro/go-zero/core/logx"
10 | )
11 |
12 | type CreateOrUpdateMenuParamLogic struct {
13 | logx.Logger
14 | ctx context.Context
15 | svcCtx *svc.ServiceContext
16 | }
17 |
18 | func NewCreateOrUpdateMenuParamLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrUpdateMenuParamLogic {
19 | return &CreateOrUpdateMenuParamLogic{
20 | Logger: logx.WithContext(ctx),
21 | ctx: ctx,
22 | svcCtx: svcCtx,
23 | }
24 | }
25 |
26 | func (l *CreateOrUpdateMenuParamLogic) CreateOrUpdateMenuParam(req *types.CreateOrUpdateMenuParamsReq) (resp *types.SimpleMsgResp, err error) {
27 | // todo: add your logic here and delete this line
28 |
29 | return
30 | }
31 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/menu/deleteMenuLogic.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "github.com/zeromicro/go-zero/core/logx"
7 | "slash-admin/app/admin/cmd/api/internal/svc"
8 | "slash-admin/app/admin/cmd/api/internal/types"
9 | "slash-admin/app/admin/ent"
10 | "slash-admin/app/admin/ent/sysmenu"
11 | "slash-admin/pkg/message"
12 | )
13 |
14 | type DeleteMenuLogic struct {
15 | logx.Logger
16 | ctx context.Context
17 | svcCtx *svc.ServiceContext
18 | }
19 |
20 | func NewDeleteMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteMenuLogic {
21 | return &DeleteMenuLogic{
22 | Logger: logx.WithContext(ctx),
23 | ctx: ctx,
24 | svcCtx: svcCtx,
25 | }
26 | }
27 |
28 | func (l *DeleteMenuLogic) DeleteMenu(req *types.IDReq) (resp *types.SimpleMsgResp, err error) {
29 |
30 | exist, err := l.svcCtx.EntClient.SysMenu.Query().Where(sysmenu.ParentID(req.ID)).Exist(l.ctx)
31 |
32 | if err != nil {
33 | l.Errorw("delete menu error", logx.Field("id", req.ID), logx.Field("error", err))
34 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
35 | }
36 |
37 | if exist {
38 | l.Errorw("Delete Menu failed, check the id", logx.Field("menuId", req.ID))
39 | return nil, errorx.NewApiBadRequestError(message.ChildrenExistError)
40 | }
41 |
42 | err = l.svcCtx.EntClient.SysMenu.DeleteOneID(req.ID).Exec(l.ctx)
43 |
44 | if err != nil {
45 | if ent.IsNotFound(err) {
46 | l.Errorw("Delete Menu failed, check the id", logx.Field("menuParamId", req.ID))
47 | return nil, errorx.NewApiBadRequestError(message.TargetNotExist)
48 | }
49 | l.Errorw("delete menu error", logx.Field("id", req.ID), logx.Field("error", err))
50 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
51 | }
52 |
53 | l.Infow("delete menu successfully", logx.Field("menuId", req.ID))
54 |
55 | return &types.SimpleMsgResp{Msg: message.DeleteSuccess}, nil
56 | }
57 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/menu/deleteMenuParamLogic.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/ent"
7 | "slash-admin/pkg/message"
8 |
9 | "slash-admin/app/admin/cmd/api/internal/svc"
10 | "slash-admin/app/admin/cmd/api/internal/types"
11 |
12 | "github.com/zeromicro/go-zero/core/logx"
13 | )
14 |
15 | type DeleteMenuParamLogic struct {
16 | logx.Logger
17 | ctx context.Context
18 | svcCtx *svc.ServiceContext
19 | }
20 |
21 | func NewDeleteMenuParamLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteMenuParamLogic {
22 | return &DeleteMenuParamLogic{
23 | Logger: logx.WithContext(ctx),
24 | ctx: ctx,
25 | svcCtx: svcCtx,
26 | }
27 | }
28 |
29 | func (l *DeleteMenuParamLogic) DeleteMenuParam(req *types.IDReq) (resp *types.SimpleMsgResp, err error) {
30 | err = l.svcCtx.EntClient.SysMenuParam.DeleteOneID(req.ID).Exec(l.ctx)
31 |
32 | if err != nil {
33 | if ent.IsNotFound(err) {
34 | l.Errorw("Delete Menu parameter failed, check the id", logx.Field("menuParamId", req.ID))
35 | return nil, errorx.NewApiBadRequestError(message.TargetNotExist)
36 | }
37 | l.Errorw("delete menu parameter error", logx.Field("id", req.ID), logx.Field("error", err))
38 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
39 | }
40 |
41 | return &types.SimpleMsgResp{Msg: message.DeleteSuccess}, nil
42 | }
43 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/menu/getMenuByRoleLogic.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "context"
5 |
6 | "slash-admin/app/admin/cmd/api/internal/svc"
7 | "slash-admin/app/admin/cmd/api/internal/types"
8 |
9 | "github.com/zeromicro/go-zero/core/logx"
10 | )
11 |
12 | type GetMenuByRoleLogic struct {
13 | logx.Logger
14 | ctx context.Context
15 | svcCtx *svc.ServiceContext
16 | }
17 |
18 | func NewGetMenuByRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuByRoleLogic {
19 | return &GetMenuByRoleLogic{
20 | Logger: logx.WithContext(ctx),
21 | ctx: ctx,
22 | svcCtx: svcCtx,
23 | }
24 | }
25 |
26 | func (l *GetMenuByRoleLogic) GetMenuByRole() (resp *types.GetMenuListBase, err error) {
27 | // todo: add your logic here and delete this line
28 |
29 | return
30 | }
31 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/menu/getMenuListLogic.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "context"
5 |
6 | "slash-admin/app/admin/cmd/api/internal/svc"
7 | "slash-admin/app/admin/cmd/api/internal/types"
8 |
9 | "github.com/zeromicro/go-zero/core/logx"
10 | )
11 |
12 | type GetMenuListLogic struct {
13 | logx.Logger
14 | ctx context.Context
15 | svcCtx *svc.ServiceContext
16 | }
17 |
18 | func NewGetMenuListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuListLogic {
19 | return &GetMenuListLogic{
20 | Logger: logx.WithContext(ctx),
21 | ctx: ctx,
22 | svcCtx: svcCtx,
23 | }
24 | }
25 |
26 | func (l *GetMenuListLogic) GetMenuList() (resp *types.MenuListResp, err error) {
27 | // todo: add your logic here and delete this line
28 |
29 | return
30 | }
31 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/menu/getMenuParamListByMenuIdLogic.go:
--------------------------------------------------------------------------------
1 | package menu
2 |
3 | import (
4 | "context"
5 |
6 | "slash-admin/app/admin/cmd/api/internal/svc"
7 | "slash-admin/app/admin/cmd/api/internal/types"
8 |
9 | "github.com/zeromicro/go-zero/core/logx"
10 | )
11 |
12 | type GetMenuParamListByMenuIdLogic struct {
13 | logx.Logger
14 | ctx context.Context
15 | svcCtx *svc.ServiceContext
16 | }
17 |
18 | func NewGetMenuParamListByMenuIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuParamListByMenuIdLogic {
19 | return &GetMenuParamListByMenuIdLogic{
20 | Logger: logx.WithContext(ctx),
21 | ctx: ctx,
22 | svcCtx: svcCtx,
23 | }
24 | }
25 |
26 | func (l *GetMenuParamListByMenuIdLogic) GetMenuParamListByMenuId(req *types.IDReq) (resp *types.MenuParamListByMenuIdResp, err error) {
27 | // todo: add your logic here and delete this line
28 |
29 | return
30 | }
31 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/oauth/createProviderLogic.go:
--------------------------------------------------------------------------------
1 | package oauth
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/pkg/message"
7 |
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 |
11 | "github.com/zeromicro/go-zero/core/logx"
12 | )
13 |
14 | type CreateProviderLogic struct {
15 | logx.Logger
16 | ctx context.Context
17 | svcCtx *svc.ServiceContext
18 | }
19 |
20 | func NewCreateProviderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateProviderLogic {
21 | return &CreateProviderLogic{
22 | Logger: logx.WithContext(ctx),
23 | ctx: ctx,
24 | svcCtx: svcCtx,
25 | }
26 | }
27 |
28 | func (l *CreateProviderLogic) CreateProvider(req *types.CreateProviderReq) (resp *types.SimpleMsgResp, err error) {
29 | err = l.svcCtx.EntClient.SysOauthProvider.Create().
30 | SetName(req.Name).
31 | SetClientID(req.ClientID).
32 | SetClientSecret(req.ClientSecret).
33 | SetRedirectURL(req.RedirectURL).
34 | SetScopes(req.Scopes).
35 | SetAuthURL(req.AuthURL).
36 | SetTokenURL(req.TokenURL).
37 | SetAuthStyle(req.AuthStyle).
38 | SetInfoURL(req.InfoURL).
39 | Exec(context.Background())
40 |
41 | if err != nil {
42 | l.Errorf("create provider error: %v", err)
43 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
44 | }
45 |
46 | return &types.SimpleMsgResp{Msg: errorx.CreateSuccess}, nil
47 | }
48 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/oauth/deleteProviderLogic.go:
--------------------------------------------------------------------------------
1 | package oauth
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/ent"
7 | "slash-admin/pkg/message"
8 |
9 | "slash-admin/app/admin/cmd/api/internal/svc"
10 | "slash-admin/app/admin/cmd/api/internal/types"
11 |
12 | "github.com/zeromicro/go-zero/core/logx"
13 | )
14 |
15 | type DeleteProviderLogic struct {
16 | logx.Logger
17 | ctx context.Context
18 | svcCtx *svc.ServiceContext
19 | }
20 |
21 | func NewDeleteProviderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteProviderLogic {
22 | return &DeleteProviderLogic{
23 | Logger: logx.WithContext(ctx),
24 | ctx: ctx,
25 | svcCtx: svcCtx,
26 | }
27 | }
28 |
29 | func (l *DeleteProviderLogic) DeleteProvider(req *types.IDReq) (resp *types.SimpleMsgResp, err error) {
30 | err = l.svcCtx.EntClient.SysOauthProvider.DeleteOneID(req.ID).Exec(l.ctx)
31 |
32 | if err != nil {
33 | if ent.IsNotFound(err) {
34 | logx.Errorw("Delete provider failed, check the id", logx.Field("ProviderId", req.ID))
35 | return nil, errorx.NewApiBadRequestError(errorx.DeleteFailed)
36 | }
37 | l.Errorw("delete provider error", logx.Field("detail", err.Error()))
38 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
39 | }
40 |
41 | l.Infow("Delete provider successfully", logx.Field("ProviderId", req.ID))
42 |
43 | return &types.SimpleMsgResp{Msg: errorx.DeleteSuccess}, nil
44 | }
45 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/oauth/getProviderListLogic.go:
--------------------------------------------------------------------------------
1 | package oauth
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/pkg/message"
7 |
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 |
11 | "github.com/zeromicro/go-zero/core/logx"
12 | )
13 |
14 | type GetProviderListLogic struct {
15 | logx.Logger
16 | ctx context.Context
17 | svcCtx *svc.ServiceContext
18 | }
19 |
20 | func NewGetProviderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProviderListLogic {
21 | return &GetProviderListLogic{
22 | Logger: logx.WithContext(ctx),
23 | ctx: ctx,
24 | svcCtx: svcCtx,
25 | }
26 | }
27 |
28 | func (l *GetProviderListLogic) GetProviderList(req *types.PageReq) (resp *types.ProviderListResp, err error) {
29 | pageResult, err := l.svcCtx.EntClient.SysOauthProvider.Query().Page(l.ctx, req.PageNo, req.PageSize)
30 |
31 | if err != nil {
32 | l.Error("query oauth provider list error: %v", err)
33 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
34 | }
35 |
36 | return &types.ProviderListResp{
37 | Pagination: l.svcCtx.Converter.ConvertPagination(pageResult.PageDetails),
38 | List: l.svcCtx.Converter.ConvertSysOauthProviderList(pageResult.List),
39 | }, nil
40 | }
41 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/role/deleteRoleLogic.go:
--------------------------------------------------------------------------------
1 | package role
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "net/http"
7 | "slash-admin/app/admin/ent/sysuser"
8 | "slash-admin/pkg/message"
9 |
10 | "slash-admin/app/admin/cmd/api/internal/svc"
11 | "slash-admin/app/admin/cmd/api/internal/types"
12 |
13 | "github.com/zeromicro/go-zero/core/logx"
14 | )
15 |
16 | type DeleteRoleLogic struct {
17 | logx.Logger
18 | ctx context.Context
19 | svcCtx *svc.ServiceContext
20 | }
21 |
22 | func NewDeleteRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteRoleLogic {
23 | return &DeleteRoleLogic{
24 | Logger: logx.WithContext(ctx),
25 | ctx: ctx,
26 | svcCtx: svcCtx,
27 | }
28 | }
29 |
30 | func (l *DeleteRoleLogic) DeleteRole(req *types.IDPathReq) (resp *types.SimpleMsgResp, err error) {
31 | // check users has this role
32 | exist, err := l.svcCtx.EntClient.SysUser.Query().Where(sysuser.RoleIDEQ(req.ID)).Exist(l.ctx)
33 |
34 | if err != nil {
35 | l.Errorf("check role exist error: %v", err)
36 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
37 | }
38 |
39 | if exist {
40 | logx.Errorw("delete role failed, please check the users who belongs to the role had been deleted",
41 | logx.Field("roleId", req.ID))
42 | return nil, errorx.NewApiError(http.StatusBadRequest, message.UserExists)
43 | }
44 |
45 | err = l.svcCtx.EntClient.SysRole.DeleteOneID(req.ID).Exec(l.ctx)
46 |
47 | if err != nil {
48 | l.Errorf("SysRole delete error: %v", err)
49 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
50 | }
51 |
52 | l.Infow("delete role successfully", logx.Field("roleId", req.ID))
53 |
54 | return &types.SimpleMsgResp{
55 | Msg: errorx.DeleteSuccess,
56 | }, nil
57 | }
58 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/role/getRoleListLogic.go:
--------------------------------------------------------------------------------
1 | package role
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/pkg/message"
7 |
8 | "slash-admin/app/admin/cmd/api/internal/svc"
9 | "slash-admin/app/admin/cmd/api/internal/types"
10 |
11 | "github.com/zeromicro/go-zero/core/logx"
12 | )
13 |
14 | type GetRoleListLogic struct {
15 | logx.Logger
16 | ctx context.Context
17 | svcCtx *svc.ServiceContext
18 | }
19 |
20 | func NewGetRoleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRoleListLogic {
21 | return &GetRoleListLogic{
22 | Logger: logx.WithContext(ctx),
23 | ctx: ctx,
24 | svcCtx: svcCtx,
25 | }
26 | }
27 |
28 | func (l *GetRoleListLogic) GetRoleList(req *types.PageParamReq) (resp *types.RoleListResp, err error) {
29 | page, err := l.svcCtx.EntClient.SysRole.Query().Page(l.ctx, req.PageNo, req.PageSize)
30 |
31 | if err != nil {
32 | l.Errorw(message.DatabaseError, logx.Field("detail", err.Error()))
33 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
34 | }
35 |
36 | return &types.RoleListResp{
37 | Pagination: l.svcCtx.Converter.ConvertPagination(page.PageDetails),
38 | List: l.svcCtx.Converter.ConvertSysRoleToRoleInfoList(page.List),
39 | }, nil
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/role/setRoleStatusLogic.go:
--------------------------------------------------------------------------------
1 | package role
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/pkg/message"
7 | pType "slash-admin/pkg/types"
8 |
9 | "slash-admin/app/admin/cmd/api/internal/svc"
10 | "slash-admin/app/admin/cmd/api/internal/types"
11 |
12 | "github.com/zeromicro/go-zero/core/logx"
13 | )
14 |
15 | type SetRoleStatusLogic struct {
16 | logx.Logger
17 | ctx context.Context
18 | svcCtx *svc.ServiceContext
19 | }
20 |
21 | func NewSetRoleStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetRoleStatusLogic {
22 | return &SetRoleStatusLogic{
23 | Logger: logx.WithContext(ctx),
24 | ctx: ctx,
25 | svcCtx: svcCtx,
26 | }
27 | }
28 |
29 | func (l *SetRoleStatusLogic) SetRoleStatus(req *types.SetStatusReq) (resp *types.SimpleMsgResp, err error) {
30 | if req.Status != 0 {
31 | req.Status = 1
32 | }
33 | _, err = l.svcCtx.EntClient.SysRole.UpdateOneID(req.ID).SetStatus(pType.Status(req.Status)).Save(l.ctx)
34 |
35 | if err != nil {
36 | logx.Errorw("update role status failed, please check the role id", logx.Field("roleId", req.ID))
37 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
38 | }
39 | logx.Infow("update role status successfully", logx.Field("roleID", req.ID), logx.Field("status", req.Status))
40 | return &types.SimpleMsgResp{Msg: message.UpdateSuccess}, nil
41 | }
42 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/token/createTokenLogic.go:
--------------------------------------------------------------------------------
1 | package token
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/cmd/api/internal/svc"
7 | "slash-admin/app/admin/cmd/api/internal/types"
8 | "slash-admin/pkg/message"
9 | pType "slash-admin/pkg/types"
10 | "time"
11 |
12 | "github.com/zeromicro/go-zero/core/logx"
13 | )
14 |
15 | type CreateTokenLogic struct {
16 | logx.Logger
17 | ctx context.Context
18 | svcCtx *svc.ServiceContext
19 | }
20 |
21 | func NewCreateTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateTokenLogic {
22 | return &CreateTokenLogic{
23 | Logger: logx.WithContext(ctx),
24 | ctx: ctx,
25 | svcCtx: svcCtx,
26 | }
27 | }
28 |
29 | func (l *CreateTokenLogic) CreateToken(req *types.CreateTokenReq) (resp *types.SimpleMsgResp, err error) {
30 |
31 | _, err = l.svcCtx.EntClient.SysToken.Create().
32 | SetUUID(req.UUID).
33 | SetToken(req.Token).
34 | SetStatus(pType.Status(req.Status)).
35 | SetSource(req.Source).
36 | SetExpiredAt(time.Unix(req.ExpireAt, 0)).
37 | Save(l.ctx)
38 |
39 | if err != nil {
40 | logx.Errorw(message.DatabaseError, logx.Field("detail", err.Error()))
41 | return nil, errorx.NewApiInternalServerError(err.Error())
42 | }
43 | return &types.SimpleMsgResp{Msg: errorx.CreateSuccess}, nil
44 | }
45 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/token/deleteTokenLogic.go:
--------------------------------------------------------------------------------
1 | package token
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 |
7 | "slash-admin/app/admin/cmd/api/internal/svc"
8 | "slash-admin/app/admin/cmd/api/internal/types"
9 |
10 | "github.com/zeromicro/go-zero/core/logx"
11 | )
12 |
13 | type DeleteTokenLogic struct {
14 | logx.Logger
15 | ctx context.Context
16 | svcCtx *svc.ServiceContext
17 | }
18 |
19 | func NewDeleteTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteTokenLogic {
20 | return &DeleteTokenLogic{
21 | Logger: logx.WithContext(ctx),
22 | ctx: ctx,
23 | svcCtx: svcCtx,
24 | }
25 | }
26 |
27 | func (l *DeleteTokenLogic) DeleteToken(req *types.IDReq) (resp *types.SimpleMsgResp, err error) {
28 | err = l.svcCtx.EntClient.SysToken.DeleteOneID(req.ID).Exec(l.ctx)
29 |
30 | if err != nil {
31 | l.Errorw("Delete token failed", logx.Field("detail", err.Error()))
32 | return nil, errorx.NewApiBadRequestError(err.Error())
33 | }
34 |
35 | l.Infow("Delete token successfully", logx.Field("TokenId", req.ID))
36 |
37 | return &types.SimpleMsgResp{Msg: "Delete token successfully"}, nil
38 | }
39 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/token/logoutLogic.go:
--------------------------------------------------------------------------------
1 | package token
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/cmd/api/internal/globalkey"
7 | "slash-admin/app/admin/ent/systoken"
8 | "slash-admin/pkg/message"
9 | "time"
10 |
11 | "slash-admin/app/admin/cmd/api/internal/svc"
12 | "slash-admin/app/admin/cmd/api/internal/types"
13 |
14 | "github.com/zeromicro/go-zero/core/logx"
15 | )
16 |
17 | type LogoutLogic struct {
18 | logx.Logger
19 | ctx context.Context
20 | svcCtx *svc.ServiceContext
21 | }
22 |
23 | func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogic {
24 | return &LogoutLogic{
25 | Logger: logx.WithContext(ctx),
26 | ctx: ctx,
27 | svcCtx: svcCtx,
28 | }
29 | }
30 |
31 | func (l *LogoutLogic) Logout(req *types.UUIDReq) (resp *types.SimpleMsgResp, err error) {
32 | UUID := l.ctx.Value(globalkey.JWTUserId).(string)
33 |
34 | _, err = l.svcCtx.EntClient.SysToken.Update().Where(systoken.UUIDEQ(UUID)).SetStatus(0).Save(l.ctx)
35 |
36 | if err != nil {
37 | logx.Errorw("logout: set token status to disabled", logx.Field("detail", err.Error()))
38 | return nil, errorx.NewApiBadRequestError(message.DatabaseError)
39 | }
40 |
41 | allTokens, err := l.svcCtx.EntClient.SysToken.Query().
42 | Where(systoken.UUIDEQ(UUID)).
43 | Where(systoken.StatusEQ(0)).
44 | Where(systoken.ExpiredAtGT(time.Now())).
45 | All(l.ctx)
46 |
47 | if err != nil {
48 | logx.Errorw("logout: get all not expired tokens", logx.Field("detail", err.Error()))
49 | return nil, errorx.NewApiBadRequestError(message.DatabaseError)
50 | }
51 |
52 | for _, v := range allTokens {
53 | err := l.svcCtx.Redis.Set(globalkey.GetBlackListToken(v.Token), "1")
54 | if err != nil {
55 | logx.Errorw("logout: set token to redis", logx.Field("detail", err.Error()))
56 | return nil, errorx.NewApiBadRequestError(message.RedisError)
57 | }
58 | }
59 |
60 | return &types.SimpleMsgResp{Msg: errorx.UpdateSuccess}, nil
61 | }
62 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/user/deleteUserLogic.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/ent"
7 | "slash-admin/pkg/message"
8 |
9 | "slash-admin/app/admin/cmd/api/internal/svc"
10 | "slash-admin/app/admin/cmd/api/internal/types"
11 |
12 | "github.com/zeromicro/go-zero/core/logx"
13 | )
14 |
15 | type DeleteUserLogic struct {
16 | logx.Logger
17 | ctx context.Context
18 | svcCtx *svc.ServiceContext
19 | }
20 |
21 | func NewDeleteUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteUserLogic {
22 | return &DeleteUserLogic{
23 | Logger: logx.WithContext(ctx),
24 | ctx: ctx,
25 | svcCtx: svcCtx,
26 | }
27 | }
28 |
29 | func (l *DeleteUserLogic) DeleteUser(req *types.IDReq) (resp *types.SimpleMsgResp, err error) {
30 | err = l.svcCtx.EntClient.SysUser.DeleteOneID(req.ID).Exec(l.ctx)
31 |
32 | if err != nil {
33 | if ent.IsNotFound(err) {
34 | logx.Errorw("delete user failed, please check the user id", logx.Field("userId", req.ID))
35 | return &types.SimpleMsgResp{Msg: errorx.DeleteFailed}, nil
36 | }
37 | logx.Errorw(message.DatabaseError, logx.Field("detail", err.Error()))
38 | return nil, errorx.NewApiBadRequestError(message.DatabaseError)
39 | }
40 |
41 | logx.Infow("delete user successfully", logx.Field("userId", req.ID))
42 |
43 | return &types.SimpleMsgResp{Msg: errorx.DeleteSuccess}, nil
44 | }
45 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/user/getUserInfoLogic.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "net/http"
7 | "slash-admin/app/admin/cmd/api/internal/globalkey"
8 | "slash-admin/app/admin/ent"
9 | "slash-admin/app/admin/ent/sysuser"
10 | "slash-admin/pkg/message"
11 |
12 | "slash-admin/app/admin/cmd/api/internal/svc"
13 | "slash-admin/app/admin/cmd/api/internal/types"
14 |
15 | "github.com/zeromicro/go-zero/core/logx"
16 | )
17 |
18 | type GetUserInfoLogic struct {
19 | logx.Logger
20 | ctx context.Context
21 | svcCtx *svc.ServiceContext
22 | }
23 |
24 | func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
25 | return &GetUserInfoLogic{
26 | Logger: logx.WithContext(ctx),
27 | ctx: ctx,
28 | svcCtx: svcCtx,
29 | }
30 | }
31 |
32 | func (l *GetUserInfoLogic) GetUserInfo() (resp *types.GetUserInfoResp, err error) {
33 | uuid := l.ctx.Value(globalkey.JWTUserId).(string)
34 |
35 | if uuid == "" {
36 | l.Errorf("GetUserInfoLogic.GetUserInfo: %s", "Please log in")
37 | return nil, errorx.NewApiError(http.StatusUnauthorized, "Please log in")
38 | }
39 |
40 | user, err := l.svcCtx.EntClient.SysUser.Query().Where(sysuser.UUIDEQ(uuid)).First(l.ctx)
41 |
42 | if err != nil {
43 | if ent.IsNotFound(err) {
44 | l.Errorf("GetUserInfoLogic.GetUserInfo: %s", message.UserNotExists)
45 | return nil, errorx.NewApiBadRequestError(message.UserNotExists)
46 | }
47 | return nil, errorx.NewApiBadRequestError(message.DatabaseError)
48 | }
49 |
50 | var roleMeta = &types.RoleMetaInfo{}
51 |
52 | if user.Edges.Role != nil {
53 | roleMeta.RoleName = user.Edges.Role.Name
54 | roleMeta.Value = user.Edges.Role.Value
55 | }
56 |
57 | return &types.GetUserInfoResp{
58 | User: l.svcCtx.Converter.ConvertSysUser(user),
59 | Roles: roleMeta,
60 | }, nil
61 | }
62 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/user/getUserListLogic.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/ent/predicate"
7 | "slash-admin/app/admin/ent/sysuser"
8 | "slash-admin/pkg/message"
9 |
10 | "slash-admin/app/admin/cmd/api/internal/svc"
11 | "slash-admin/app/admin/cmd/api/internal/types"
12 |
13 | "github.com/zeromicro/go-zero/core/logx"
14 | )
15 |
16 | type GetUserListLogic struct {
17 | logx.Logger
18 | ctx context.Context
19 | svcCtx *svc.ServiceContext
20 | }
21 |
22 | func NewGetUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserListLogic {
23 | return &GetUserListLogic{
24 | Logger: logx.WithContext(ctx),
25 | ctx: ctx,
26 | svcCtx: svcCtx,
27 | }
28 | }
29 |
30 | func (l *GetUserListLogic) GetUserList(req *types.GetUserListReq) (resp *types.UserListResp, err error) {
31 | var predicates []predicate.SysUser
32 | if req.Username != "" {
33 | predicates = append(predicates, sysuser.UsernameContains(req.Username))
34 | }
35 | if req.Nickname != "" {
36 | predicates = append(predicates, sysuser.NicknameContains(req.Nickname))
37 | }
38 | if req.Email != "" {
39 | predicates = append(predicates, sysuser.EmailContains(req.Email))
40 | }
41 | if req.Mobile != "" {
42 | predicates = append(predicates, sysuser.MobileContains(req.Mobile))
43 | }
44 | if req.RoleId != 0 {
45 | predicates = append(predicates, sysuser.RoleIDEQ(req.RoleId))
46 | }
47 |
48 | pageResult, err := l.svcCtx.EntClient.SysUser.Query().Where(predicates...).Page(l.ctx, req.PageNo, req.PageSize)
49 |
50 | if err != nil {
51 | logx.Errorw(message.DatabaseError, logx.Field("detail", err.Error()))
52 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
53 | }
54 |
55 | return &types.UserListResp{
56 | Pagination: l.svcCtx.Converter.ConvertPagination(pageResult.PageDetails),
57 | List: l.svcCtx.Converter.ConvertSysUserList(pageResult.List),
58 | }, nil
59 | }
60 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/user/getUserPermCodeLogic.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "github.com/zeromicro/go-zero/core/errorx"
7 | "net/http"
8 | "slash-admin/app/admin/cmd/api/internal/globalkey"
9 |
10 | "slash-admin/app/admin/cmd/api/internal/svc"
11 | "slash-admin/app/admin/cmd/api/internal/types"
12 |
13 | "github.com/zeromicro/go-zero/core/logx"
14 | )
15 |
16 | type GetUserPermCodeLogic struct {
17 | logx.Logger
18 | ctx context.Context
19 | svcCtx *svc.ServiceContext
20 | }
21 |
22 | func NewGetUserPermCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserPermCodeLogic {
23 | return &GetUserPermCodeLogic{
24 | Logger: logx.WithContext(ctx),
25 | ctx: ctx,
26 | svcCtx: svcCtx,
27 | }
28 | }
29 |
30 | func (l *GetUserPermCodeLogic) GetUserPermCode() (resp *types.PermCodeResp, err error) {
31 | roleId := l.ctx.Value(globalkey.JWTRoleId)
32 | if roleId == nil {
33 | return nil, &errorx.ApiError{Code: http.StatusUnauthorized, Msg: "sys.login.requireLogin"}
34 | }
35 | return &types.PermCodeResp{Data: []string{fmt.Sprintf("%v", roleId)}}, nil
36 | }
37 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/user/getUserProfileLogic.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/cmd/api/internal/globalkey"
7 | "slash-admin/app/admin/ent"
8 | "slash-admin/app/admin/ent/sysuser"
9 | "slash-admin/pkg/message"
10 |
11 | "slash-admin/app/admin/cmd/api/internal/svc"
12 | "slash-admin/app/admin/cmd/api/internal/types"
13 |
14 | "github.com/zeromicro/go-zero/core/logx"
15 | )
16 |
17 | type GetUserProfileLogic struct {
18 | logx.Logger
19 | ctx context.Context
20 | svcCtx *svc.ServiceContext
21 | }
22 |
23 | func NewGetUserProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserProfileLogic {
24 | return &GetUserProfileLogic{
25 | Logger: logx.WithContext(ctx),
26 | ctx: ctx,
27 | svcCtx: svcCtx,
28 | }
29 | }
30 |
31 | func (l *GetUserProfileLogic) GetUserProfile() (resp *types.ProfileResp, err error) {
32 |
33 | UUID := l.ctx.Value(globalkey.JWTUserId).(string)
34 |
35 | user, err := l.svcCtx.EntClient.SysUser.Query().Where(sysuser.UUIDEQ(UUID)).First(l.ctx)
36 |
37 | if err != nil {
38 | if ent.IsNotFound(err) {
39 | return nil, errorx.NewApiBadRequestError(message.UserNotExists)
40 | }
41 | return nil, errorx.NewApiBadRequestError(message.DatabaseError)
42 | }
43 |
44 | resp.User = l.svcCtx.Converter.ConvertSysUser(user)
45 |
46 | return
47 | }
48 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/user/logoutLogic.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/cmd/api/internal/globalkey"
7 | "slash-admin/app/admin/ent/systoken"
8 | "slash-admin/pkg/message"
9 | "time"
10 |
11 | "slash-admin/app/admin/cmd/api/internal/svc"
12 | "slash-admin/app/admin/cmd/api/internal/types"
13 |
14 | "github.com/zeromicro/go-zero/core/logx"
15 | )
16 |
17 | type LogoutLogic struct {
18 | logx.Logger
19 | ctx context.Context
20 | svcCtx *svc.ServiceContext
21 | }
22 |
23 | func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogic {
24 | return &LogoutLogic{
25 | Logger: logx.WithContext(ctx),
26 | ctx: ctx,
27 | svcCtx: svcCtx,
28 | }
29 | }
30 |
31 | func (l *LogoutLogic) Logout() (resp *types.SimpleMsgResp, err error) {
32 | UUID := l.ctx.Value(globalkey.JWTUserId).(string)
33 |
34 | _, err = l.svcCtx.EntClient.SysToken.Update().Where(systoken.UUIDEQ(UUID)).SetStatus(0).Save(l.ctx)
35 |
36 | if err != nil {
37 | logx.Errorw("logout: set token status to disabled", logx.Field("detail", err.Error()))
38 | return nil, errorx.NewApiBadRequestError(message.DatabaseError)
39 | }
40 |
41 | allTokens, err := l.svcCtx.EntClient.SysToken.Query().
42 | Where(systoken.UUIDEQ(UUID)).
43 | Where(systoken.StatusEQ(0)).
44 | Where(systoken.ExpiredAtGT(time.Now())).
45 | All(l.ctx)
46 |
47 | if err != nil {
48 | logx.Errorw("logout: get all not expired tokens", logx.Field("detail", err.Error()))
49 | return nil, errorx.NewApiBadRequestError(message.DatabaseError)
50 | }
51 |
52 | for _, v := range allTokens {
53 | err := l.svcCtx.Redis.Set(globalkey.GetBlackListToken(v.Token), "1")
54 | if err != nil {
55 | logx.Errorw("logout: set token to redis", logx.Field("detail", err.Error()))
56 | return nil, errorx.NewApiBadRequestError(message.RedisError)
57 | }
58 | }
59 |
60 | return &types.SimpleMsgResp{Msg: errorx.UpdateSuccess}, nil
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/user/registerLogic.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "context"
5 | "github.com/google/uuid"
6 | "github.com/zeromicro/go-zero/core/errorx"
7 | "slash-admin/app/admin/cmd/api/internal/logic/captcha"
8 | "slash-admin/pkg/message"
9 | "slash-admin/pkg/utils"
10 |
11 | "slash-admin/app/admin/cmd/api/internal/svc"
12 | "slash-admin/app/admin/cmd/api/internal/types"
13 |
14 | "github.com/zeromicro/go-zero/core/logx"
15 | )
16 |
17 | type RegisterLogic struct {
18 | logx.Logger
19 | ctx context.Context
20 | svcCtx *svc.ServiceContext
21 | }
22 |
23 | func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
24 | return &RegisterLogic{
25 | Logger: logx.WithContext(ctx),
26 | ctx: ctx,
27 | svcCtx: svcCtx,
28 | }
29 | }
30 |
31 | func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.SimpleMsgResp, err error) {
32 | store, _ := captcha.GetCaptchaStore(l.svcCtx.Config, l.svcCtx.Redis)
33 |
34 | if ok := store.Verify(req.CaptchaId, req.Captcha, true); !ok {
35 | return nil, errorx.NewApiBadRequestError(message.WrongCaptcha)
36 | }
37 |
38 | save, err := l.svcCtx.EntClient.SysUser.
39 | Create().
40 | SetUUID(uuid.NewString()).
41 | SetUsername(req.Username).
42 | SetNickname(req.Username).
43 | SetPassword(utils.BcryptEncrypt(req.Password)).
44 | SetEmail(req.Email).
45 | Save(l.ctx)
46 |
47 | if err != nil {
48 | l.Errorf("register logic: create user err: %s", err.Error())
49 | return nil, errorx.NewApiInternalServerError(message.DatabaseError)
50 | }
51 |
52 | l.Infow("register logic: create user success", logx.Field("user", save))
53 |
54 | return &types.SimpleMsgResp{
55 | Msg: errorx.Success,
56 | }, nil
57 | }
58 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/user/updateUserLogic.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/cmd/api/internal/svc"
7 | "slash-admin/app/admin/cmd/api/internal/types"
8 | "slash-admin/pkg/message"
9 | pType "slash-admin/pkg/types"
10 |
11 | "github.com/zeromicro/go-zero/core/logx"
12 | )
13 |
14 | type UpdateUserLogic struct {
15 | logx.Logger
16 | ctx context.Context
17 | svcCtx *svc.ServiceContext
18 | }
19 |
20 | func NewUpdateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserLogic {
21 | return &UpdateUserLogic{
22 | Logger: logx.WithContext(ctx),
23 | ctx: ctx,
24 | svcCtx: svcCtx,
25 | }
26 | }
27 |
28 | func (l *UpdateUserLogic) UpdateUser(req *types.UpdateUserReq) (resp *types.SimpleMsgResp, err error) {
29 |
30 | err = l.svcCtx.EntClient.SysUser.UpdateOneID(req.ID).
31 | SetNillableUsername(req.Username).
32 | SetNillableNickname(req.Nickname).
33 | SetNillablePassword(req.Password).
34 | SetNillableEmail(req.Email).
35 | SetNillableRoleID(req.RoleID).
36 | SetNillableAvatar(req.Avatar).
37 | SetNillableMobile(req.Mobile).
38 | SetNillableStatus((*pType.Status)(req.Status)).
39 | Exec(l.ctx)
40 |
41 | if err != nil {
42 | l.Errorw("update user error", logx.Field("err", err))
43 | return nil, errorx.NewApiBadRequestError(message.DatabaseError)
44 | }
45 |
46 | logx.Infow("update user successfully", logx.Field("detail", req))
47 |
48 | return &types.SimpleMsgResp{Msg: errorx.Success}, nil
49 | }
50 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/logic/user/updateUserProfileLogic.go:
--------------------------------------------------------------------------------
1 | package user
2 |
3 | import (
4 | "context"
5 | "github.com/zeromicro/go-zero/core/errorx"
6 | "slash-admin/app/admin/cmd/api/internal/globalkey"
7 | "slash-admin/app/admin/ent/sysuser"
8 | "slash-admin/pkg/message"
9 |
10 | "slash-admin/app/admin/cmd/api/internal/svc"
11 | "slash-admin/app/admin/cmd/api/internal/types"
12 |
13 | "github.com/zeromicro/go-zero/core/logx"
14 | )
15 |
16 | type UpdateUserProfileLogic struct {
17 | logx.Logger
18 | ctx context.Context
19 | svcCtx *svc.ServiceContext
20 | }
21 |
22 | func NewUpdateUserProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserProfileLogic {
23 | return &UpdateUserProfileLogic{
24 | Logger: logx.WithContext(ctx),
25 | ctx: ctx,
26 | svcCtx: svcCtx,
27 | }
28 | }
29 |
30 | func (l *UpdateUserProfileLogic) UpdateUserProfile(req *types.UpdateProfileReq) (resp *types.SimpleMsgResp, err error) {
31 | uuid := l.ctx.Value(globalkey.JWTUserId).(string)
32 |
33 | updateOne := l.svcCtx.EntClient.SysUser.Update().
34 | Where(sysuser.UUID(uuid)).
35 | SetNillableAvatar(req.Avatar).
36 | SetNillableMobile(req.Mobile).
37 | SetNillableEmail(req.Email)
38 |
39 | if req.Nickname != nil {
40 | updateOne.SetNickname(*req.Nickname)
41 | }
42 |
43 | affect, err := updateOne.Save(l.ctx)
44 |
45 | if err != nil {
46 | l.Errorf("UpdateUserProfile error: %v", err)
47 | return nil, errorx.NewApiBadRequestError(message.DatabaseError)
48 | }
49 |
50 | if affect == 0 {
51 | return nil, errorx.NewApiBadRequestError(errorx.UpdateFailed)
52 | }
53 |
54 | return &types.SimpleMsgResp{
55 | Msg: errorx.UpdateSuccess,
56 | }, nil
57 | }
58 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/middleware/authorityMiddleware.go:
--------------------------------------------------------------------------------
1 | package middleware
2 |
3 | import (
4 | "github.com/casbin/casbin/v2"
5 | "github.com/zeromicro/go-zero/core/stores/redis"
6 | "net/http"
7 | )
8 |
9 | type AuthorityMiddleware struct {
10 | CasbinSyncedEnforcer *casbin.SyncedEnforcer
11 | RedisClient *redis.Redis
12 | }
13 |
14 | func NewAuthorityMiddleware(enforcer *casbin.SyncedEnforcer, redisClient *redis.Redis) *AuthorityMiddleware {
15 | return &AuthorityMiddleware{
16 | CasbinSyncedEnforcer: enforcer,
17 | RedisClient: redisClient,
18 | }
19 | }
20 |
21 | func (m *AuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
22 | return func(w http.ResponseWriter, r *http.Request) {
23 | // TODO generate middleware implement function, delete after code implementation
24 |
25 | // Passthrough to next handler if you need
26 | next(w, r)
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/admin/cmd/api/internal/svc/serviceContext.go:
--------------------------------------------------------------------------------
1 | package svc
2 |
3 | import (
4 | "context"
5 | "entgo.io/ent/dialect/sql/schema"
6 | "github.com/casbin/casbin/v2"
7 | "github.com/zeromicro/go-zero/core/logx"
8 | "github.com/zeromicro/go-zero/core/stores/redis"
9 | "github.com/zeromicro/go-zero/rest"
10 | "slash-admin/app/admin/cmd/api/internal/config"
11 | "slash-admin/app/admin/cmd/api/internal/converter"
12 | "slash-admin/app/admin/cmd/api/internal/converter/generated"
13 | "slash-admin/app/admin/cmd/api/internal/middleware"
14 | "slash-admin/app/admin/ent"
15 | )
16 |
17 | type ServiceContext struct {
18 | Redis *redis.Redis
19 | EntClient *ent.Client
20 | Config config.Config
21 | Authority rest.Middleware
22 | Converter converter.Converter
23 | Casbin *casbin.SyncedEnforcer
24 | }
25 |
26 | func NewServiceContext(c config.Config) *ServiceContext {
27 | var (
28 | redisClient *redis.Redis
29 | entClient *ent.Client
30 | casbinEnforcer *casbin.SyncedEnforcer
31 | err error
32 | )
33 | if redisClient, err = c.Redis.NewRedis(); err != nil {
34 | logx.Errorf("初始化redis失败: ", err)
35 | panic(err)
36 | }
37 | if entClient, err = c.Database.NewDatabase(c.Redis); err != nil {
38 | logx.Errorf("初始化ent失败: ", err)
39 | panic(err)
40 | }
41 |
42 | if c.Database.AutoMigrate {
43 | if err = entClient.Schema.Create(context.Background(), schema.WithForeignKeys(false)); err != nil {
44 | logx.Errorf("初始化ent schema失败: ", err)
45 | panic(err)
46 | }
47 | }
48 |
49 | if casbinEnforcer, err = c.Casbin.NewCasbin(entClient); err != nil {
50 | logx.Errorf("初始化casbin失败: ", err)
51 | panic(err)
52 | }
53 |
54 | return &ServiceContext{
55 | Redis: redisClient,
56 | EntClient: entClient,
57 | Config: c,
58 | Authority: middleware.NewAuthorityMiddleware(casbinEnforcer, redisClient).Handle,
59 | Converter: &generated.ConverterImpl{},
60 | Casbin: casbinEnforcer,
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/admin/ent/context.go:
--------------------------------------------------------------------------------
1 | // Code generated by ent, DO NOT EDIT.
2 |
3 | package ent
4 |
5 | import (
6 | "context"
7 | )
8 |
9 | type clientCtxKey struct{}
10 |
11 | // FromContext returns a Client stored inside a context, or nil if there isn't one.
12 | func FromContext(ctx context.Context) *Client {
13 | c, _ := ctx.Value(clientCtxKey{}).(*Client)
14 | return c
15 | }
16 |
17 | // NewContext returns a new context with the given Client attached.
18 | func NewContext(parent context.Context, c *Client) context.Context {
19 | return context.WithValue(parent, clientCtxKey{}, c)
20 | }
21 |
22 | type txCtxKey struct{}
23 |
24 | // TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
25 | func TxFromContext(ctx context.Context) *Tx {
26 | tx, _ := ctx.Value(txCtxKey{}).(*Tx)
27 | return tx
28 | }
29 |
30 | // NewTxContext returns a new context with the given Tx attached.
31 | func NewTxContext(parent context.Context, tx *Tx) context.Context {
32 | return context.WithValue(parent, txCtxKey{}, tx)
33 | }
34 |
--------------------------------------------------------------------------------
/app/admin/ent/entc.go:
--------------------------------------------------------------------------------
1 | //go:build ignore
2 | // +build ignore
3 |
4 | package main
5 |
6 | import (
7 | "entgo.io/contrib/entgql"
8 | "entgo.io/ent/entc"
9 | "entgo.io/ent/entc/gen"
10 | "fmt"
11 | )
12 |
13 | func main() {
14 | _, err := entgql.NewExtension()
15 |
16 | if err != nil {
17 | panic("creating entgql extension")
18 | }
19 |
20 | opts := []entc.Option{
21 | entc.TemplateDir("./template"),
22 | }
23 |
24 | if err := entc.Generate("./schema", &gen.Config{
25 | Features: []gen.Feature{
26 | gen.FeatureModifier,
27 | gen.FeatureUpsert,
28 | gen.FeatureExecQuery,
29 | },
30 | }, opts...); err != nil {
31 | fmt.Println("running entgo codegen:", err)
32 | return
33 | }
34 | fmt.Println("Code generation completed successfully")
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/app/admin/ent/enttest/client.go:
--------------------------------------------------------------------------------
1 | package enttest
2 |
3 | import (
4 | "ariga.io/entcache"
5 | "context"
6 | "database/sql"
7 | entsql "entgo.io/ent/dialect/sql"
8 | "github.com/go-redis/redis/v8"
9 | "slash-admin/app/admin/ent"
10 | "slash-admin/app/admin/ent/migrate"
11 | "time"
12 | )
13 |
14 | func NewTestClient(t TestingT) *ent.Client {
15 | opts := []Option{
16 | WithOptions(ent.Debug()),
17 | WithMigrateOptions(migrate.WithForeignKeys(false)),
18 | }
19 |
20 | client := Open(t,
21 | "mysql",
22 | "root:123456@tcp(127.0.0.1:3306)/slash_admin_enhance?charset=utf8mb4&parseTime=True",
23 | opts...,
24 | )
25 |
26 | return client
27 | }
28 |
29 | func NewTestClientWithCache() *ent.Client {
30 | rdb := redis.NewClient(&redis.Options{
31 | Addr: "127.0.0.1:16379",
32 | })
33 |
34 | if err := rdb.Ping(context.Background()).Err(); err != nil {
35 | panic(err)
36 | }
37 |
38 | db, err := sql.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/slash_admin_enhance?charset=utf8mb4&parseTime=True&loc=Local")
39 |
40 | if err != nil {
41 | panic(err)
42 | }
43 |
44 | drv := entsql.OpenDB("mysql", db)
45 |
46 | cacheDrv := entcache.NewDriver(
47 | drv,
48 | entcache.TTL(time.Minute),
49 | entcache.Levels(
50 | entcache.NewRedis(rdb),
51 | ),
52 | )
53 |
54 | client := ent.NewClient(ent.Driver(cacheDrv), ent.Debug())
55 |
56 | err = client.Schema.Create(context.Background(), migrate.WithForeignKeys(false))
57 |
58 | if err != nil {
59 | panic(err)
60 | }
61 |
62 | return client
63 | }
64 |
--------------------------------------------------------------------------------
/app/admin/ent/enttest/user_query_test.go:
--------------------------------------------------------------------------------
1 | package enttest
2 |
3 | import (
4 | "context"
5 | _ "github.com/go-sql-driver/mysql"
6 | "github.com/stretchr/testify/assert"
7 | "testing"
8 | )
9 |
10 | func TestGetUserById(t *testing.T) {
11 | client := NewTestClient(t)
12 |
13 | user, err := client.SysUser.Get(context.Background(), 1)
14 |
15 | assert.Equal(t, nil, err)
16 | assert.Equal(t, "admin", user.Username)
17 | }
18 |
--------------------------------------------------------------------------------
/app/admin/ent/gql_transaction.go:
--------------------------------------------------------------------------------
1 | // Code generated by ent, DO NOT EDIT.
2 |
3 | package ent
4 |
5 | import (
6 | "context"
7 | "database/sql/driver"
8 | "errors"
9 | )
10 |
11 | // OpenTx opens a transaction and returns a transactional
12 | // context along with the created transaction.
13 | func (c *Client) OpenTx(ctx context.Context) (context.Context, driver.Tx, error) {
14 | tx, err := c.Tx(ctx)
15 | if err != nil {
16 | return nil, nil, err
17 | }
18 | ctx = NewTxContext(ctx, tx)
19 | ctx = NewContext(ctx, tx.Client())
20 | return ctx, tx, nil
21 | }
22 |
23 | // OpenTxFromContext open transactions from client stored in context.
24 | func OpenTxFromContext(ctx context.Context) (context.Context, driver.Tx, error) {
25 | client := FromContext(ctx)
26 | if client == nil {
27 | return nil, nil, errors.New("no client attached to context")
28 | }
29 | return client.OpenTx(ctx)
30 | }
31 |
--------------------------------------------------------------------------------
/app/admin/ent/predicate/predicate.go:
--------------------------------------------------------------------------------
1 | // Code generated by ent, DO NOT EDIT.
2 |
3 | package predicate
4 |
5 | import (
6 | "entgo.io/ent/dialect/sql"
7 | )
8 |
9 | // CasbinRule is the predicate function for casbinrule builders.
10 | type CasbinRule func(*sql.Selector)
11 |
12 | // SysApi is the predicate function for sysapi builders.
13 | type SysApi func(*sql.Selector)
14 |
15 | // SysDictionary is the predicate function for sysdictionary builders.
16 | type SysDictionary func(*sql.Selector)
17 |
18 | // SysDictionaryDetail is the predicate function for sysdictionarydetail builders.
19 | type SysDictionaryDetail func(*sql.Selector)
20 |
21 | // SysMenu is the predicate function for sysmenu builders.
22 | type SysMenu func(*sql.Selector)
23 |
24 | // SysMenuParam is the predicate function for sysmenuparam builders.
25 | type SysMenuParam func(*sql.Selector)
26 |
27 | // SysOauthProvider is the predicate function for sysoauthprovider builders.
28 | type SysOauthProvider func(*sql.Selector)
29 |
30 | // SysRole is the predicate function for sysrole builders.
31 | type SysRole func(*sql.Selector)
32 |
33 | // SysToken is the predicate function for systoken builders.
34 | type SysToken func(*sql.Selector)
35 |
36 | // SysUser is the predicate function for sysuser builders.
37 | type SysUser func(*sql.Selector)
38 |
--------------------------------------------------------------------------------
/app/admin/ent/runtime/runtime.go:
--------------------------------------------------------------------------------
1 | // Code generated by ent, DO NOT EDIT.
2 |
3 | package runtime
4 |
5 | // The schema-stitching logic is generated in slash-admin/app/admin/ent/runtime.go
6 |
7 | const (
8 | Version = "v0.11.4-0.20221001062602-1029a2d3ba2a" // Version of ent codegen.
9 | Sum = "h1:T28WZZUdeJb7DQVQNnZkr3pasIdDrDVC41eQIV0hvTU=" // Sum of ent codegen.
10 | )
11 |
--------------------------------------------------------------------------------
/app/admin/ent/schema/casbin_rule.go:
--------------------------------------------------------------------------------
1 | package schema
2 |
3 | import (
4 | "entgo.io/ent"
5 | "entgo.io/ent/dialect/entsql"
6 | "entgo.io/ent/schema"
7 | "entgo.io/ent/schema/field"
8 | "entgo.io/ent/schema/index"
9 | )
10 |
11 | // CasbinRule holds the schema definition for the CasbinRule entity.
12 | type CasbinRule struct {
13 | ent.Schema
14 | }
15 |
16 | // Fields of the CasbinRule.
17 | func (CasbinRule) Fields() []ent.Field {
18 | return []ent.Field{
19 | field.String("Ptype").Default(""),
20 | field.String("V0").Default(""),
21 | field.String("V1").Default(""),
22 | field.String("V2").Default(""),
23 | field.String("V3").Default(""),
24 | field.String("V4").Default(""),
25 | field.String("V5").Default(""),
26 | }
27 | }
28 |
29 | // Edges of the CasbinRule.
30 | func (CasbinRule) Edges() []ent.Edge {
31 | return nil
32 | }
33 |
34 | func (CasbinRule) Index() []ent.Index {
35 | return []ent.Index{
36 | index.Fields("Ptype", "V0", "V1", "V2", "V3", "V4", "V5").Unique(),
37 | }
38 | }
39 |
40 | func (CasbinRule) Annotations() []schema.Annotation {
41 | return []schema.Annotation{
42 | entsql.Annotation{Table: "casbin_rule"},
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/admin/ent/schema/sys_api.go:
--------------------------------------------------------------------------------
1 | package schema
2 |
3 | import (
4 | "entgo.io/ent"
5 | "entgo.io/ent/dialect/entsql"
6 | "entgo.io/ent/schema"
7 | "entgo.io/ent/schema/field"
8 | "time"
9 | )
10 |
11 | type SysApi struct {
12 | ent.Schema
13 | }
14 |
15 | func (SysApi) Fields() []ent.Field {
16 | return []ent.Field{
17 | field.Uint64("id"),
18 | field.String("path").Comment("API path"),
19 | field.String("description").Comment("API description"),
20 | field.String("api_group").Comment("API group"),
21 | field.String("method").Default("POST").Comment("HTTP method"),
22 | field.Time("created_at").Default(time.Now),
23 | field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
24 | field.Time("deleted_at").Optional().Nillable(),
25 | }
26 | }
27 |
28 | func (SysApi) Edges() []ent.Edge {
29 | return nil
30 | }
31 |
32 | func (SysApi) Annotations() []schema.Annotation {
33 | return []schema.Annotation{
34 | entsql.Annotation{Table: "sys_api"},
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/admin/ent/schema/sys_dictonary.go:
--------------------------------------------------------------------------------
1 | package schema
2 |
3 | import (
4 | "entgo.io/ent"
5 | "entgo.io/ent/dialect"
6 | "entgo.io/ent/dialect/entsql"
7 | "entgo.io/ent/schema"
8 | "entgo.io/ent/schema/edge"
9 | "entgo.io/ent/schema/field"
10 | "entgo.io/ent/schema/index"
11 | "slash-admin/pkg/types"
12 | "time"
13 | )
14 |
15 | type SysDictionary struct {
16 | ent.Schema
17 | }
18 |
19 | func (SysDictionary) Fields() []ent.Field {
20 | return []ent.Field{
21 | field.Uint64("id"),
22 | field.String("title").Comment("the title shown in the UI"),
23 | field.String("name").Comment("the name of dictionary for search"),
24 |
25 | field.Uint8("status").
26 | SchemaType(map[string]string{dialect.MySQL: "tinyint unsigned"}).
27 | GoType(types.Status(0)).
28 | Default(0).
29 | Optional().
30 | Comment("0=开启 1=禁用"),
31 |
32 | field.String("desc").Comment("the descriptions of dictionary"),
33 | field.Time("created_at").Default(time.Now),
34 | field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
35 | field.Time("deleted_at").Optional().Nillable(),
36 | }
37 | }
38 |
39 | func (SysDictionary) Edges() []ent.Edge {
40 | return []ent.Edge{
41 | edge.To("details", SysDictionaryDetail.Type),
42 | }
43 | }
44 |
45 | func (SysDictionary) Indexes() []ent.Index {
46 | return []ent.Index{
47 | index.Fields("deleted_at"),
48 | }
49 | }
50 |
51 | func (SysDictionary) Annotations() []schema.Annotation {
52 | return []schema.Annotation{
53 | entsql.Annotation{Table: "sys_dictionary"},
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/admin/ent/schema/sys_dictonary_detail.go:
--------------------------------------------------------------------------------
1 | package schema
2 |
3 | import (
4 | "entgo.io/ent"
5 | "entgo.io/ent/dialect"
6 | "entgo.io/ent/dialect/entsql"
7 | "entgo.io/ent/schema"
8 | "entgo.io/ent/schema/edge"
9 | "entgo.io/ent/schema/field"
10 | "entgo.io/ent/schema/index"
11 | "slash-admin/pkg/types"
12 | "time"
13 | )
14 |
15 | type SysDictionaryDetail struct {
16 | ent.Schema
17 | }
18 |
19 | func (SysDictionaryDetail) Fields() []ent.Field {
20 | return []ent.Field{
21 | field.Uint64("id"),
22 | field.String("title").Comment("the title shown in the UI"),
23 | field.String("key").Comment("key"),
24 | field.String("value").Comment("value"),
25 |
26 | field.Uint8("status").
27 | SchemaType(map[string]string{dialect.MySQL: "tinyint unsigned"}).
28 | GoType(types.Status(0)).
29 | Default(0).
30 | Optional().
31 | Comment("0=开启 1=禁用"),
32 |
33 | field.Uint64("dictionary_id").Optional().Comment("dictionary id"),
34 | field.String("remark").Comment("备注"),
35 | field.Uint32("order_no").Default(0).Comment("排序编号"),
36 | field.Time("created_at").Default(time.Now),
37 | field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
38 | field.Time("deleted_at").Optional().Nillable(),
39 | }
40 | }
41 |
42 | func (SysDictionaryDetail) Edges() []ent.Edge {
43 | return []ent.Edge{
44 | edge.From("parent", SysDictionary.Type).Ref("details").Unique().Field("dictionary_id"),
45 | }
46 | }
47 |
48 | func (SysDictionaryDetail) Indexes() []ent.Index {
49 | return []ent.Index{
50 | index.Fields("deleted_at"),
51 | }
52 | }
53 |
54 | func (SysDictionaryDetail) Annotations() []schema.Annotation {
55 | return []schema.Annotation{
56 | entsql.Annotation{Table: "sys_dictionary_detail"},
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/admin/ent/schema/sys_menu.go:
--------------------------------------------------------------------------------
1 | package schema
2 |
3 | import (
4 | "entgo.io/ent"
5 | "entgo.io/ent/dialect"
6 | "entgo.io/ent/dialect/entsql"
7 | "entgo.io/ent/schema"
8 | "entgo.io/ent/schema/edge"
9 | "entgo.io/ent/schema/field"
10 | "entgo.io/ent/schema/index"
11 | "slash-admin/pkg/types"
12 | "time"
13 | )
14 |
15 | type SysMenu struct {
16 | ent.Schema
17 | }
18 |
19 | func (SysMenu) Fields() []ent.Field {
20 | return []ent.Field{
21 | field.Uint64("id"),
22 | field.Uint64("parent_id").Optional().Comment("parent menu ID"),
23 | field.Uint8("menu_level").Comment("menu level"),
24 | field.Uint8("menu_type").Comment("menu type: 0. group 1. menu"),
25 | field.String("path").Comment("index path"),
26 | field.String("name").Comment("index name"),
27 | field.String("redirect").Optional().Default("").Comment("redirect path"),
28 | field.String("component").Comment("the path of vue file"),
29 | field.Uint8("order_no").Default(0).Comment("numbers for sorting"),
30 | field.Bool("disabled").Default(false).Comment("if true, disable"),
31 | field.String("meta").
32 | Optional().
33 | GoType(types.MenuMeta{}).
34 | SchemaType(map[string]string{
35 | dialect.MySQL: "JSON",
36 | }).
37 | Comment("extra parameters"),
38 | field.Time("created_at").Default(time.Now),
39 | field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
40 | field.Time("deleted_at").Optional().Nillable(),
41 | }
42 | }
43 |
44 | func (SysMenu) Edges() []ent.Edge {
45 | return []ent.Edge{
46 | edge.To("roles", SysRole.Type),
47 | //https://entgo.io/docs/schema-edges/#o2m-same-type
48 | edge.To("children", SysMenu.Type).From("parent").Unique().Field("parent_id"),
49 | }
50 | }
51 |
52 | func (SysMenu) Indexes() []ent.Index {
53 | return []ent.Index{
54 | index.Fields("deleted_at"),
55 | }
56 | }
57 |
58 | func (SysMenu) Annotations() []schema.Annotation {
59 | return []schema.Annotation{
60 | entsql.Annotation{Table: "sys_menu"},
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/admin/ent/schema/sys_menu_param.go:
--------------------------------------------------------------------------------
1 | package schema
2 |
3 | import (
4 | "entgo.io/ent"
5 | "entgo.io/ent/dialect/entsql"
6 | "entgo.io/ent/schema"
7 | "entgo.io/ent/schema/field"
8 | "entgo.io/ent/schema/index"
9 | "time"
10 | )
11 |
12 | type SysMenuParam struct {
13 | ent.Schema
14 | }
15 |
16 | func (SysMenuParam) Fields() []ent.Field {
17 | return []ent.Field{
18 | field.Uint64("id"),
19 | field.Uint64("menu_id").Comment("menu id"),
20 | field.String("type").Comment("参数类型"),
21 | field.String("key").Comment("参数键"),
22 | field.String("value").Comment("参数值"),
23 | field.Time("created_at").Default(time.Now),
24 | field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
25 | field.Time("deleted_at").Optional().Nillable(),
26 | }
27 | }
28 |
29 | func (SysMenuParam) Edges() []ent.Edge {
30 | return nil
31 | }
32 |
33 | func (SysMenuParam) Indexes() []ent.Index {
34 | return []ent.Index{
35 | index.Fields("deleted_at"),
36 | }
37 | }
38 |
39 | func (SysMenuParam) Annotations() []schema.Annotation {
40 | return []schema.Annotation{
41 | entsql.Annotation{Table: "sys_menu_param"},
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/admin/ent/schema/sys_oauth_provider.go:
--------------------------------------------------------------------------------
1 | package schema
2 |
3 | import (
4 | "entgo.io/ent"
5 | "entgo.io/ent/dialect/entsql"
6 | "entgo.io/ent/schema"
7 | "entgo.io/ent/schema/field"
8 | "entgo.io/ent/schema/index"
9 | "time"
10 | )
11 |
12 | type SysOauthProvider struct {
13 | ent.Schema
14 | }
15 |
16 | func (SysOauthProvider) Fields() []ent.Field {
17 | return []ent.Field{
18 | field.Uint64("id"),
19 | field.String("name").Comment("the provider's name"),
20 | field.String("client_id").Comment("the client id"),
21 | field.String("client_secret").Comment("the client secret"),
22 | field.String("redirect_url").Comment("the redirect url"),
23 | field.String("scopes").Comment("the scopes"),
24 | field.String("auth_url").Comment("the auth url of the provider"),
25 | field.String("token_url").Comment("the token url of the provider"),
26 | field.Uint8("auth_style").Comment("the auth style, 0: auto detect 1: third party log in 2: log in with username and password"),
27 | field.String("info_url").Comment("the URL to request user information by token"),
28 | field.Time("created_at").Default(time.Now),
29 | field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
30 | field.Time("deleted_at").Optional().Nillable(),
31 | }
32 | }
33 |
34 | func (SysOauthProvider) Edges() []ent.Edge {
35 | return nil
36 | }
37 |
38 | func (SysOauthProvider) Indexes() []ent.Index {
39 | return []ent.Index{
40 | index.Fields("deleted_at"),
41 | }
42 | }
43 |
44 | func (SysOauthProvider) Annotations() []schema.Annotation {
45 | return []schema.Annotation{
46 | entsql.Annotation{Table: "sys_oauth_provider"},
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/admin/ent/schema/sys_role.go:
--------------------------------------------------------------------------------
1 | package schema
2 |
3 | import (
4 | "entgo.io/ent"
5 | "entgo.io/ent/dialect"
6 | "entgo.io/ent/dialect/entsql"
7 | "entgo.io/ent/schema"
8 | "entgo.io/ent/schema/edge"
9 | "entgo.io/ent/schema/field"
10 | "entgo.io/ent/schema/index"
11 | "slash-admin/pkg/types"
12 | "time"
13 | )
14 |
15 | type SysRole struct {
16 | ent.Schema
17 | }
18 |
19 | func (SysRole) Fields() []ent.Field {
20 | return []ent.Field{
21 | field.Uint64("id"),
22 | field.String("name").Comment("角色名"),
23 | field.String("value").Unique().Comment("角色值,用于前端权限控制"),
24 | field.String("default_router").Default("dashboard").Comment("默认登录页面"),
25 |
26 | field.Uint8("status").
27 | SchemaType(map[string]string{dialect.MySQL: "tinyint unsigned"}).
28 | GoType(types.Status(0)).
29 | Optional().
30 | Default(0).
31 | Comment("0=开启 1=禁用"),
32 |
33 | field.String("remark").Default("").Comment("备注"),
34 | field.Uint32("order_no").Default(0).Comment("排序编号"),
35 | field.Time("created_at").Default(time.Now),
36 | field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
37 | field.Time("deleted_at").Optional().Nillable(),
38 | }
39 | }
40 |
41 | func (SysRole) Edges() []ent.Edge {
42 | return []ent.Edge{
43 | edge.From("menus", SysMenu.Type).Ref("roles"),
44 | edge.To("role", SysUser.Type).Comment("用户"),
45 | }
46 | }
47 |
48 | func (SysRole) Indexes() []ent.Index {
49 | return []ent.Index{
50 | index.Fields("deleted_at"),
51 | }
52 | }
53 |
54 | func (SysRole) Annotations() []schema.Annotation {
55 | return []schema.Annotation{
56 | entsql.Annotation{Table: "sys_role"},
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/admin/ent/schema/sys_token.go:
--------------------------------------------------------------------------------
1 | package schema
2 |
3 | import (
4 | "entgo.io/ent"
5 | "entgo.io/ent/dialect"
6 | "entgo.io/ent/dialect/entsql"
7 | "entgo.io/ent/schema"
8 | "entgo.io/ent/schema/field"
9 | "entgo.io/ent/schema/index"
10 | "slash-admin/pkg/types"
11 | "time"
12 | )
13 |
14 | type SysToken struct {
15 | ent.Schema
16 | }
17 |
18 | func (SysToken) Fields() []ent.Field {
19 | return []ent.Field{
20 | field.Uint64("id"),
21 | field.String("uuid").Comment(" 用户的UUID"),
22 | field.String("token").Comment(" Token 字符串"),
23 | field.String("source").Comment(" Token 来源 (本地为core, 第三方如github等)"),
24 |
25 | field.Uint8("status").
26 | SchemaType(map[string]string{dialect.MySQL: "tinyint unsigned"}).
27 | GoType(types.Status(0)).
28 | Default(0).
29 | Optional().
30 | Comment("0=正常 1=禁用"),
31 |
32 | field.Time("expired_at").Comment(" 过期时间"),
33 | field.Time("created_at").Default(time.Now),
34 | field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
35 | field.Time("deleted_at").Optional().Nillable(),
36 | }
37 | }
38 |
39 | func (SysToken) Edges() []ent.Edge {
40 | return nil
41 | }
42 |
43 | func (SysToken) Indexes() []ent.Index {
44 | return []ent.Index{
45 | index.Fields("uuid"),
46 | index.Fields("deleted_at"),
47 | index.Fields("expired_at"),
48 | }
49 | }
50 |
51 | func (SysToken) Annotations() []schema.Annotation {
52 | return []schema.Annotation{
53 | entsql.Annotation{Table: "sys_token"},
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/admin/ent/template/extension_mutation_create.tmpl:
--------------------------------------------------------------------------------
1 | {{ define "extension_mutation_create" }}
2 | {{- /*gotype: entgo.io/ent/entc/gen.Graph*/ -}}
3 |
4 | {{ template "header" $ }}
5 | {{ $pkg := base $.Config.Package }}
6 | {{ template "import" $ }}
7 |
8 | {{ range $n := $.Nodes }}
9 | {{- if ne $n.Name "CasbinRule" }}
10 | {{ $createBuilder := $n.CreateName }}
11 | {{ $createReceiver := receiver $createBuilder }}
12 | {{ $fields := $n.Fields }}
13 |
14 | func ({{ $createReceiver }} *{{ $createBuilder }}) Copy(input *Create{{ $n.Name }}Input) *{{ $createBuilder }} {
15 | if input.{{ $n.ID.StructField }} != nil {
16 | {{ $createReceiver }}.Set{{ $n.ID.StructField }}(*input.{{ $n.ID.StructField }})
17 | }
18 | {{- range $f := $fields }}
19 | {{ $field := $f.StructField }}
20 | {{ $set := print "Set" $field }}
21 | if input.{{ $field }} != nil {
22 | {{ $createReceiver }}.{{ $set }}(*input.{{ $field }})
23 | }
24 | {{- end }}
25 | return {{ $createReceiver }}
26 | }
27 | {{ end }}
28 | {{ end }}
29 | {{ end }}
30 |
--------------------------------------------------------------------------------
/app/admin/ent/template/extension_object.tmpl:
--------------------------------------------------------------------------------
1 | {{ define "extension_object" }}
2 | {{- /*gotype: entgo.io/ent/entc/gen.Graph*/ -}}
3 |
4 | {{ template "header" $ }}
5 | {{ $pkg := base $.Config.Package }}
6 | {{ template "import" $ }}
7 |
8 | {{- range $n := $.Nodes }}
9 | {{- if ne $n.Name "CasbinRule" }}
10 | {{- $input := $n.Name }}
11 | {{ $fields := $n.Fields }}
12 | type Create{{ $input }}Input struct {
13 | {{$n.ID.StructField}} *{{ $n.ID.Type }}
14 | {{- range $f := $fields }}
15 | {{ $f.StructField }} *{{ $f.Type }}
16 | {{- end }}
17 | }
18 | {{- end }}
19 | {{ end }}
20 | {{- end }}
21 |
--------------------------------------------------------------------------------
/app/admin/ent/template/extension_object_nillable.tmpl:
--------------------------------------------------------------------------------
1 | {{ define "extension_object_nillable" }}
2 | {{- /*gotype: entgo.io/ent/entc/gen.Graph*/ -}}
3 |
4 | {{ template "header" $ }}
5 | {{ $pkg := base $.Config.Package }}
6 | {{ template "import" $ }}
7 |
8 | {{/* Loop over all updaters and implement the "SetOrClear" method for all optional fields */}}
9 | {{ range $n := $.Nodes }}
10 | {{- if ne $n.Name "CasbinRule" }}
11 | {{ $updater := $n.UpdateOneName }}
12 | {{ $receiverName := $n.Receiver}}
13 | {{ range $f := $n.Fields }}
14 | {{ if not $f.Optional }}
15 | {{ if not $f.Default}}
16 | {{ if not $f.Nillable}}
17 | {{ $set := print "Set" $f.StructField }}
18 | func ({{ $receiverName }} *{{ $updater }}) SetNillable{{ $f.StructField }}(value *{{ $f.Type }}) *{{ $updater }} {
19 | if value != nil {
20 | {{$receiverName}}.{{ $set }}(*value)
21 | }
22 | return {{$receiverName}}
23 | }
24 | {{ end }}
25 | {{ end }}
26 | {{ end }}
27 | {{ end }}
28 | {{ end }}
29 | {{ end }}
30 | {{ end }}
31 |
--------------------------------------------------------------------------------
/deployment/docker-compose/docker-compose.yaml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
3 | volumes:
4 | mysql:
5 | redis:
6 |
7 | networks:
8 | slash-admin:
9 | driver: bridge
10 |
11 | services:
12 | mysql:
13 | image: mysql:8.0.21
14 | container_name: mysql
15 | command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
16 | restart: always
17 | ports:
18 | - '3306:3306'
19 | environment:
20 | MYSQL_DATABASE: 'slash-admin'
21 | MYSQL_ROOT_PASSWORD: '123456'
22 | volumes:
23 | - mysql:/var/lib/mysql
24 | networks:
25 | slash-admin:
26 | aliases:
27 | - mysqlserver
28 | deploy:
29 | resources:
30 | limits:
31 | cpus: '0.1'
32 | memory: 300M
33 | reservations:
34 | cpus: '0.05'
35 | memory: 200M
36 |
37 | redis:
38 | image: redis:7.0.5-alpine
39 | container_name: redis
40 | restart: always
41 | ports:
42 | - '6379:6379'
43 | volumes:
44 | - redis:/data
45 | networks:
46 | slash-admin:
47 | aliases:
48 | - redisserver
49 | deploy:
50 | resources:
51 | limits:
52 | cpus: '0.1'
53 | memory: 300M
54 | reservations:
55 | cpus: '0.05'
56 | memory: 200M
57 |
--------------------------------------------------------------------------------
/docs/.nojekyll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/.nojekyll
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | # Welcome | 欢迎
2 |
3 | #### Welcome to Slash admin document | 欢迎来到 slash admin
4 |
5 |
--------------------------------------------------------------------------------
/docs/_navbar.md:
--------------------------------------------------------------------------------
1 | * Languages
2 |
3 | * [En](/slash-admin/en/)
4 | * [简体中文](/slash-admin/zh-cn/)
--------------------------------------------------------------------------------
/docs/_sidebar.md:
--------------------------------------------------------------------------------
1 | * Slash Admin
2 |
3 | * [Slash Admin 中文文档](/slash-admin/zh-cn/)
4 | * [Slash Admin English Document](/slash-admin/en/)
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Slash Admin
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/docs/slash-admin/assets/add_example_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/add_example_api.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/add_example_api_authority.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/add_example_api_authority.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/add_example_api_zh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/add_example_api_zh.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/add_example_authority.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/add_example_authority.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/add_example_authority_zh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/add_example_authority_zh.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/add_example_menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/add_example_menu.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/api_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/api_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/api_zh_cn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/api_zh_cn.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/authority_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/authority_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/authority_zh_cn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/authority_zh_cn.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/consul.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/consul.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/consul_kv.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/consul_kv.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/copy_translation_path.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/copy_translation_path.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/dashboard_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/dashboard_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/dashboard_zh_cn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/dashboard_zh_cn.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/edit_menu_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/edit_menu_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/example-struct.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/example-struct.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/example_api_desc_title_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/example_api_desc_title_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/example_api_desc_title_zh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/example_api_desc_title_zh.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/example_en_title.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/example_en_title.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/example_page.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/example_page.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/example_rpc_struct.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/example_rpc_struct.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/example_validator_message_mode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/example_validator_message_mode.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/example_validator_modal_mode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/example_validator_modal_mode.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/example_zh_title.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/example_zh_title.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/file_list_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/file_list_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/file_list_zh_cn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/file_list_zh_cn.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/file_preview_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/file_preview_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/file_preview_zh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/file_preview_zh.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/get_token.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/get_token.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/i18n_ext.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/i18n_ext.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/init_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/init_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/init_zh_cn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/init_zh_cn.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/kibana.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/kibana.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/login_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/login_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/login_zh_cn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/login_zh_cn.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/menu_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/menu_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/menu_zh_cn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/menu_zh_cn.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/oauth_add_provider.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/oauth_add_provider.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/oauth_add_provider_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/oauth_add_provider_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/prometheus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/prometheus.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/register_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/register_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/register_zh_cn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/register_zh_cn.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/role_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/role_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/role_zh_cn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/role_zh_cn.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/swagger.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/swagger.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/swagger_authority.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/swagger_authority.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/user_en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/user_en.png
--------------------------------------------------------------------------------
/docs/slash-admin/assets/user_zh_cn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/slash-space/slash-admin/c8c58f70eccb710b9301c32275d5be292c3f35b6/docs/slash-admin/assets/user_zh_cn.png
--------------------------------------------------------------------------------
/docs/slash-admin/en/_navbar.md:
--------------------------------------------------------------------------------
1 | * Languages
2 |
3 | * [En](/slash-admin/en/)
4 | * [简体中文](/slash-admin/zh-cn/)
--------------------------------------------------------------------------------
/docs/slash-admin/en/_sidebar.md:
--------------------------------------------------------------------------------
1 | * Basic Configuration
2 | * [Local Development Setting](slash-admin/en/docs/env_setting.md)
3 | * K8s
4 | * [K8s Deployment](slash-admin/en/docs/k8s-deploy.md)
5 | * [Minikube Setting](slash-admin/en/docs/minikube.md)
6 | * [Simple Admin Tool](slash-admin/en/docs/simple-admin-tools.md)
7 | * [File Manager](/slash-admin/en/docs/file_manager.md)
8 | * [Web Setting](/slash-admin/en/docs/web-setting.md)
9 | * [Global Variable](/slash-admin/en/docs/global_vars.md)
10 | * Quick Start
11 | * Develop Core Project
12 | * [Develop Backend](slash-admin/en/docs/quick_develop_example.md)
13 | * [Develop Frontend](slash-admin/en/docs/web_develop_example.md)
14 | * [API Service](slash-admin/en/docs/api_example.md)
15 | * [RPC Service](slash-admin/en/docs/rpc_example.md)
16 | * [Docker](slash-admin/en/docs/deploy_docker.md)
17 | * Tools
18 | * [Validator](/slash-admin/en/docs/validator.md)
19 | * [Consul](/slash-admin/en/docs/consul.md)
20 | * [Swagger](slash-admin/en/docs/swagger.md)
21 | * [GORM](slash-admin/en/docs/gorm.md)
22 | * [Authorization](slash-admin/en/docs/authorization.md)
23 | * [Error Handling](slash-admin/en/docs/error_handling.md)
24 | * [Oauth](slash-admin/en/docs/oauth.md)
25 | * [Service Monitor](slash-admin/en/docs/prometheus.md)
26 | * [Log Collecting](slash-admin/en/docs/log-collection.md)
27 | * [FAQ](slash-admin/en/docs/FAQ.md)
--------------------------------------------------------------------------------
/docs/slash-admin/en/docs/FAQ.md:
--------------------------------------------------------------------------------
1 | # FAQ
2 |
3 | > Q: What is the default account?
4 |
5 | A: account: admin password: simple-admin
6 |
7 | > Q: Why the account I register cannot log in?
8 |
9 | A: The use register's default role is member. He does not have authorization to log in. \
10 | You should modify the role's authority or change the user's role.
11 |
12 |
--------------------------------------------------------------------------------
/docs/slash-admin/en/docs/error_handling.md:
--------------------------------------------------------------------------------
1 | # Error Handling
2 |
3 | > RPC Error
4 |
5 | ```go
6 | status.Error(codes.Internal, result.Error.Error())
7 | ```
8 |
9 | Just return status.Error
10 |
11 | > Notice: codes.InvalidArgument will convert into http.http.StatusBadRequest in api service
12 | > It will create prompt, you can control it by api ErrorMessageMode.
13 |
14 | > API Error
15 |
16 | ```go
17 | errorx.NewApiError(http.StatusUnauthorized, "Please log in")
18 | ```
19 |
20 |
--------------------------------------------------------------------------------
/docs/slash-admin/en/docs/file_manager.md:
--------------------------------------------------------------------------------
1 | ## File manager service
2 |
3 | > Get code
4 | ```shell
5 | git clone https://github.com/suyuan32/simple-admin-file.git
6 | ```
7 |
8 | > Modify configuration file
9 |
10 | ```yaml
11 | Name: file_manager_0
12 | Host: 0.0.0.0
13 | Port: 9102
14 | MaxBytes: 1073741824 # max content length : 1 gb
15 | Timeout: 30000 # bigger max bytes need longer timeout
16 |
17 | Auth:
18 | AccessSecret: jS6VKDtsJf3z1n2VKDtsJf3z1n2
19 | AccessExpire: 259200 # Seconds
20 |
21 | Log:
22 | ServiceName: fileManagerLogger
23 | Mode: file
24 | Path: /home/ryan/logs/file/api
25 | Level: info
26 | Compress: false
27 | KeepDays: 7
28 | StackCoolDownMillis: 100
29 |
30 | RedisConf:
31 | Host: 127.0.0.1:6379
32 | Type: node
33 |
34 | DatabaseConf:
35 | Type: mysql
36 | Path: 127.0.0.1
37 | Port: 3306
38 | Config: charset=utf8mb4&parseTime=True&loc=Local
39 | DBName: simple_admin_file
40 | Username:
41 | Password:
42 | MaxIdleConn: 10
43 | MaxOpenConn: 100
44 | LogMode: error
45 | LogZap: false
46 |
47 | UploadConf:
48 | MaxImageSize: 33554432 # 32 mb the maximum size of image
49 | MaxVideoSize: 1073741824 # 1gb the maximum size of video
50 | MaxAudioSize: 33554432 # 32mb the maximum size of audio
51 | MaxOtherSize: 10485760 # 10 mb the maximum size of other type
52 | PrivateStorePath: /home/ryan/www/private # private path
53 | PublicStorePath: /home/ryan/www/public # public path for every one access e.g. nginx path
54 | ```
55 |
56 | > You should use nginx to set PublicStorePath as static path for front end.
57 | > Make sure AccessSecret is the same as slash-admin' api set
58 | > The configuration is similar as core
59 | > Run code the same as core
60 |
61 | ### K8s Deployment
62 | > It is similar with core api.
63 |
64 | You should do these step:
65 | - deploy the images via fileapi.yaml
66 | - modify simple-admin-backend-ui/deploy/default.conf, uncomment the file manager rule
67 | - update ingress configmap
68 | - update ingress controller
--------------------------------------------------------------------------------
/docs/slash-admin/en/docs/oauth.md:
--------------------------------------------------------------------------------
1 | # Oauth
2 |
3 | > The system offer google and github Oauth log in by default
4 |
5 | > How to get clientID and client secret?
6 | [google](https://developers.google.com/identity/protocols/oauth2)
7 | [github](https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps)
8 |
9 | > Add provider
10 |
11 | 
12 |
13 | > Edit src/views/sys/login/LoginForm.vue
14 |
15 | ```html
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | ```
24 |
25 | > Add icon and click event with the provider name
26 | > param mode is put the token in the URL
27 | > header mode is put the token in the 'authorization' header
--------------------------------------------------------------------------------
/docs/slash-admin/en/docs/prometheus.md:
--------------------------------------------------------------------------------
1 | # Service Monitor
2 |
3 | ## We use Prometheus to do the service monitoring.
4 |
5 | > Install Prometheus
6 |
7 | [Install Steps](https://prometheus-operator.dev/docs/prologue/quick-start/)
8 |
9 | > After installation, cd slash-admin/deploy/k8s/prometheus
10 |
11 | ```shell
12 | # Run
13 | sh setup.sh
14 | ```
15 |
16 | > Browse http://localhost:9090 \
17 | > View status - targets
18 |
19 | 
--------------------------------------------------------------------------------
/docs/slash-admin/en/docs/screenshot.md:
--------------------------------------------------------------------------------
1 | > Initialization
2 |
3 | 
4 | > Login and Register
5 |
6 | 
7 | 
8 | > Dashboard
9 |
10 | 
11 | > User Management
12 |
13 | 
14 | > Menu Management
15 |
16 | 
17 | > Role Management
18 |
19 | 
20 | > Authorization Management
21 |
22 | 
23 | > File Management
24 |
25 | 
26 | 
--------------------------------------------------------------------------------
/docs/slash-admin/en/docs/swagger.md:
--------------------------------------------------------------------------------
1 | ## Use swagger
2 |
3 | > Environment setting
4 |
5 | [go-swagger](https://goswagger.io/install.html)
6 |
7 | > In the root of project run slash-admin/
8 |
9 | ```shell
10 | swagger generate spec --output=./core.yml --scan-models
11 |
12 | swagger serve --no-open -F=swagger --port 36666 core.yaml
13 | ```
14 |
15 | 
16 |
17 | > Get Token
18 | > Firstly, log in the system and press F12 to get authorization from any request
19 |
20 | 
21 |
22 | > Copy to swagger
23 |
24 | 
--------------------------------------------------------------------------------
/docs/slash-admin/en/docs/web-setting.md:
--------------------------------------------------------------------------------
1 | ## Web UI setting
2 |
3 | > Mainly modify env file
4 |
5 | > .env
6 |
7 | ```text
8 | # port
9 | VITE_PORT = 3100
10 |
11 | # spa-title
12 | VITE_GLOB_APP_TITLE = Simple Admin
13 |
14 | # spa shortname
15 | VITE_GLOB_APP_SHORT_NAME = Simple_Admin
16 |
17 | ```
18 |
19 | You can set develop port and the name or system.
20 |
21 | > .env.development
22 |
23 | ```text
24 | # Whether to open mock
25 | VITE_USE_MOCK = false
26 |
27 | # public path
28 | VITE_PUBLIC_PATH = /
29 |
30 | # Cross-domain proxy, you can configure multiple
31 | # Please note that no line breaks
32 | VITE_PROXY = [["/sys-api","http://localhost:9100"],["/file-manager","http://localhost:9102"]]
33 |
34 | VITE_BUILD_COMPRESS = 'none'
35 |
36 | # Delete console
37 | VITE_DROP_CONSOLE = false
38 |
39 | # Basic interface address SPA
40 | VITE_GLOB_API_URL=
41 |
42 | # File upload address, optional
43 | VITE_GLOB_UPLOAD_URL=/upload
44 |
45 | # File store address
46 | VITE_FILE_STORE_URL=http://localhost:8080
47 |
48 | # Interface prefix
49 | VITE_GLOB_API_URL_PREFIX=
50 |
51 | ```
52 |
53 | Mainly modify the VITE_PROXY to CROS request to different host.
54 |
55 | > You must write your code in one line.
56 | > VITE_PROXY = [["/sys-api","http://localhost:9100"],["/file-manager","http://localhost:9102"]]
--------------------------------------------------------------------------------
/docs/slash-admin/zh-cn/_navbar.md:
--------------------------------------------------------------------------------
1 | * Languages
2 |
3 | * [En](/slash-admin/en/)
4 | * [简体中文](/slash-admin/zh-cn/)
--------------------------------------------------------------------------------
/docs/slash-admin/zh-cn/_sidebar.md:
--------------------------------------------------------------------------------
1 | * [效果展示](slash-admin/zh-cn/docs/screenshot.md)
2 | * 基础配置
3 | * [本地开发环境配置](slash-admin/zh-cn/docs/env_setting.md)
4 | * K8s
5 | * [K8s 部署](slash-admin/zh-cn/docs/k8s-deploy.md)
6 | * [Minikube配置](slash-admin/zh-cn/docs/minikube.md)
7 | * [Simple-admin-tool](slash-admin/zh-cn/docs/simple-admin-tools.md)
8 | * [文件上传管理](/slash-admin/zh-cn/docs/file_manager.md)
9 | * [前端设置](/slash-admin/zh-cn/docs/web-setting.md)
10 | * [全局变量](/slash-admin/zh-cn/docs/global_vars.md)
11 | * 快速开始
12 | * 集成到原项目
13 | * [后端](slash-admin/zh-cn/docs/quick_develop_example.md)
14 | * [前端](slash-admin/zh-cn/docs/web_develop_example.md)
15 | * [API微服务](slash-admin/zh-cn/docs/api_example.md)
16 | * [RPC 微服务](slash-admin/zh-cn/docs/rpc_example.md)
17 | * 工具
18 | * [验证器](/slash-admin/zh-cn/docs/validator.md)
19 | * [Swagger](slash-admin/zh-cn/docs/swagger.md)
20 | * [GORM](slash-admin/zh-cn/docs/gorm.md)
21 | * [权限验证](slash-admin/zh-cn/docs/authorization.md)
22 | * [错误处理](slash-admin/zh-cn/docs/error_handling.md)
23 | * [第三方登录](slash-admin/zh-cn/docs/oauth.md)
24 | * [服务监控](slash-admin/zh-cn/docs/prometheus.md)
25 | * [日志收集](slash-admin/zh-cn/docs/log-collection.md)
26 | * [常见问题](slash-admin/zh-cn/docs/FAQ.md)
--------------------------------------------------------------------------------
/docs/slash-admin/zh-cn/docs/FAQ.md:
--------------------------------------------------------------------------------
1 | # FAQ
2 |
3 | > Q: 默认账号是什么?
4 |
5 | A: 账号: admin 密码: simple-admin
6 |
7 | > Q: 注册的账号不能登录?
8 |
9 | A: 默认注册成功后的角色是会员,没有登录的权限。 \
10 | 你需要修改角色权限或者将用户的角色设置为管理员.
11 |
12 | > Q: go-zero 有几种服务注册发现方式?
13 |
14 | A: 3 种 [go-zero](https://mp.weixin.qq.com/s/-WaWJaM_ePEQOf7ExNJe7w)
15 |
16 |
17 |
--------------------------------------------------------------------------------
/docs/slash-admin/zh-cn/docs/error_handling.md:
--------------------------------------------------------------------------------
1 | # 错误处理
2 |
3 | > RPC 错误
4 |
5 | ```go
6 | status.Error(codes.Internal, result.Error.Error())
7 | ```
8 |
9 | 直接 return status.Error
10 |
11 | > 注意: codes.InvalidArgument 会转化为前端 http.http.StatusBadRequest , 会产生弹窗, 通过 api ErrorMessageMode 控制
12 |
13 | > API 错误
14 |
15 | ```go
16 | errorx.NewApiError(http.StatusUnauthorized, "Please log in")
17 | ```
18 |
--------------------------------------------------------------------------------
/docs/slash-admin/zh-cn/docs/file_manager.md:
--------------------------------------------------------------------------------
1 | ## 文件上传服务
2 |
3 | > 下载代码
4 | ```shell
5 | git clone https://github.com/suyuan32/simple-admin-file.git
6 | ```
7 |
8 | > 修改配置文件 etc/file.yaml
9 |
10 | #### value
11 | ```yaml
12 | Name: file_manager_0
13 | Host: 0.0.0.0
14 | Port: 9102
15 | MaxBytes: 1073741824 # max content length : 1 gb
16 | Timeout: 30000 # bigger max bytes need longer timeout
17 |
18 | Auth:
19 | AccessSecret: jS6VKDtsJf3z1n2VKDtsJf3z1n2
20 | AccessExpire: 259200 # Seconds
21 |
22 | Log:
23 | ServiceName: fileManagerLogger
24 | Mode: file
25 | Path: /home/ryan/logs/file/api
26 | Level: info
27 | Compress: false
28 | KeepDays: 7
29 | StackCoolDownMillis: 100
30 |
31 | RedisConf:
32 | Host: 127.0.0.1:6379
33 | Type: node
34 |
35 | DatabaseConf:
36 | Type: mysql
37 | Path: 127.0.0.1
38 | Port: 3306
39 | Config: charset=utf8mb4&parseTime=True&loc=Local
40 | DBName: simple_admin_file
41 | Username:
42 | Password:
43 | MaxIdleConn: 10
44 | MaxOpenConn: 100
45 | LogMode: error
46 | LogZap: false
47 |
48 | UploadConf:
49 | MaxImageSize: 33554432 # 32 mb 最大图片大小
50 | MaxVideoSize: 1073741824 # 1gb 最大视频大小
51 | MaxAudioSize: 33554432 # 32mb 最大音频大小
52 | MaxOtherSize: 10485760 # 10 mb 最大其他类型大小
53 | PrivateStorePath: /home/ryan/www/private # private 私有文件路径
54 | PublicStorePath: /home/ryan/www/public # public path for every one access e.g. nginx path 公开文件路径
55 | ```
56 | > 你可以使用nginx 将 PublicStorePath 转发为静态地址方便前端调用
57 |
58 | > 确保 AccessSecret 和 slash-admin的api配置文件内一致 \
59 | 配置方式参考core \
60 | 运行方式同理
61 |
62 | ### K8s 部署
63 | > 和 core api 相似
64 |
65 | 你应该做如下工作:
66 | - 通过 fileapi.yaml 部署服务
67 | - 修改 simple-admin-backend-ui/deploy/default.conf ,解开 file-manager注释
68 | - 更新 ingress configmap
69 | - 更新 ingress controller
--------------------------------------------------------------------------------
/docs/slash-admin/zh-cn/docs/log-collection.md:
--------------------------------------------------------------------------------
1 | # 日志收集
2 |
3 | > 本项目主要使用 EFK 进行日志收集
4 |
5 | - Elasticsearch
6 | - Filebeat
7 | - Kibana
8 |
9 | > 安装方法
10 |
11 | - [Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html)
12 | - [Filebeat](https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-installation-configuration.html)
13 | - [Kibana](https://www.elastic.co/guide/en/kibana/current/docker.html)
14 |
15 | > 测试环境快速安装方法 \
16 | > Docker
17 |
18 | ```shell
19 | # es
20 | docker run --name es01 --net elastic -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS="-Xms1g -Xmx1g" -m 3g -it docker.elastic.co/elasticsearch/elasticsearch:8.4.3
21 |
22 | # kibana
23 | docker run --name kib-01 --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.4.3
24 | ```
25 |
26 | > Filebeat
27 |
28 | 修改 filebeat-deploy.yaml, 位置 slash-admin/deploy/k8s/log-collection/filebeat/
29 | > 可以添加 log 来源位置,默认有 core
30 |
31 | ```yaml
32 | - type: log
33 | paths:
34 | - /home/data/logs/core/*/*.log
35 | ```
36 |
37 | > 配置环境变量
38 |
39 | ```yaml
40 | env:
41 | - name: ELASTICSEARCH_HOST
42 | value: "192.168.50.216" # ES的地址
43 | - name: ELASTICSEARCH_PORT
44 | value: "9200" # ES的端口
45 | - name: ELASTICSEARCH_USERNAME
46 | value: elastic # ES 的用户名
47 | - name: ELASTICSEARCH_PASSWORD
48 | value: UQ==CXXjw47bK_I13*f1 # 密码
49 | - name: ELASTICSEARCH_CA_FINGERPRINT
50 | value: 8d6aed6bba745f2f0aaa46f628e3124c82ae6727c1f5e207e3d821ffeefb5e5e # 信任的CA指纹
51 | - name: ELASTIC_CLOUD_ID
52 | value: # 云 ID, 可选
53 | - name: ELASTIC_CLOUD_AUTH
54 | value: # 云 Token, 可选
55 | ```
56 |
57 | > 然后使用脚本部署 filebeat
58 |
59 | ```shell
60 | # 进入 slash-admin/deploy/k8s/log-collection/filebeat
61 | kubectl apply -f filebeat-deploy.yaml
62 | ```
63 |
64 | > 效果展示
65 |
66 | 
--------------------------------------------------------------------------------
/docs/slash-admin/zh-cn/docs/oauth.md:
--------------------------------------------------------------------------------
1 | # Oauth
2 |
3 | > 目前系统已默认提供 google 和 github Oauth 登录功能
4 |
5 | > 如何获取 clientID 和 client secret?
6 | [google](https://developers.google.com/identity/protocols/oauth2)
7 | [github](https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps)
8 |
9 | > 添加第三方
10 |
11 | 
12 |
13 | > 编辑 src/views/sys/login/LoginForm.vue
14 |
15 | ```html
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | ```
24 |
25 | > 添加对应的provider名称即可。
26 | > param 模式是将请求放在网址中
27 | > header 模式是将请求放在 authorization 内
--------------------------------------------------------------------------------
/docs/slash-admin/zh-cn/docs/prometheus.md:
--------------------------------------------------------------------------------
1 | # 服务监控
2 |
3 | ## 我们使用 Prometheus 进行服务监控
4 |
5 | > 安装 Prometheus
6 |
7 | [安装方法](https://prometheus-operator.dev/docs/prologue/quick-start/)
8 |
9 | > 安装好后进入 slash-admin/deploy/k8s/prometheus
10 |
11 | ```shell
12 | # 运行
13 | sh setup.sh
14 | ```
15 |
16 | > 访问 http://localhost:9090 \
17 | > 查看 status - targets
18 |
19 | 
--------------------------------------------------------------------------------
/docs/slash-admin/zh-cn/docs/screenshot.md:
--------------------------------------------------------------------------------
1 | > 初始化
2 |
3 | 
4 | > 注册登录
5 |
6 | 
7 | 
8 | > 主页
9 |
10 | 
11 | > 用户管理
12 |
13 | 
14 | > 菜单管理
15 |
16 | 
17 | > 角色管理
18 |
19 | 
20 | > 权限管理
21 |
22 | 
23 | > 上传文件管理
24 |
25 | 
26 | 
--------------------------------------------------------------------------------
/docs/slash-admin/zh-cn/docs/swagger.md:
--------------------------------------------------------------------------------
1 | ## 使用swagger
2 |
3 | > 环境配置
4 |
5 | [go-swagger](https://goswagger.io/install.html)
6 |
7 | > 在项目根目录运行 slash-admin/
8 |
9 | ```shell
10 | swagger generate spec --output=./core.yml --scan-models
11 |
12 | swagger serve --no-open -F=swagger --port 36666 core.yaml
13 | ```
14 |
15 | 
16 |
17 | > 获取 Token
18 | >
19 | > 先登录系统,在任意请求中复制 authorization
20 |
21 | 
22 |
23 | > 粘贴到 swagger
24 |
25 | 
26 |
27 |
28 |
--------------------------------------------------------------------------------
/docs/slash-admin/zh-cn/docs/web-setting.md:
--------------------------------------------------------------------------------
1 | ## 前端设置
2 |
3 | ### 主要修改 env 文件
4 |
5 |
6 | > .env
7 |
8 | ```text
9 | # port
10 | VITE_PORT = 3100
11 |
12 | # spa-title
13 | VITE_GLOB_APP_TITLE = Simple Admin
14 |
15 | # spa shortname
16 | VITE_GLOB_APP_SHORT_NAME = Simple_Admin
17 |
18 | ```
19 |
20 | 可以修改调试端口和系统名称
21 |
22 |
23 | > .env.development
24 |
25 | ```text
26 | # Whether to open mock
27 | VITE_USE_MOCK = false
28 |
29 | # public path
30 | VITE_PUBLIC_PATH = /
31 |
32 | # Cross-domain proxy, you can configure multiple
33 | # Please note that no line breaks
34 | VITE_PROXY = [["/sys-api","http://localhost:8500"],["/file-manager","http://localhost:9102"]]
35 |
36 | VITE_BUILD_COMPRESS = 'none'
37 |
38 | # Delete console
39 | VITE_DROP_CONSOLE = false
40 |
41 | # Basic interface address SPA
42 | VITE_GLOB_API_URL=
43 |
44 | # File upload address, optional
45 | VITE_GLOB_UPLOAD_URL=/upload
46 |
47 | # File store address
48 | VITE_FILE_STORE_URL=http://localhost:8080
49 |
50 | # Interface prefix
51 | VITE_GLOB_API_URL_PREFIX=
52 |
53 | ```
54 |
55 | 主要修改 VITE_PROXY 用于实现跨域请求不同地址,
56 | > 注意必须写在同一行
57 | VITE_PROXY = [["/sys-api","http://localhost:8500"],["/file-manager","http://localhost:9102"]]
--------------------------------------------------------------------------------
/modd.conf:
--------------------------------------------------------------------------------
1 | app/admin/**/*.go {
2 | prep: go build -o ./data/server/admin-api -v app/admin/cmd/api/core.go
3 | daemon +sigkill: ./data/server/admin-api -f app/admin/cmd/api/etc/core.yaml
4 | }
--------------------------------------------------------------------------------
/pkg/captcha/store.go:
--------------------------------------------------------------------------------
1 | package captcha
2 |
3 | import (
4 | "context"
5 | "github.com/mojocn/base64Captcha"
6 | "github.com/zeromicro/go-zero/core/logx"
7 | "github.com/zeromicro/go-zero/core/stores/redis"
8 | "time"
9 | )
10 |
11 | func NewCaptchaStoreWithRedis(r *redis.Redis) *RedisStore {
12 | return &RedisStore{
13 | Expiration: time.Minute * 5,
14 | PreKey: "CAPTCHA_",
15 | Redis: r,
16 | }
17 | }
18 |
19 | type RedisStore struct {
20 | Expiration time.Duration
21 | PreKey string
22 | Context context.Context
23 | Redis *redis.Redis
24 | }
25 |
26 | func (r *RedisStore) UseWithCtx(ctx context.Context) base64Captcha.Store {
27 | r.Context = ctx
28 | return r
29 | }
30 |
31 | func (r *RedisStore) Set(id string, value string) error {
32 | err := r.Redis.Setex(r.PreKey+id, value, int(r.Expiration.Seconds()))
33 | if err != nil {
34 | logx.Error("captcha: RedisStoreSet Error!", err)
35 | return err
36 | }
37 | return nil
38 | }
39 |
40 | func (r *RedisStore) Get(key string, clear bool) string {
41 | val, err := r.Redis.Get(key)
42 | if err != nil {
43 | logx.Error("captcha: RedisStoreGet Error!", err)
44 | return ""
45 | }
46 | if clear {
47 | _, err := r.Redis.Del(key)
48 | if err != nil {
49 | logx.Error("captcha: RedisStoreClear Error!", err)
50 | return ""
51 | }
52 | }
53 | return val
54 | }
55 |
56 | func (r *RedisStore) Verify(id, answer string, clear bool) bool {
57 | key := r.PreKey + id
58 | v := r.Get(key, clear)
59 | return v == answer
60 | }
61 |
--------------------------------------------------------------------------------
/pkg/slconfig/captcha.go:
--------------------------------------------------------------------------------
1 | package slconfig
2 |
3 | type CaptchaConf struct {
4 | KeyLong int `json:"KeyLong"`
5 | ImgWidth int `json:"ImgWidth"`
6 | ImgHeight int `json:"ImgHeight"`
7 | }
8 |
--------------------------------------------------------------------------------
/pkg/slconfig/casbin.go:
--------------------------------------------------------------------------------
1 | package slconfig
2 |
3 | import (
4 | "github.com/casbin/casbin/v2"
5 | "github.com/casbin/casbin/v2/model"
6 | "log"
7 | "slash-admin/app/admin/ent"
8 | entcasbin "slash-admin/app/admin/ent/casbin"
9 | )
10 |
11 | // CasbinConf casbin config
12 |
13 | type CasbinConf struct {
14 | ModelText string `json:"ModelText"`
15 | }
16 |
17 | func (config CasbinConf) NewCasbin(client *ent.Client) (*casbin.SyncedEnforcer, error) {
18 | var syncedEnforcer *casbin.SyncedEnforcer
19 | a, err := entcasbin.NewAdapterWithClient(client)
20 |
21 | if err != nil {
22 | log.Fatal("InitCasbin: init adapter fail!", err)
23 | return nil, err
24 | }
25 |
26 | m, err := model.NewModelFromString(config.ModelText)
27 | if err != nil {
28 | log.Fatal("InitCasbin: import model fail!", err)
29 | return nil, err
30 | }
31 | syncedEnforcer, err = casbin.NewSyncedEnforcer(m, a)
32 | if err != nil {
33 | log.Fatal("InitCasbin: NewSyncedEnforcer fail!", err)
34 | return nil, err
35 | }
36 | err = syncedEnforcer.LoadPolicy()
37 | if err != nil {
38 | log.Fatal("InitCasbin: LoadPolicy fail!", err)
39 | return nil, err
40 | }
41 | return syncedEnforcer, nil
42 | }
43 |
--------------------------------------------------------------------------------
/pkg/slconfig/redis.go:
--------------------------------------------------------------------------------
1 | package slconfig
2 |
3 | import (
4 | "fmt"
5 | "github.com/zeromicro/go-zero/core/stores/redis"
6 | )
7 |
8 | type RedisConf struct {
9 | Host string `json:"Host"`
10 | Port int `json:"Port"`
11 | Pass string `json:"Pass"`
12 | Type string `json:"Type"`
13 | TLS bool `json:"TLS"`
14 | }
15 |
16 | // NewRedis returns a Redis.
17 | func (rc RedisConf) NewRedis() (*redis.Redis, error) {
18 | var opts []redis.Option
19 |
20 | if rc.Type == redis.ClusterType {
21 | opts = append(opts, redis.Cluster())
22 | }
23 | if len(rc.Pass) > 0 {
24 | opts = append(opts, redis.WithPass(rc.Pass))
25 | }
26 | if rc.TLS {
27 | opts = append(opts, redis.WithTLS())
28 | }
29 |
30 | addr := fmt.Sprintf("%s:%d", rc.Host, rc.Port)
31 |
32 | client := redis.New(addr, opts...)
33 |
34 | if client.Ping() {
35 | return client, nil
36 | }
37 |
38 | return nil, fmt.Errorf("NewRedis: redis connect failed")
39 | }
40 |
--------------------------------------------------------------------------------
/pkg/types/menu.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import (
4 | "database/sql/driver"
5 | "encoding/json"
6 | "fmt"
7 | )
8 |
9 | type MenuMeta struct {
10 | Title string `json:"title"` // menu name | 菜单显示标题
11 | Icon string `json:"icon"` // menu icon | 菜单图标
12 | HideMenu bool `json:"hideMenu"` // hide menu | 是否隐藏菜单
13 | HideBreadcrumb bool `json:"hideBreadcrumb"` // hide the breadcrumb | 隐藏面包屑
14 | CurrentActiveMenu string `json:"currentActiveMenu"` // set the active menu | 激活菜单
15 | IgnoreKeepAlive bool `json:"ignoreKeepAlive"` // do not keep alive the tab | 取消页面缓存
16 | HideTab bool `json:"hideTab"` // hide the tab header | 隐藏页头
17 | FrameSrc string `json:"frameSrc"` // show iframe | 内嵌 iframe
18 | CarryParam bool `json:"carryParam"` // the route carries parameters or not | 携带参数
19 | HideChildrenInMenu bool `json:"hideChildrenInMenu"` // hide children menu or not | 隐藏所有子菜单
20 | Affix bool `json:"affix"` // affix tab | Tab 固定
21 | DynamicLevel uint32 `json:"dynamicLevel"` // the maximum number of pages the router can open | 能打开的子TAB数
22 | RealPath string `json:"realPath"` // the real path of the route without dynamic part | 菜单路由不包含参数部分
23 | }
24 |
25 | func (m MenuMeta) Value() (driver.Value, error) {
26 | val, err := json.Marshal(m)
27 | if err != nil {
28 | fmt.Println("MenuMeta.Value() error:", err)
29 | return nil, err
30 | }
31 | return string(val), nil
32 | }
33 |
34 | func (m *MenuMeta) Scan(v any) error {
35 | s2 := asString(v)
36 | err := json.Unmarshal([]byte(s2), m)
37 | if err != nil {
38 | fmt.Println("MenuMeta.Scan() error:", err)
39 | return err
40 | }
41 | return nil
42 | }
43 |
--------------------------------------------------------------------------------
/pkg/types/oauth.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import (
4 | "database/sql/driver"
5 | "fmt"
6 | "strconv"
7 | )
8 |
9 | type OAuthStyle uint8
10 |
11 | func (s OAuthStyle) Value() (driver.Value, error) {
12 | return int64(s), nil
13 | }
14 |
15 | func (s *OAuthStyle) Scan(v any) error {
16 | s2 := asString(v)
17 | parseUint, err := strconv.ParseUint(s2, 10, 8)
18 | if err != nil {
19 | return fmt.Errorf("invalid database type: %T %v", v, v)
20 | }
21 | *s = OAuthStyle(parseUint)
22 | return nil
23 | }
24 |
25 | const (
26 | OAuthStyleAuto OAuthStyle = iota
27 | OAuthStyleThirdParty
28 | OAuthStyleUsernamePassword
29 | )
30 |
--------------------------------------------------------------------------------
/pkg/types/status.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import (
4 | "database/sql/driver"
5 | "fmt"
6 | "strconv"
7 | )
8 |
9 | type Status uint8
10 |
11 | func (s Status) Value() (driver.Value, error) {
12 | return int64(s), nil
13 | }
14 |
15 | func (s *Status) Scan(v any) error {
16 | if v == nil {
17 | return nil
18 | }
19 | s2 := asString(v)
20 | parseUint, err := strconv.ParseUint(s2, 10, 8)
21 | if err != nil {
22 | return fmt.Errorf("scan: invalid database type: %T %v", v, v)
23 | }
24 | *s = Status(parseUint)
25 | return nil
26 | }
27 |
28 | const (
29 | StatusNormal Status = iota
30 | StatusBanned
31 | )
32 |
--------------------------------------------------------------------------------
/pkg/types/utils.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import (
4 | "fmt"
5 | "reflect"
6 | "strconv"
7 | )
8 |
9 | func asString(src any) string {
10 | switch v := src.(type) {
11 | case string:
12 | return v
13 | case []byte:
14 | return string(v)
15 | }
16 | rv := reflect.ValueOf(src)
17 | switch rv.Kind() {
18 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
19 | return strconv.FormatInt(rv.Int(), 10)
20 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
21 | return strconv.FormatUint(rv.Uint(), 10)
22 | case reflect.Float64:
23 | return strconv.FormatFloat(rv.Float(), 'g', -1, 64)
24 | case reflect.Float32:
25 | return strconv.FormatFloat(rv.Float(), 'g', -1, 32)
26 | case reflect.Bool:
27 | return strconv.FormatBool(rv.Bool())
28 | }
29 | return fmt.Sprintf("%v", src)
30 | }
31 |
--------------------------------------------------------------------------------
/pkg/utils/encrypt.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "golang.org/x/crypto/bcrypt"
5 | )
6 |
7 | func BcryptEncrypt(password string) string {
8 | bytes, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
9 | return string(bytes)
10 | }
11 |
12 | func BcryptCheck(password, hash string) bool {
13 | err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
14 | return err == nil
15 | }
16 |
--------------------------------------------------------------------------------
/pkg/utils/encrypt_test.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "github.com/stretchr/testify/assert"
5 | "testing"
6 | )
7 |
8 | func TestEncrypt(t *testing.T) {
9 | tests := []struct {
10 | origin string
11 | }{
12 | {
13 | origin: "123456",
14 | },
15 | {
16 | origin: "123456789..",
17 | },
18 | }
19 |
20 | for _, v := range tests {
21 | // test encrypt
22 | encryptedData := BcryptEncrypt(v.origin)
23 | result := BcryptCheck(v.origin, encryptedData)
24 | assert.Equal(t, result, true)
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/pkg/utils/tx.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "slash-admin/app/admin/ent"
7 | )
8 |
9 | func WithTx(ctx context.Context, client *ent.Client, fn func(tx *ent.Tx) error) error {
10 | tx, err := client.Tx(ctx)
11 | if err != nil {
12 | return err
13 | }
14 | defer func() {
15 | if v := recover(); v != nil {
16 | tx.Rollback()
17 | panic(v)
18 | }
19 | }()
20 | if err := fn(tx); err != nil {
21 | if rerr := tx.Rollback(); rerr != nil {
22 | err = fmt.Errorf("rolling back transaction: %w", rerr)
23 | }
24 | return err
25 | }
26 | if err := tx.Commit(); err != nil {
27 | return fmt.Errorf("committing transaction: %w", err)
28 | }
29 | return nil
30 | }
31 |
--------------------------------------------------------------------------------
/pkg/utils/wrap.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | func Wrap[T any](x T) (r *T) {
4 | r = &x
5 | return
6 | }
7 |
--------------------------------------------------------------------------------