增加系统信息

master
xiao.ming 2021-11-02 12:02:43 +08:00
parent 944b273bbb
commit d93041180a
21 changed files with 1892 additions and 3 deletions

View File

@ -518,7 +518,7 @@ if ok == true {
results, err := e.BatchEnforce([][]interface{}{{"alice", "data1", "read"}, {"bob", "data2", "write"}, {"jack", "data3", "read"}})
```
f
# 文件上传及下载
# 反射reflect
@ -548,6 +548,10 @@ func (t *T) Do(a int, b string) {
}
```
# GoWeb 发布
go build编译出moduleName的可执行文件加载配置文件config.yaml即可运行。
# 疑问及拓展
#### 为什么函数或方法中变量名很多都是大写字母开始的?
- 任何需要对外暴露的名字必须以大写字母开头,不需要对外暴露的则应该以小写字母开头。

View File

@ -14,4 +14,5 @@ var userService = service.ServiceGroupApp.UserService
var jwtService = service.ServiceGroupApp.JwtService
var menuService = service.ServiceGroupApp.MenuService
var baseMenuService = service.ServiceGroupApp.BaseMenuService
var systemConfigService = service.ServiceGroupApp.SystemConfigService

79
api/web/system.go Normal file
View File

@ -0,0 +1,79 @@
package web
import (
"goweb-gin-demo/global"
"goweb-gin-demo/model/common/response"
"goweb-gin-demo/model/web"
systemRes "goweb-gin-demo/model/web/response"
"goweb-gin-demo/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
type SystemApi struct {
}
// @Tags System
// @Summary 获取配置文件内容
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /system/getSystemConfig [post]
func (s *SystemApi) GetSystemConfig(c *gin.Context) {
if err, config := systemConfigService.GetSystemConfig(); err != nil {
global.GLOBAL_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(systemRes.SysConfigResponse{Config: config}, "获取成功", c)
}
}
// @Tags System
// @Summary 设置配置文件内容
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body web.System true "设置配置文件内容"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
// @Router /system/setSystemConfig [post]
func (s *SystemApi) SetSystemConfig(c *gin.Context) {
var sys web.System
_ = c.ShouldBindJSON(&sys)
if err := systemConfigService.SetSystemConfig(sys); err != nil {
global.GLOBAL_LOG.Error("设置失败!", zap.Any("err", err))
response.FailWithMessage("设置失败", c)
} else {
response.OkWithData("设置成功", c)
}
}
// @Tags System
// @Summary 重启系统
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"code":0,"data":{},"msg":"重启系统成功"}"
// @Router /system/reloadSystem [post]
func (s *SystemApi) ReloadSystem(c *gin.Context) {
err := utils.Reload()
if err != nil {
global.GLOBAL_LOG.Error("重启系统失败!", zap.Any("err", err))
response.FailWithMessage("重启系统失败", c)
} else {
response.OkWithMessage("重启系统成功", c)
}
}
// @Tags System
// @Summary 获取服务器信息
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /system/getServerInfo [post]
func (s *SystemApi) GetServerInfo(c *gin.Context) {
if server, err := systemConfigService.GetServerInfo(); err != nil {
global.GLOBAL_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(gin.H{"server": server}, "获取成功", c)
}
}

79
build.sh Executable file
View File

@ -0,0 +1,79 @@
#!/usr/bin/env bash
def_version="1.0.0"
version=''
os=''
arch=''
debug=''
echo -e "请选择操作系统:"
oss=("linux" "windows" "darwin")
select opt in "${oss[@]}"; do
case $opt in
"linux")
os=$opt
break
;;
"windows")
os=$opt
break
;;
"darwin")
os=$opt
break
;;
*) echo "invalid option $REPLY" ;;
esac
done
echo -e "请选择CPU架构:"
archs=("amd64" "arm" "arm64")
select opt in "${archs[@]}"; do
case $opt in
"amd64")
arch=$opt
break
;;
"arm")
arch=$opt
break
;;
"arm64")
arch=$opt
break
;;
*) echo "invalid option $REPLY" ;;
esac
done
read -p "请选择编译版本:" name
echo -e "是否是调试版本"
debugs=("false" "true")
select opt in "${debugs[@]}"; do
case $opt in
"true")
debug=''
break
;;
"false")
debug="-ldflags '-s -w'"
break
;;
*) echo "invalid option $REPLY" ;;
esac
done
export CGO_ENABLED=1
export GOOS=${os}
export GOARCH=${arch}
# CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags '-s -w'
build_info="CGO_ENABLED=1 GOOS=${os} GOARCH=${arch} go build ${debug}"
echo "编译指令为:${build_info}"
build_cmd="go build ${debug}"
`${build_cmd}`

View File

@ -8,7 +8,7 @@ jwt:
zap:
level: 'info'
format: 'console'
prefix: '[github.com/flipped-aurora/gin-vue-admin/server]'
prefix: '[goweb-demo]'
director: 'log'
link-name: 'latest_log'
show-line: true

View File

@ -443,6 +443,113 @@ var doc = `{
}
}
},
"/system/getServerInfo": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"System"
],
"summary": "获取服务器信息",
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/system/getSystemConfig": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"System"
],
"summary": "获取配置文件内容",
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/system/reloadSystem": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"System"
],
"summary": "重启系统",
"responses": {
"200": {
"description": "{\"code\":0,\"data\":{},\"msg\":\"重启系统成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/system/setSystemConfig": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"System"
],
"summary": "设置配置文件内容",
"parameters": [
{
"description": "设置配置文件内容",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/web.System"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"设置成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/user/changePassword": {
"post": {
"security": [
@ -727,6 +834,435 @@ var doc = `{
}
},
"definitions": {
"config.AliyunOSS": {
"type": "object",
"properties": {
"accessKeyId": {
"type": "string"
},
"accessKeySecret": {
"type": "string"
},
"basePath": {
"type": "string"
},
"bucketName": {
"type": "string"
},
"bucketUrl": {
"type": "string"
},
"endpoint": {
"type": "string"
}
}
},
"config.Autocode": {
"type": "object",
"properties": {
"root": {
"type": "string"
},
"server": {
"type": "string"
},
"serverApi": {
"type": "string"
},
"serverInitialize": {
"type": "string"
},
"serverModel": {
"type": "string"
},
"serverRequest": {
"type": "string"
},
"serverRouter": {
"type": "string"
},
"serverService": {
"type": "string"
},
"transferRestart": {
"type": "boolean"
},
"web": {
"type": "string"
},
"webApi": {
"type": "string"
},
"webForm": {
"type": "string"
},
"webTable": {
"type": "string"
}
}
},
"config.Captcha": {
"type": "object",
"properties": {
"imgHeight": {
"description": "验证码高度",
"type": "integer"
},
"imgWidth": {
"description": "验证码宽度",
"type": "integer"
},
"keyLong": {
"description": "验证码长度",
"type": "integer"
}
}
},
"config.Casbin": {
"type": "object",
"properties": {
"modelPath": {
"description": "存放casbin模型的相对路径",
"type": "string"
}
}
},
"config.Detail": {
"type": "object",
"properties": {
"compareField": {
"description": "需要比较时间的字段",
"type": "string"
},
"interval": {
"description": "时间间隔",
"type": "string"
},
"tableName": {
"description": "需要清理的表名",
"type": "string"
}
}
},
"config.Email": {
"type": "object",
"properties": {
"from": {
"description": "收件人",
"type": "string"
},
"host": {
"description": "服务器地址",
"type": "string"
},
"isSSL": {
"description": "是否SSL",
"type": "boolean"
},
"nickname": {
"description": "昵称",
"type": "string"
},
"port": {
"description": "端口",
"type": "integer"
},
"secret": {
"description": "密钥",
"type": "string"
},
"to": {
"description": "收件人:多个以英文逗号分隔",
"type": "string"
}
}
},
"config.Excel": {
"type": "object",
"properties": {
"dir": {
"type": "string"
}
}
},
"config.JWT": {
"type": "object",
"properties": {
"bufferTime": {
"description": "缓冲时间",
"type": "integer"
},
"expiresTime": {
"description": "过期时间",
"type": "integer"
},
"signingKey": {
"description": "jwt签名",
"type": "string"
}
}
},
"config.Local": {
"type": "object",
"properties": {
"path": {
"description": "本地文件路径",
"type": "string"
}
}
},
"config.Mysql": {
"type": "object",
"properties": {
"config": {
"description": "高级配置",
"type": "string"
},
"dbname": {
"description": "数据库名",
"type": "string"
},
"logMode": {
"description": "是否开启Gorm全局日志",
"type": "string"
},
"logZap": {
"description": "是否通过zap写入日志文件",
"type": "boolean"
},
"maxIdleConns": {
"description": "空闲中的最大连接数",
"type": "integer"
},
"maxOpenConns": {
"description": "打开到数据库的最大连接数",
"type": "integer"
},
"password": {
"description": "数据库密码",
"type": "string"
},
"path": {
"description": "服务器地址:端口",
"type": "string"
},
"username": {
"description": "数据库用户名",
"type": "string"
}
}
},
"config.Qiniu": {
"type": "object",
"properties": {
"accessKey": {
"description": "秘钥AK",
"type": "string"
},
"bucket": {
"description": "空间名称",
"type": "string"
},
"imgPath": {
"description": "CDN加速域名",
"type": "string"
},
"secretKey": {
"description": "秘钥SK",
"type": "string"
},
"useCdnDomains": {
"description": "上传是否使用CDN上传加速",
"type": "boolean"
},
"useHttps": {
"description": "是否使用https",
"type": "boolean"
},
"zone": {
"description": "存储区域",
"type": "string"
}
}
},
"config.Redis": {
"type": "object",
"properties": {
"addr": {
"description": "服务器地址:端口",
"type": "string"
},
"db": {
"description": "redis的哪个数据库",
"type": "integer"
},
"password": {
"description": "密码",
"type": "string"
}
}
},
"config.Server": {
"type": "object",
"properties": {
"aliyunOSS": {
"$ref": "#/definitions/config.AliyunOSS"
},
"autoCode": {
"description": "auto",
"$ref": "#/definitions/config.Autocode"
},
"captcha": {
"$ref": "#/definitions/config.Captcha"
},
"casbin": {
"$ref": "#/definitions/config.Casbin"
},
"email": {
"$ref": "#/definitions/config.Email"
},
"excel": {
"$ref": "#/definitions/config.Excel"
},
"jwt": {
"$ref": "#/definitions/config.JWT"
},
"local": {
"description": "oss",
"$ref": "#/definitions/config.Local"
},
"mysql": {
"description": "gorm",
"$ref": "#/definitions/config.Mysql"
},
"qiniu": {
"$ref": "#/definitions/config.Qiniu"
},
"redis": {
"$ref": "#/definitions/config.Redis"
},
"system": {
"$ref": "#/definitions/config.System"
},
"tencentCOS": {
"$ref": "#/definitions/config.TencentCOS"
},
"timer": {
"$ref": "#/definitions/config.Timer"
},
"zap": {
"$ref": "#/definitions/config.Zap"
}
}
},
"config.System": {
"type": "object",
"properties": {
"addr": {
"description": "端口值",
"type": "integer"
},
"dbType": {
"description": "数据库类型:mysql(默认)|sqlite|sqlserver|postgresql",
"type": "string"
},
"env": {
"description": "环境值",
"type": "string"
},
"ossType": {
"description": "Oss类型",
"type": "string"
},
"useMultipoint": {
"description": "多点登录拦截",
"type": "boolean"
}
}
},
"config.TencentCOS": {
"type": "object",
"properties": {
"baseURL": {
"type": "string"
},
"bucket": {
"type": "string"
},
"pathPrefix": {
"type": "string"
},
"region": {
"type": "string"
},
"secretID": {
"type": "string"
},
"secretKey": {
"type": "string"
}
}
},
"config.Timer": {
"type": "object",
"properties": {
"detail": {
"type": "array",
"items": {
"$ref": "#/definitions/config.Detail"
}
},
"spec": {
"description": "CRON表达式",
"type": "string"
},
"start": {
"description": "是否启用",
"type": "boolean"
}
}
},
"config.Zap": {
"type": "object",
"properties": {
"director": {
"description": "日志文件夹",
"type": "string"
},
"encodeLevel": {
"description": "编码级",
"type": "string"
},
"format": {
"description": "输出",
"type": "string"
},
"level": {
"description": "级别",
"type": "string"
},
"linkName": {
"description": "软链接名称",
"type": "string"
},
"logInConsole": {
"description": "输出控制台",
"type": "boolean"
},
"prefix": {
"description": "日志前缀",
"type": "string"
},
"showLine": {
"description": "显示行",
"type": "boolean"
},
"stacktraceKey": {
"description": "栈名",
"type": "string"
}
}
},
"request.AddMenuAuthorityInfo": {
"type": "object",
"properties": {
@ -1082,6 +1618,14 @@ var doc = `{
"type": "string"
}
}
},
"web.System": {
"type": "object",
"properties": {
"config": {
"$ref": "#/definitions/config.Server"
}
}
}
}
}`

View File

@ -424,6 +424,113 @@
}
}
},
"/system/getServerInfo": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"System"
],
"summary": "获取服务器信息",
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/system/getSystemConfig": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"System"
],
"summary": "获取配置文件内容",
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/system/reloadSystem": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"System"
],
"summary": "重启系统",
"responses": {
"200": {
"description": "{\"code\":0,\"data\":{},\"msg\":\"重启系统成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/system/setSystemConfig": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"System"
],
"summary": "设置配置文件内容",
"parameters": [
{
"description": "设置配置文件内容",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/web.System"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"设置成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/user/changePassword": {
"post": {
"security": [
@ -708,6 +815,435 @@
}
},
"definitions": {
"config.AliyunOSS": {
"type": "object",
"properties": {
"accessKeyId": {
"type": "string"
},
"accessKeySecret": {
"type": "string"
},
"basePath": {
"type": "string"
},
"bucketName": {
"type": "string"
},
"bucketUrl": {
"type": "string"
},
"endpoint": {
"type": "string"
}
}
},
"config.Autocode": {
"type": "object",
"properties": {
"root": {
"type": "string"
},
"server": {
"type": "string"
},
"serverApi": {
"type": "string"
},
"serverInitialize": {
"type": "string"
},
"serverModel": {
"type": "string"
},
"serverRequest": {
"type": "string"
},
"serverRouter": {
"type": "string"
},
"serverService": {
"type": "string"
},
"transferRestart": {
"type": "boolean"
},
"web": {
"type": "string"
},
"webApi": {
"type": "string"
},
"webForm": {
"type": "string"
},
"webTable": {
"type": "string"
}
}
},
"config.Captcha": {
"type": "object",
"properties": {
"imgHeight": {
"description": "验证码高度",
"type": "integer"
},
"imgWidth": {
"description": "验证码宽度",
"type": "integer"
},
"keyLong": {
"description": "验证码长度",
"type": "integer"
}
}
},
"config.Casbin": {
"type": "object",
"properties": {
"modelPath": {
"description": "存放casbin模型的相对路径",
"type": "string"
}
}
},
"config.Detail": {
"type": "object",
"properties": {
"compareField": {
"description": "需要比较时间的字段",
"type": "string"
},
"interval": {
"description": "时间间隔",
"type": "string"
},
"tableName": {
"description": "需要清理的表名",
"type": "string"
}
}
},
"config.Email": {
"type": "object",
"properties": {
"from": {
"description": "收件人",
"type": "string"
},
"host": {
"description": "服务器地址",
"type": "string"
},
"isSSL": {
"description": "是否SSL",
"type": "boolean"
},
"nickname": {
"description": "昵称",
"type": "string"
},
"port": {
"description": "端口",
"type": "integer"
},
"secret": {
"description": "密钥",
"type": "string"
},
"to": {
"description": "收件人:多个以英文逗号分隔",
"type": "string"
}
}
},
"config.Excel": {
"type": "object",
"properties": {
"dir": {
"type": "string"
}
}
},
"config.JWT": {
"type": "object",
"properties": {
"bufferTime": {
"description": "缓冲时间",
"type": "integer"
},
"expiresTime": {
"description": "过期时间",
"type": "integer"
},
"signingKey": {
"description": "jwt签名",
"type": "string"
}
}
},
"config.Local": {
"type": "object",
"properties": {
"path": {
"description": "本地文件路径",
"type": "string"
}
}
},
"config.Mysql": {
"type": "object",
"properties": {
"config": {
"description": "高级配置",
"type": "string"
},
"dbname": {
"description": "数据库名",
"type": "string"
},
"logMode": {
"description": "是否开启Gorm全局日志",
"type": "string"
},
"logZap": {
"description": "是否通过zap写入日志文件",
"type": "boolean"
},
"maxIdleConns": {
"description": "空闲中的最大连接数",
"type": "integer"
},
"maxOpenConns": {
"description": "打开到数据库的最大连接数",
"type": "integer"
},
"password": {
"description": "数据库密码",
"type": "string"
},
"path": {
"description": "服务器地址:端口",
"type": "string"
},
"username": {
"description": "数据库用户名",
"type": "string"
}
}
},
"config.Qiniu": {
"type": "object",
"properties": {
"accessKey": {
"description": "秘钥AK",
"type": "string"
},
"bucket": {
"description": "空间名称",
"type": "string"
},
"imgPath": {
"description": "CDN加速域名",
"type": "string"
},
"secretKey": {
"description": "秘钥SK",
"type": "string"
},
"useCdnDomains": {
"description": "上传是否使用CDN上传加速",
"type": "boolean"
},
"useHttps": {
"description": "是否使用https",
"type": "boolean"
},
"zone": {
"description": "存储区域",
"type": "string"
}
}
},
"config.Redis": {
"type": "object",
"properties": {
"addr": {
"description": "服务器地址:端口",
"type": "string"
},
"db": {
"description": "redis的哪个数据库",
"type": "integer"
},
"password": {
"description": "密码",
"type": "string"
}
}
},
"config.Server": {
"type": "object",
"properties": {
"aliyunOSS": {
"$ref": "#/definitions/config.AliyunOSS"
},
"autoCode": {
"description": "auto",
"$ref": "#/definitions/config.Autocode"
},
"captcha": {
"$ref": "#/definitions/config.Captcha"
},
"casbin": {
"$ref": "#/definitions/config.Casbin"
},
"email": {
"$ref": "#/definitions/config.Email"
},
"excel": {
"$ref": "#/definitions/config.Excel"
},
"jwt": {
"$ref": "#/definitions/config.JWT"
},
"local": {
"description": "oss",
"$ref": "#/definitions/config.Local"
},
"mysql": {
"description": "gorm",
"$ref": "#/definitions/config.Mysql"
},
"qiniu": {
"$ref": "#/definitions/config.Qiniu"
},
"redis": {
"$ref": "#/definitions/config.Redis"
},
"system": {
"$ref": "#/definitions/config.System"
},
"tencentCOS": {
"$ref": "#/definitions/config.TencentCOS"
},
"timer": {
"$ref": "#/definitions/config.Timer"
},
"zap": {
"$ref": "#/definitions/config.Zap"
}
}
},
"config.System": {
"type": "object",
"properties": {
"addr": {
"description": "端口值",
"type": "integer"
},
"dbType": {
"description": "数据库类型:mysql(默认)|sqlite|sqlserver|postgresql",
"type": "string"
},
"env": {
"description": "环境值",
"type": "string"
},
"ossType": {
"description": "Oss类型",
"type": "string"
},
"useMultipoint": {
"description": "多点登录拦截",
"type": "boolean"
}
}
},
"config.TencentCOS": {
"type": "object",
"properties": {
"baseURL": {
"type": "string"
},
"bucket": {
"type": "string"
},
"pathPrefix": {
"type": "string"
},
"region": {
"type": "string"
},
"secretID": {
"type": "string"
},
"secretKey": {
"type": "string"
}
}
},
"config.Timer": {
"type": "object",
"properties": {
"detail": {
"type": "array",
"items": {
"$ref": "#/definitions/config.Detail"
}
},
"spec": {
"description": "CRON表达式",
"type": "string"
},
"start": {
"description": "是否启用",
"type": "boolean"
}
}
},
"config.Zap": {
"type": "object",
"properties": {
"director": {
"description": "日志文件夹",
"type": "string"
},
"encodeLevel": {
"description": "编码级",
"type": "string"
},
"format": {
"description": "输出",
"type": "string"
},
"level": {
"description": "级别",
"type": "string"
},
"linkName": {
"description": "软链接名称",
"type": "string"
},
"logInConsole": {
"description": "输出控制台",
"type": "boolean"
},
"prefix": {
"description": "日志前缀",
"type": "string"
},
"showLine": {
"description": "显示行",
"type": "boolean"
},
"stacktraceKey": {
"description": "栈名",
"type": "string"
}
}
},
"request.AddMenuAuthorityInfo": {
"type": "object",
"properties": {
@ -1063,6 +1599,14 @@
"type": "string"
}
}
},
"web.System": {
"type": "object",
"properties": {
"config": {
"$ref": "#/definitions/config.Server"
}
}
}
}
}

View File

@ -1,4 +1,303 @@
definitions:
config.AliyunOSS:
properties:
accessKeyId:
type: string
accessKeySecret:
type: string
basePath:
type: string
bucketName:
type: string
bucketUrl:
type: string
endpoint:
type: string
type: object
config.Autocode:
properties:
root:
type: string
server:
type: string
serverApi:
type: string
serverInitialize:
type: string
serverModel:
type: string
serverRequest:
type: string
serverRouter:
type: string
serverService:
type: string
transferRestart:
type: boolean
web:
type: string
webApi:
type: string
webForm:
type: string
webTable:
type: string
type: object
config.Captcha:
properties:
imgHeight:
description: 验证码高度
type: integer
imgWidth:
description: 验证码宽度
type: integer
keyLong:
description: 验证码长度
type: integer
type: object
config.Casbin:
properties:
modelPath:
description: 存放casbin模型的相对路径
type: string
type: object
config.Detail:
properties:
compareField:
description: 需要比较时间的字段
type: string
interval:
description: 时间间隔
type: string
tableName:
description: 需要清理的表名
type: string
type: object
config.Email:
properties:
from:
description: 收件人
type: string
host:
description: 服务器地址
type: string
isSSL:
description: 是否SSL
type: boolean
nickname:
description: 昵称
type: string
port:
description: 端口
type: integer
secret:
description: 密钥
type: string
to:
description: 收件人:多个以英文逗号分隔
type: string
type: object
config.Excel:
properties:
dir:
type: string
type: object
config.JWT:
properties:
bufferTime:
description: 缓冲时间
type: integer
expiresTime:
description: 过期时间
type: integer
signingKey:
description: jwt签名
type: string
type: object
config.Local:
properties:
path:
description: 本地文件路径
type: string
type: object
config.Mysql:
properties:
config:
description: 高级配置
type: string
dbname:
description: 数据库名
type: string
logMode:
description: 是否开启Gorm全局日志
type: string
logZap:
description: 是否通过zap写入日志文件
type: boolean
maxIdleConns:
description: 空闲中的最大连接数
type: integer
maxOpenConns:
description: 打开到数据库的最大连接数
type: integer
password:
description: 数据库密码
type: string
path:
description: 服务器地址:端口
type: string
username:
description: 数据库用户名
type: string
type: object
config.Qiniu:
properties:
accessKey:
description: 秘钥AK
type: string
bucket:
description: 空间名称
type: string
imgPath:
description: CDN加速域名
type: string
secretKey:
description: 秘钥SK
type: string
useCdnDomains:
description: 上传是否使用CDN上传加速
type: boolean
useHttps:
description: 是否使用https
type: boolean
zone:
description: 存储区域
type: string
type: object
config.Redis:
properties:
addr:
description: 服务器地址:端口
type: string
db:
description: redis的哪个数据库
type: integer
password:
description: 密码
type: string
type: object
config.Server:
properties:
aliyunOSS:
$ref: '#/definitions/config.AliyunOSS'
autoCode:
$ref: '#/definitions/config.Autocode'
description: auto
captcha:
$ref: '#/definitions/config.Captcha'
casbin:
$ref: '#/definitions/config.Casbin'
email:
$ref: '#/definitions/config.Email'
excel:
$ref: '#/definitions/config.Excel'
jwt:
$ref: '#/definitions/config.JWT'
local:
$ref: '#/definitions/config.Local'
description: oss
mysql:
$ref: '#/definitions/config.Mysql'
description: gorm
qiniu:
$ref: '#/definitions/config.Qiniu'
redis:
$ref: '#/definitions/config.Redis'
system:
$ref: '#/definitions/config.System'
tencentCOS:
$ref: '#/definitions/config.TencentCOS'
timer:
$ref: '#/definitions/config.Timer'
zap:
$ref: '#/definitions/config.Zap'
type: object
config.System:
properties:
addr:
description: 端口值
type: integer
dbType:
description: 数据库类型:mysql(默认)|sqlite|sqlserver|postgresql
type: string
env:
description: 环境值
type: string
ossType:
description: Oss类型
type: string
useMultipoint:
description: 多点登录拦截
type: boolean
type: object
config.TencentCOS:
properties:
baseURL:
type: string
bucket:
type: string
pathPrefix:
type: string
region:
type: string
secretID:
type: string
secretKey:
type: string
type: object
config.Timer:
properties:
detail:
items:
$ref: '#/definitions/config.Detail'
type: array
spec:
description: CRON表达式
type: string
start:
description: 是否启用
type: boolean
type: object
config.Zap:
properties:
director:
description: 日志文件夹
type: string
encodeLevel:
description: 编码级
type: string
format:
description: 输出
type: string
level:
description: 级别
type: string
linkName:
description: 软链接名称
type: string
logInConsole:
description: 输出控制台
type: boolean
prefix:
description: 日志前缀
type: string
showLine:
description: 显示行
type: boolean
stacktraceKey:
description: 栈名
type: string
type: object
request.AddMenuAuthorityInfo:
properties:
authorityId:
@ -249,6 +548,11 @@ definitions:
description: 用户UUID
type: string
type: object
web.System:
properties:
config:
$ref: '#/definitions/config.Server'
type: object
info:
contact: {}
paths:
@ -506,6 +810,69 @@ paths:
summary: 更新菜单
tags:
- Menu
/system/getServerInfo:
post:
produces:
- application/json
responses:
"200":
description: '{"success":true,"data":{},"msg":"获取成功"}'
schema:
type: string
security:
- ApiKeyAuth: []
summary: 获取服务器信息
tags:
- System
/system/getSystemConfig:
post:
produces:
- application/json
responses:
"200":
description: '{"success":true,"data":{},"msg":"获取成功"}'
schema:
type: string
security:
- ApiKeyAuth: []
summary: 获取配置文件内容
tags:
- System
/system/reloadSystem:
post:
produces:
- application/json
responses:
"200":
description: '{"code":0,"data":{},"msg":"重启系统成功"}'
schema:
type: string
security:
- ApiKeyAuth: []
summary: 重启系统
tags:
- System
/system/setSystemConfig:
post:
parameters:
- description: 设置配置文件内容
in: body
name: data
required: true
schema:
$ref: '#/definitions/web.System'
produces:
- application/json
responses:
"200":
description: '{"success":true,"data":{},"msg":"设置成功"}'
schema:
type: string
security:
- ApiKeyAuth: []
summary: 设置配置文件内容
tags:
- System
/user/changePassword:
post:
parameters:

1
go.mod
View File

@ -18,6 +18,7 @@ require (
github.com/mojocn/base64Captcha v1.3.1
github.com/robfig/cron/v3 v3.0.1
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil v3.20.11+incompatible
github.com/songzhibin97/gkit v1.1.1
github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.7.0

3
go.sum
View File

@ -24,6 +24,7 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
@ -93,6 +94,7 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
@ -376,6 +378,7 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shirou/gopsutil v3.20.11+incompatible h1:LJr4ZQK4mPpIV5gOa4jCOKOGb4ty4DZO54I4FGqIpto=
github.com/shirou/gopsutil v3.20.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=

Binary file not shown.

View File

@ -1 +1 @@
log/2021-11-01.log
log/2021-11-02.log

View File

@ -38,3 +38,12 @@
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/01 - 18:12:49.860 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:43 router register success
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/01 - 18:12:49.861 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/01 - 18:13:19.271 error /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8888: use of closed network connection
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/01 - 18:30:05.640 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:43 router register success
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/01 - 18:30:05.644 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/01 - 18:30:05.644 error /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 net.Listen error: listen tcp :8888: bind: address already in use
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/01 - 18:30:24.169 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:43 router register success
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/01 - 18:30:24.170 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/01 - 18:56:07.799 error /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8888: use of closed network connection
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/01 - 18:57:34.874 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:43 router register success
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/01 - 18:57:34.877 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/01 - 18:57:55.922 error /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8888: use of closed network connection

6
log/2021-11-02.log Normal file
View File

@ -0,0 +1,6 @@
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/02 - 09:23:57.317 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:43 router register success
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/02 - 09:23:57.319 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/02 - 09:26:03.968 error /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8888: use of closed network connection
[goweb-demo]2021/11/02 - 11:30:42.979 info /Users/zero/work/mygithub/goweb-gin-demo/initialize/router.go:43 router register success
[goweb-demo]2021/11/02 - 11:30:42.982 info /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:31 server run success on {"address": ":8888"}
[goweb-demo]2021/11/02 - 11:30:44.819 error /Users/zero/work/mygithub/goweb-gin-demo/core/server.go:38 accept tcp [::]:8888: use of closed network connection

View File

@ -0,0 +1,7 @@
package response
import "goweb-gin-demo/config"
type SysConfigResponse struct {
Config config.Server `json:"config"`
}

10
model/web/system.go Normal file
View File

@ -0,0 +1,10 @@
package web
import (
"goweb-gin-demo/config"
)
// 配置文件结构体
type System struct {
Config config.Server `json:"config"`
}

View File

@ -7,6 +7,7 @@ type ServiceGroup struct {
OperationRecordService
MenuService
BaseMenuService
SystemConfigService
}
var ServiceGroupApp = new(ServiceGroup)

61
service/system.go Normal file
View File

@ -0,0 +1,61 @@
package service
import (
"go.uber.org/zap"
"goweb-gin-demo/config"
"goweb-gin-demo/global"
"goweb-gin-demo/model/web"
"goweb-gin-demo/utils"
)
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetSystemConfig
//@description: 读取配置文件
//@return: err error, conf config.Server
type SystemConfigService struct {
}
func (systemConfigService *SystemConfigService) GetSystemConfig() (err error, conf config.Server) {
return nil, global.GLOBAL_CONFIG
}
// @description set system config,
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetSystemConfig
//@description: 设置配置文件
//@param: system model.System
//@return: err error
func (systemConfigService *SystemConfigService) SetSystemConfig(web web.System) (err error) {
cs := utils.StructToMap(web.Config)
for k, v := range cs {
global.GLOBAL_VP.Set(k, v)
}
err = global.GLOBAL_VP.WriteConfig()
return err
}
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: GetServerInfo
//@description: 获取服务器信息
//@return: server *utils.Server, err error
func (systemConfigService *SystemConfigService) GetServerInfo() (server *utils.Server, err error) {
var s utils.Server
s.Os = utils.InitOS()
if s.Cpu, err = utils.InitCPU(); err != nil {
global.GLOBAL_LOG.Error("func utils.InitCPU() Failed", zap.String("err", err.Error()))
return &s, err
}
if s.Rrm, err = utils.InitRAM(); err != nil {
global.GLOBAL_LOG.Error("func utils.InitRAM() Failed", zap.String("err", err.Error()))
return &s, err
}
if s.Disk, err = utils.InitDisk(); err != nil {
global.GLOBAL_LOG.Error("func utils.InitDisk() Failed", zap.String("err", err.Error()))
return &s, err
}
return &s, nil
}

38
utils/fmt_plus.go Normal file
View File

@ -0,0 +1,38 @@
package utils
import (
"fmt"
"reflect"
"strings"
)
//@author: [piexlmax](https://github.com/piexlmax)
//@function: StructToMap
//@description: 利用反射将结构体转化为map
//@param: obj interface{}
//@return: map[string]interface{}
func StructToMap(obj interface{}) map[string]interface{} {
obj1 := reflect.TypeOf(obj)
obj2 := reflect.ValueOf(obj)
var data = make(map[string]interface{})
for i := 0; i < obj1.NumField(); i++ {
if obj1.Field(i).Tag.Get("mapstructure") != "" {
data[obj1.Field(i).Tag.Get("mapstructure")] = obj2.Field(i).Interface()
} else {
data[obj1.Field(i).Name] = obj2.Field(i).Interface()
}
}
return data
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: ArrayToString
//@description: 将数组格式化为字符串
//@param: array []interface{}
//@return: string
func ArrayToString(array []interface{}) string {
return strings.Replace(strings.Trim(fmt.Sprint(array), "[]"), " ", ",", -1)
}

18
utils/reload.go Normal file
View File

@ -0,0 +1,18 @@
package utils
import (
"errors"
"os"
"os/exec"
"runtime"
"strconv"
)
func Reload() error {
if runtime.GOOS == "windows" {
return errors.New("系统不支持")
}
pid := os.Getpid()
cmd := exec.Command("kill", "-1", strconv.Itoa(pid))
return cmd.Run()
}

117
utils/server.go Normal file
View File

@ -0,0 +1,117 @@
package utils
import (
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/mem"
"runtime"
"time"
)
const (
B = 1
KB = 1024 * B
MB = 1024 * KB
GB = 1024 * MB
)
type Server struct {
Os Os `json:"os"`
Cpu Cpu `json:"cpu"`
Rrm Rrm `json:"ram"`
Disk Disk `json:"disk"`
}
type Os struct {
GOOS string `json:"goos"`
NumCPU int `json:"numCpu"`
Compiler string `json:"compiler"`
GoVersion string `json:"goVersion"`
NumGoroutine int `json:"numGoroutine"`
}
type Cpu struct {
Cpus []float64 `json:"cpus"`
Cores int `json:"cores"`
}
type Rrm struct {
UsedMB int `json:"usedMb"`
TotalMB int `json:"totalMb"`
UsedPercent int `json:"usedPercent"`
}
type Disk struct {
UsedMB int `json:"usedMb"`
UsedGB int `json:"usedGb"`
TotalMB int `json:"totalMb"`
TotalGB int `json:"totalGb"`
UsedPercent int `json:"usedPercent"`
}
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: InitCPU
//@description: OS信息
//@return: o Os, err error
func InitOS() (o Os) {
o.GOOS = runtime.GOOS
o.NumCPU = runtime.NumCPU()
o.Compiler = runtime.Compiler
o.GoVersion = runtime.Version()
o.NumGoroutine = runtime.NumGoroutine()
return o
}
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: InitCPU
//@description: CPU信息
//@return: c Cpu, err error
func InitCPU() (c Cpu, err error) {
if cores, err := cpu.Counts(false); err != nil {
return c, err
} else {
c.Cores = cores
}
if cpus, err := cpu.Percent(time.Duration(200)*time.Millisecond, true); err != nil {
return c, err
} else {
c.Cpus = cpus
}
return c, nil
}
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: InitRAM
//@description: ARM信息
//@return: r Rrm, err error
func InitRAM() (r Rrm, err error) {
if u, err := mem.VirtualMemory(); err != nil {
return r, err
} else {
r.UsedMB = int(u.Used) / MB
r.TotalMB = int(u.Total) / MB
r.UsedPercent = int(u.UsedPercent)
}
return r, nil
}
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: InitDisk
//@description: 硬盘信息
//@return: d Disk, err error
func InitDisk() (d Disk, err error) {
if u, err := disk.Usage("/"); err != nil {
return d, err
} else {
d.UsedMB = int(u.Used) / MB
d.UsedGB = int(u.Used) / GB
d.TotalMB = int(u.Total) / MB
d.TotalGB = int(u.Total) / GB
d.UsedPercent = int(u.UsedPercent)
}
return d, nil
}