Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
50cac8f0
G
gin-vue-admin
项目概览
FLIPPED-AURORA
/
gin-vue-admin
大约 1 年 前同步成功
通知
345
Star
18155
Fork
5506
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
50cac8f0
编写于
9月 02, 2019
作者:
Mr.奇淼(
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
swagger配置 数据库初始化结构调整
上级
f6a0b05e
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
76 addition
and
24 deletion
+76
-24
QMPlusServer/controller/api/user.go
QMPlusServer/controller/api/user.go
+26
-0
QMPlusServer/go.mod
QMPlusServer/go.mod
+2
-0
QMPlusServer/init/initRouter/initRouter.go
QMPlusServer/init/initRouter/initRouter.go
+7
-4
QMPlusServer/init/mysql/initMysql.go
QMPlusServer/init/mysql/initMysql.go
+3
-3
QMPlusServer/init/registTable/registTable.go
QMPlusServer/init/registTable/registTable.go
+10
-0
QMPlusServer/main.go
QMPlusServer/main.go
+8
-15
QMPlusServer/model/dbModel/user.go
QMPlusServer/model/dbModel/user.go
+6
-1
QMPlusServer/model/modelInterface/interface.go
QMPlusServer/model/modelInterface/interface.go
+1
-1
QMPlusServer/router/user.go
QMPlusServer/router/user.go
+13
-0
未找到文件。
QMPlusServer/controller/api/user.go
0 → 100644
浏览文件 @
50cac8f0
package
api
import
(
"fmt"
"github.com/gin-gonic/gin"
"main/model/dbModel"
)
type
RegistStuct
struct
{
UserName
string
`json:"userName"`
PassWord
string
`json:"passWord"`
}
// @Summary 创建用户
// @Produce application/x-www-form-urlencoded
// @Param data body api.RegistStuct true "用户注册接口"
// @Success 200 {string} json "{"code":200,"data":{},"msg":"ok"}"
// @Router /user/regist [post]
func
Regist
(
c
*
gin
.
Context
)
{
var
U
dbModel
.
User
_
=
c
.
BindJSON
(
&
U
)
fmt
.
Println
(
U
)
err
,
user
:=
U
.
Create
()
fmt
.
Println
(
err
,
user
)
}
QMPlusServer/go.mod
浏览文件 @
50cac8f0
...
...
@@ -3,6 +3,7 @@ module main
go 1.12
require (
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/fsnotify/fsnotify v1.4.7
...
...
@@ -17,5 +18,6 @@ require (
github.com/sirupsen/logrus v1.2.0
github.com/spf13/viper v1.4.0
github.com/swaggo/gin-swagger v1.2.0
github.com/swaggo/swag v1.5.1
github.com/tebeka/strftime v0.1.3 // indirect
)
QMPlusServer/init/initRouter.go
→
QMPlusServer/init/initRouter
/initRouter
.go
浏览文件 @
50cac8f0
package
init
package
init
Router
import
(
"github.com/gin-gonic/gin"
"github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"
_
"main/docs"
"main/router"
)
var
Router
=
gin
.
Default
()
func
InitRouter
()
{
func
InitRouter
()
*
gin
.
Engine
{
var
Router
=
gin
.
Default
()
Router
.
GET
(
"/swagger/*any"
,
ginSwagger
.
WrapHandler
(
swaggerFiles
.
Handler
))
//Router.Use(middleware.Logger())
router
.
InitUserRouter
(
Router
)
return
Router
}
QMPlusServer/init/initMysql.go
→
QMPlusServer/init/
mysql/
initMysql.go
浏览文件 @
50cac8f0
package
init
package
mysql
import
(
"github.com/jinzhu/gorm"
...
...
@@ -9,13 +9,13 @@ import (
var
DEFAULTDB
*
gorm
.
DB
func
InitMysql
(
admin
config
.
Admin
)
{
func
InitMysql
(
admin
config
.
Admin
)
*
gorm
.
DB
{
if
db
,
err
:=
gorm
.
Open
(
"mysql"
,
admin
.
UserName
+
":"
+
admin
.
Password
+
"@("
+
admin
.
Path
+
")/"
+
admin
.
Dbname
+
"?"
+
admin
.
Config
);
err
!=
nil
{
log
.
Printf
(
"DEFAULTDB数据库启动异常%S"
,
err
)
}
else
{
DEFAULTDB
=
db
DEFAULTDB
.
DB
()
.
SetMaxIdleConns
(
10
)
DEFAULTDB
.
DB
()
.
SetMaxIdleConns
(
100
)
DEFAULTDB
.
AutoMigrate
()
}
return
DEFAULTDB
}
QMPlusServer/init/registTable/registTable.go
0 → 100644
浏览文件 @
50cac8f0
package
registTable
import
(
"github.com/jinzhu/gorm"
"main/model/dbModel"
)
func
RegistTable
(
db
*
gorm
.
DB
)
{
db
.
AutoMigrate
(
dbModel
.
User
{})
}
QMPlusServer/main.go
浏览文件 @
50cac8f0
...
...
@@ -2,28 +2,21 @@ package main
import
(
"main/config"
"main/init"
"main/init/initRouter"
"main/init/mysql"
"main/init/registTable"
"net/http"
"time"
)
// @Summary 打印测试功能
// @title Swagger Example API
// @version 0.0.1
// @description This is a sample server Petstore server.
// @BasePath /api/v1
// @Host 127.0.0.1:8080
// @Produce json
// @Param name query string true "Name"
// @Success 200 {string} json "{"code":200,"data":"name","msg":"ok"}"
// @Router / [get]
func
main
()
{
init
.
InitMysql
(
config
.
Dbconfig
.
Admin
)
defer
init
.
DEFAULTDB
.
Close
()
init
.
InitRouter
()
registTable
.
RegistTable
(
mysql
.
InitMysql
(
config
.
Dbconfig
.
Admin
))
defer
mysql
.
DEFAULTDB
.
Close
()
Router
:=
initRouter
.
InitRouter
()
s
:=
&
http
.
Server
{
Addr
:
":8888"
,
Handler
:
init
.
Router
,
Handler
:
Router
,
ReadTimeout
:
10
*
time
.
Second
,
WriteTimeout
:
10
*
time
.
Second
,
MaxHeaderBytes
:
1
<<
20
,
...
...
QMPlusServer/model/user.go
→
QMPlusServer/model/
dbModel/
user.go
浏览文件 @
50cac8f0
package
m
odel
package
dbM
odel
import
(
"github.com/jinzhu/gorm"
uuid
"github.com/satori/go.uuid"
"main/init/mysql"
)
type
User
struct
{
...
...
@@ -19,3 +20,7 @@ type User struct {
//type Propertie struct {
// gorm.Model
//}
func
(
u
*
User
)
Create
()
(
err
error
,
user
interface
{})
{
err
=
mysql
.
DEFAULTDB
.
Create
(
u
)
.
Error
return
err
,
user
}
QMPlusServer/model/interface.go
→
QMPlusServer/model/
modelInterface/
interface.go
浏览文件 @
50cac8f0
package
model
package
model
Interface
// 因为我也不确定项目要不要多人维护 所以定义了CURD接口 凡是对数据库进行简单CURD操作 请实现此接口 默认首位返回 error
type
CURD
interface
{
...
...
QMPlusServer/router/user.go
0 → 100644
浏览文件 @
50cac8f0
package
router
import
(
"github.com/gin-gonic/gin"
"main/controller/api"
)
func
InitUserRouter
(
Router
*
gin
.
Engine
)
{
UserRouter
:=
Router
.
Group
(
"user"
)
{
UserRouter
.
POST
(
"regist"
,
api
.
Regist
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录