启动后端

直接参考官方文档:
https://doc.go-admin.dev/guide/ksks.html

go build下载包出错,需要设置goproxy为https://goproxy.cn

初始化数据库

  1. go-admin git:(v1.2.2_phone_dev) ./go-admin migrate -c=config/settings.yml
  2. start init
  3. warning config not found settings.ssl in the configuration
  4. 2021-02-27 20:47:32 file=logger/setup.go:44 level=fatal request logger setup error: %s0x4844040

settings.ssl的错误,需要制定配置文件为settings.full.yml,因为里面制定了ssl:enable为false。

fatal request logger setup error: %s0x4844040这个错误是由于日志目录问题导致的。
参考:
https://github.com/go-admin-team/go-admin/issues/298

在项目目录下创建:

  1. 你在你的项目盘建好相应的文件夹, 比如 E:\temp\logs\bus E:\temp\logs\job E:\temp\logs\request。
  2. 修改配置文件 logger:

logger:
# 日志存放路径
#———————-修改这里 像这样 就可以了——————————————

  1. path: E:\temp\logs
  2. # 控制台日志
  3. stdout: true
  4. # 日志等级
  5. level: all
  6. # 业务日志开关
  7. enabledbus: true
  8. # 请求日志开关
  9. enabledreq: false

如果报如下错误:

  1. [error] failed to initialize database, got error Error 1049: Unknown database 'go-admin'
  2. 2021-02-27 22:28:13 file=database/mysql_drive.go:43 level=fatal mysql connect error :Error 1049: Unknown database 'go-admin'

需要先创建go-admin database。

然后执行初始化,就不会报错了,下面是goland配置:
./go-admin migrate -c=config/settings.full.yml
image.png
初始化执行成功:

  1. 数据库基础数据初始化成功
  2. Process finished with exit code 0

image.png

启动后端

./go-admin server -c=config/settings.full.yml
image.png

启动成功后:
看接口:
http://localhost:8000/swagger/index.html

欢迎界面:
http://localhost:8000/

日志打印目录:
image.png

启动前端

参考官方文档:
https://doc.go-admin.dev/guide/ksks.html#npm-install

编译

  1. go-admin-ui git:(v1.2.2_phone_dev) npm i --registry=https://registry.npm.taobao.org
  2. npm notice
  3. npm notice New minor version of npm available! 7.5.3 -> 7.6.0
  4. npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.6.0
  5. npm notice Run npm install -g npm@7.6.0 to update!
  6. npm notice
  7. npm ERR! code ERESOLVE
  8. npm ERR! ERESOLVE unable to resolve dependency tree
  9. npm ERR!
  10. npm ERR! While resolving: go-admin@1.2.2
  11. npm ERR! Found: eslint@7.6.0
  12. npm ERR! node_modules/eslint
  13. npm ERR! dev eslint@"7.6.0" from the root project
  14. npm ERR!
  15. npm ERR! Could not resolve dependency:
  16. npm ERR! peer eslint@">= 1.6.0 < 7.0.0" from @vue/cli-plugin-eslint@4.5.11
  17. npm ERR! node_modules/@vue/cli-plugin-eslint
  18. npm ERR! dev @vue/cli-plugin-eslint@"^4.4.6" from the root project
  19. npm ERR!
  20. npm ERR! Fix the upstream dependency conflict, or retry
  21. npm ERR! this command with --force, or --legacy-peer-deps
  22. npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
  23. npm ERR!
  24. npm ERR! See /Users/liliang22/.npm/eresolve-report.txt for a full report.
  25. npm ERR! A complete log of this run can be found in:
  26. npm ERR! /Users/liliang22/.npm/_logs/2021-02-27T11_54_24_458Z-debug.log

考虑可能是node版本太高,导致:

重新安装node v14.14.0:

  1. go-admin-ui git:(v1.2.2_phone_dev) node -v
  2. v15.10.0
  3. go-admin-ui git:(v1.2.2_phone_dev) npm -v
  4. 7.5.3
  5. go-admin-ui git:(v1.2.2_phone_dev) nvm ls
  6. v0.11.0
  7. v14.14.0
  8. -> v15.10.0
  9. default -> v15.10.0
  10. ^[[Aiojs -> N/A (default)
  11. node -> stable (-> v15.10.0) (default)
  12. stable -> 15.10 (-> v15.10.0) (default)
  13. unstable -> 0.11 (-> v0.11.0) (default)
  14. lts/* -> lts/fermium (-> N/A)
  15. lts/argon -> v4.9.1 (-> N/A)
  16. lts/boron -> v6.17.1 (-> N/A)
  17. lts/carbon -> v8.17.0 (-> N/A)
  18. lts/dubnium -> v10.24.0 (-> N/A)
  19. lts/erbium -> v12.21.0 (-> N/A)
  20. lts/fermium -> v14.16.0 (-> N/A)
  21. ➜ go-admin-ui git:(v1.2.2_phone_dev) nvm use v14.14.0
  22. Now using node v14.14.0 (npm v6.14.8)
  23. ➜ go-admin-ui git:(v1.2.2_phone_dev) node -v
  24. v14.14.0

使用nvm use修改的版本只对当前会话生效,下次打开窗口还是原来的版本。全局生效需要nvm alias default v0.11.0:

  1. go-admin-ui git:(v1.2.2_phone_dev) nvm alias default v13.14.0
  2. default -> v13.14.0

此时执行编译:

  1. go-admin-ui git:(v1.2.2_phone_dev) nvm alias default v13.14.0
  2. default -> v13.14.0
  3. go-admin-ui git:(v1.2.2_phone_dev) npm install
  4. npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
  5. npm WARN deprecated runjs@4.4.2: This project has been renamed to 'tasksfile'. Install using 'npm install tasksfile' instead.
  6. npm WARN deprecated axios@0.19.2: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410
  7. npm WARN deprecated eslint-loader@2.2.1: This loader has been deprecated. Please use eslint-webpack-plugin
  8. npm WARN deprecated html-webpack-plugin@3.2.0: 3.x is no longer supported
  9. npm WARN deprecated fsevents@2.1.3: "Please update to latest v2.3 or v2.2"
  10. npm WARN deprecated microcli@1.3.3: This project has been renamed to @pawelgalazka/cli . Install using @pawelgalazka/cli instead
  11. npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
  12. npm WARN deprecated nomnom@1.8.1: Package no longer supported. Contact support@npmjs.com for more info.
  13. npm WARN deprecated highlight.js@9.18.5: Support has ended for 9.x series. Upgrade to @latest
  14. npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
  15. npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
  16. npm WARN deprecated har-validator@5.1.5: this library is no longer supported
  17. npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
  18. npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
  19. npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
  20. npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
  21. npm WARN deprecated core-js@2.6.12: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual
  22. version of core-js@3.
  23. npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
  24. npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
  25. npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
  26. npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
  27. > fsevents@1.2.13 install /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/jest-haste-map/node_modules/fsevents
  28. > node install.js
  29. SOLINK_MODULE(target) Release/.node
  30. CXX(target) Release/obj.target/fse/fsevents.o
  31. SOLINK_MODULE(target) Release/fse.node
  32. > deasync@0.1.21 install /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/deasync
  33. > node ./build.js
  34. `darwin-x64-node-13` exists; testing
  35. Binary is fine; exiting
  36. > fsevents@1.2.13 install /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/watchpack-chokidar2/node_modules/fsevents
  37. > node install.js
  38. SOLINK_MODULE(target) Release/.node
  39. CXX(target) Release/obj.target/fse/fsevents.o
  40. SOLINK_MODULE(target) Release/fse.node
  41. > fsevents@1.2.13 install /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/webpack-dev-server/node_modules/fsevents
  42. > node install.js
  43. SOLINK_MODULE(target) Release/.node
  44. CXX(target) Release/obj.target/fse/fsevents.o
  45. SOLINK_MODULE(target) Release/fse.node
  46. > yorkie@2.0.0 install /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/yorkie
  47. > node bin/install.js
  48. setting up Git hooks
  49. done
  50. > husky@4.2.5 install /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/husky
  51. > node husky install
  52. husky > Setting up git hooks
  53. husky > Done
  54. > node-sass@4.14.1 install /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/node-sass
  55. > node scripts/install.js
  56. Downloading binary from https://npm.taobao.org/mirrors/node-sass//v4.14.1/darwin-x64-79_binding.node
  57. Download complete :
  58. Binary saved to /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/node-sass/vendor/darwin-x64-79/binding.node
  59. Caching binary to /Users/liliang22/.npm/node-sass/4.14.1/darwin-x64-79_binding.node
  60. > core-js@2.6.12 postinstall /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/babel-runtime/node_modules/core-js
  61. > node -e "try{require('./postinstall')}catch(e){}"
  62. Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
  63. The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
  64. > https://opencollective.com/core-js
  65. > https://www.patreon.com/zloirock
  66. Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
  67. > core-js@3.9.0 postinstall /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/core-js
  68. > node -e "try{require('./postinstall')}catch(e){}"
  69. > core-js-pure@3.9.0 postinstall /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/core-js-pure
  70. > node -e "try{require('./postinstall')}catch(e){}"
  71. > ejs@2.7.4 postinstall /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/ejs
  72. > node ./postinstall.js
  73. Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)
  74. > highlight.js@9.18.5 postinstall /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/highlight.js
  75. > node deprecated.js
  76. -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  77. Verion 9 of Highlight.js has reached EOL. It will no longer
  78. be supported or receive security updates in the future.
  79. Please upgrade to version 10 or encourage your indirect
  80. dependencies to do so.
  81. For more info:
  82. https://github.com/highlightjs/highlight.js/issues/2877
  83. https://github.com/highlightjs/highlight.js/blob/master/VERSION_10_UPGRADE.md
  84. -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  85. > husky@4.2.5 postinstall /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/husky
  86. > opencollective-postinstall || exit 0
  87. Thank you for using husky!
  88. If you rely on this package, please consider supporting our open collective:
  89. > https://opencollective.com/husky/donate
  90. > node-sass@4.14.1 postinstall /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/node-sass
  91. > node scripts/build.js
  92. Binary found at /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/node-sass/vendor/darwin-x64-79/binding.node
  93. Testing binary
  94. Binary is fine
  95. npm notice created a lockfile as package-lock.json. You should commit this file.
  96. npm WARN @vue/cli-plugin-eslint@4.5.11 requires a peer of eslint@>= 1.6.0 < 7.0.0 but none is installed. You must install peer dependencies yourself.
  97. npm WARN eslint-plugin-vue@6.2.2 requires a peer of eslint@^5.0.0 || ^6.0.0 but none is installed. You must install peer dependencies yourself.
  98. npm WARN sass-loader@9.0.3 requires a peer of sass@^1.3.0 but none is installed. You must install peer dependencies yourself.
  99. npm WARN sass-loader@9.0.3 requires a peer of fibers@>= 3.1.0 but none is installed. You must install peer dependencies yourself.
  100. npm WARN eslint-loader@2.2.1 requires a peer of eslint@>=1.6.0 <7.0.0 but none is installed. You must install peer dependencies yourself.
  101. npm WARN jsdom@15.2.1 requires a peer of canvas@^2.5.0 but none is installed. You must install peer dependencies yourself.
  102. npm WARN ws@7.4.3 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
  103. npm WARN ws@7.4.3 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
  104. npm WARN The package vue-quill-editor is included as both a dev and production dependency.
  105. added 2345 packages from 2245 contributors in 109.33s
  106. 89 packages are looking for funding
  107. run `npm fund` for details

群主(项目owner)建议的使用v13.14.0版本才编译通过。

启动

  1. go-admin-ui git:(v1.2.2_phone_dev) npm run dev
  2. > go-admin@1.2.2 dev /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui
  3. > vue-cli-service serve
  4. INFO Starting development server...
  5. 98% after emitting CopyPlugin
  6. WARNING Compiled with 2 warnings 11:04:12 AM
  7. Module Warning (from ./node_modules/eslint-loader/index.js):
  8. /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/src/components/FileManage/Left.vue
  9. 18:37 warning Variable 'data' is already declared in the upper scope vue/no-template-shadow
  10. 1 problem (0 errors, 1 warning)
  11. Module Warning (from ./node_modules/eslint-loader/index.js):
  12. /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/src/views/loginlog/index.vue
  13. 283:13 error 'updateSysLoginlog' is not defined no-undef
  14. 293:13 error 'addSysLoginlog' is not defined no-undef
  15. 2 problems (2 errors, 0 warnings)
  16. You may use special comments to disable some warnings.
  17. Use // eslint-disable-next-line to ignore the next line.
  18. Use /* eslint-disable */ to ignore all warnings in a file.
  19. App running at:
  20. - Local: http://localhost:9527/
  21. - Network: http://192.168.1.102:9527/
  22. Note that the development build is not optimized.
  23. To create a production build, run npm run build.

看到还有一个warning,2个error

最终版本

最终群主(项目owner)建议使用 v10.16.0版本才没任何错误。

  1. go-admin-ui git:(v1.2.2_phone_dev) nvm install v10.16.0
  2. Downloading and installing node v10.16.0...
  3. Downloading https://nodejs.org/dist/v10.16.0/node-v10.16.0-darwin-x64.tar.xz...
  4. ########################################################################################################################################################################### 100.0%
  5. Computing checksum with shasum -a 256
  6. Checksums matched!
  7. Now using node v10.16.0 (npm v6.9.0)
  8. go-admin-ui git:(v1.2.2_phone_dev) nvm alias default v10.16.0
  9. default -> v10.16.0
  10. go-admin-ui git:(v1.2.2_phone_dev) npm install
  11. npm WARN @vue/cli-plugin-eslint@4.5.11 requires a peer of eslint@>= 1.6.0 < 7.0.0 but none is installed. You must install peer dependencies yourself.
  12. npm WARN eslint-loader@2.2.1 requires a peer of eslint@>=1.6.0 <7.0.0 but none is installed. You must install peer dependencies yourself.
  13. npm WARN eslint-plugin-vue@6.2.2 requires a peer of eslint@^5.0.0 || ^6.0.0 but none is installed. You must install peer dependencies yourself.
  14. npm WARN jsdom@15.2.1 requires a peer of canvas@^2.5.0 but none is installed. You must install peer dependencies yourself.
  15. npm WARN ws@7.4.3 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
  16. npm WARN ws@7.4.3 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
  17. npm WARN sass-loader@9.0.3 requires a peer of sass@^1.3.0 but none is installed. You must install peer dependencies yourself.
  18. npm WARN sass-loader@9.0.3 requires a peer of fibers@>= 3.1.0 but none is installed. You must install peer dependencies yourself.
  19. npm WARN The package vue-quill-editor is included as both a dev and production dependency.
  20. up to date in 7.796s
  21. go-admin-ui git:(v1.2.2_phone_dev) npm run dev
  22. > go-admin@1.2.2 dev /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui
  23. > vue-cli-service serve
  24. INFO Starting development server...
  25. 98% after emitting CopyPlugin
  26. ⸨░░░░░░░░░░░░░░░░░░⸩ :
  27. ░░░░░░░░░░░░░░░⸩ :
  28. ░░░░░░░░░░░░⸩ :
  29. ░░░░░░░░░░░⸩ :
  30. ░░░░░░░░⸩ :
  31. ░░░░░░░⸩ :
  32. ░░░░░░░⸩ :
  33. ░░░░░░░⸩ :
  34. ░░░░░░░⸩ :
  35. ░░░░░░░⸩ :
  36. ░░░░░░░⸩ :
  37. ░░░░░░⸩ :
  38. ░░░░░⸩ :
  39. ░░░░░⸩ :
  40. ░░░░░⸩ :
  41. ░░░░░⸩ :
  42. ░░░░░⸩ :
  43. ░░░░░⸩ :
  44. ░░░░░⸩ :
  45. ░░░░░⸩ :
  46. ░░░░░⸩ :
  47. ░░░░⸩ :
  48. ░░░⸩ :
  49. ░⸩ :
  50. ░⸩ :
  51. ░⸩ :
  52. ░⸩ :
  53. ░⸩ :
  54. ░⸩ :
  55. ERROR Failed to compile with 1 error 11:19:18 AM
  56. error in ./src/components/tableAction.vue?vue&type=style&index=0&id=aaabb078&lang=scss&scoped=true&
  57. Syntax Error: Error: Missing binding /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/node-sass/vendor/darwin-x64-64/binding.node
  58. Node Sass could not find a binding for your current environment: OS X 64-bit with Node.js 10.x
  59. Found bindings for the following environments:
  60. - OS X 64-bit with Node.js 13.x
  61. This usually happens because your environment has changed since running `npm install`.
  62. Run `npm rebuild node-sass` to download the binding for your current environment.
  63. @ ./node_modules/vue-style-loader??ref--8-oneOf-1-0!./node_modules/css-loader/dist/cjs.js??ref--8-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--8-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--8-oneOf-1-3!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/tableAction.vue?vue&type=style&index=0&id=aaabb078&lang=scss&scoped=true& 4:14-466 14:3-18:5 15:22-474
  64. @ ./src/components/tableAction.vue?vue&type=style&index=0&id=aaabb078&lang=scss&scoped=true&
  65. @ ./src/components/tableAction.vue
  66. @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/views/system/schedule.vue?vue&type=script&lang=js&
  67. @ ./src/views/system/schedule.vue?vue&type=script&lang=js&
  68. @ ./src/views/system/schedule.vue
  69. @ ./src sync ^\.\/views.*$
  70. @ ./src/store/modules/permission.js
  71. @ ./src/store/modules sync \.js$
  72. @ ./src/store/index.js
  73. @ ./src/main.js
  74. @ multi (webpack)-dev-server/client?http://192.168.1.102:9527&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
  75. ^C

run的使用提示了 1 error ,根据提示,需要执行下npm rebuild node-sass:

  1. go-admin-ui git:(v1.2.2_phone_dev)
  2. go-admin-ui git:(v1.2.2_phone_dev)
  3. go-admin-ui git:(v1.2.2_phone_dev) npm rebuild node-sass
  4. > node-sass@4.14.1 install /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/node-sass
  5. > node scripts/install.js
  6. Downloading binary from https://npm.taobao.org/mirrors/node-sass//v4.14.1/darwin-x64-64_binding.node
  7. Download complete ░⸩ :
  8. Binary saved to /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/node-sass/vendor/darwin-x64-64/binding.node
  9. Caching binary to /Users/liliang22/.npm/node-sass/4.14.1/darwin-x64-64_binding.node
  10. > node-sass@4.14.1 postinstall /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/node-sass
  11. > node scripts/build.js
  12. Binary found at /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/node-sass/vendor/darwin-x64-64/binding.node
  13. Testing binary
  14. Binary is fine
  15. node-sass@4.14.1 /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui/node_modules/node-sass
  16. go-admin-ui git:(v1.2.2_phone_dev) npm run dev
  17. > go-admin@1.2.2 dev /Users/liliang22/go/src/github.com/go-admin-team/go-admin-ui
  18. > vue-cli-service serve
  19. INFO Starting development server...
  20. 98% after emitting CopyPlugin
  21. DONE Compiled successfully in 18315ms 11:20:34 AM
  22. App running at:
  23. - Local: http://localhost:9527/
  24. - Network: http://192.168.1.102:9527/
  25. Note that the development build is not optimized.
  26. To create a production build, run npm run build.

最后启动就不会报错了。

访问成功:http://localhost:9527/
image.png

第一个测试

参考:
编写 go-admin 应用,第 1 步

示例文章界面

创建github.com/go-admin-team/go-admin/app/admin/apis/phone/article.go

  1. package phone
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. "go-admin/tools/app"
  6. )
  7. // GetArticleList 获取文章列表
  8. func GetArticleList(c *gin.Context) {
  9. var res app.Response
  10. res.Data = "hello world !"
  11. c.JSON(http.StatusOK, res.ReturnOK())
  12. }

创建github.com/go-admin-team/go-admin/app/admin/router/phone.go

  1. package router
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "go-admin/app/admin/apis/phone"
  5. )
  6. // 无需认证的路由代码
  7. func registerPhoneInfoRouter(v1 *gin.RouterGroup) {
  8. v1.GET("/articleList", phone.GetArticleList)
  9. }

修改github.com/go-admin-team/go-admin/app/admin/router/router.go中的examplesNoCheckRoleRouter方法,最后加以下代码调用:

  1. // 无需认证的路由示例
  2. func examplesNoCheckRoleRouter(r *gin.Engine) {
  3. // 可根据业务需求来设置接口版本
  4. v1 := r.Group("/api/v1")
  5. // 空接口防止v1定义无使用报错
  6. v1.GET("/nilcheckrole", nil)
  7. for _, f := range routerNoCheckRole {
  8. f(v1)
  9. }
  10. // {{无需认证路由自动补充在此处请勿删除}}
  11. registerSysFileInfoRouter(v1)
  12. registerSysFileDirRouter(v1)
  13. //注册phone
  14. registerPhoneInfoRouter(v1)
  15. }

goland重新启动后,请求访问:

  1. http://localhost:8000/api/v1/articleList

返回:

  1. {"code":200,"data":"hello world !","msg":"","requestId":""}

创建表

  1. CREATE TABLE `article` (
  2. `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '编码',
  3. `title` varchar(128) DEFAULT NULL COMMENT '标题',
  4. `author` varchar(128) DEFAULT NULL COMMENT '作者',
  5. `content` varchar(255) DEFAULT NULL COMMENT '内容',
  6. `status` int(1) DEFAULT NULL COMMENT '状态',
  7. `publish_at` timestamp NULL DEFAULT NULL COMMENT '发布时间',
  8. `created_at` timestamp NULL DEFAULT NULL,
  9. `updated_at` timestamp NULL DEFAULT NULL,
  10. `deleted_at` timestamp NULL DEFAULT NULL,
  11. `create_by` int(11) unsigned DEFAULT NULL,
  12. `update_by` int(11) unsigned DEFAULT NULL,
  13. PRIMARY KEY (`id`),
  14. KEY `idx_article_deleted_at` (`deleted_at`) USING BTREE
  15. ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='文章';

代码生成

导入:
image.png
编辑:
image.png
点击生成代码,之后后端代码会多出以下文件:
image.png
前段也会多出以下相关文件:
image.png

重启前段服务后,刷新页面,点击代码生成->配置生成。

然后重启后端工程后,刷新页面,此时就出来文章菜单了:
image.png
新增文章:
image.png

image.png