Compare commits
4 Commits
v1.0.00020
...
main
| Author | SHA1 | Date |
|---|---|---|
|
|
60f0d8053d | |
|
|
258112d38e | |
|
|
8927551779 | |
|
|
0ad7304eca |
|
|
@ -87,6 +87,22 @@
|
|||
</set>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="NewsOne">
|
||||
<value>
|
||||
<set>
|
||||
<option value="file://$PROJECT_DIR$/../gin_test/api/new.go" />
|
||||
<option value="file://$PROJECT_DIR$/../gin_test/req/new.go" />
|
||||
</set>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="NewsSave">
|
||||
<value>
|
||||
<set>
|
||||
<option value="file://$PROJECT_DIR$/../gin_test/api/new.go" />
|
||||
<option value="file://$PROJECT_DIR$/../gin_test/req/new.go" />
|
||||
</set>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="Paginate">
|
||||
<value>
|
||||
<set>
|
||||
|
|
@ -185,7 +201,7 @@
|
|||
<entry key="file://$PROJECT_DIR$/database/database.go">
|
||||
<value>
|
||||
<ScannedPath>
|
||||
<option name="lastModified" value="1770100613057" />
|
||||
<option name="lastModified" value="1770258641711" />
|
||||
</ScannedPath>
|
||||
</value>
|
||||
</entry>
|
||||
|
|
@ -326,7 +342,7 @@
|
|||
<entry key="file://$PROJECT_DIR$/valid/valid.go">
|
||||
<value>
|
||||
<ScannedPath>
|
||||
<option name="lastModified" value="1770185876649" />
|
||||
<option name="lastModified" value="1770197737203" />
|
||||
</ScannedPath>
|
||||
</value>
|
||||
</entry>
|
||||
|
|
@ -352,6 +368,67 @@
|
|||
</ScannedPath>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="file://$PROJECT_DIR$/../gin_test/api/home.go">
|
||||
<value>
|
||||
<ScannedPath>
|
||||
<option name="lastModified" value="1770190095707" />
|
||||
</ScannedPath>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="file://$PROJECT_DIR$/../gin_test/api/new.go">
|
||||
<value>
|
||||
<ScannedPath>
|
||||
<option name="lastModified" value="1770191206242" />
|
||||
<option name="schema">
|
||||
<list>
|
||||
<option value="NewsOne" />
|
||||
<option value="NewsSave" />
|
||||
</list>
|
||||
</option>
|
||||
</ScannedPath>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="file://$PROJECT_DIR$/../gin_test/controller/home/houeRouter.go">
|
||||
<value>
|
||||
<ScannedPath>
|
||||
<option name="lastModified" value="1770191001042" />
|
||||
</ScannedPath>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="file://$PROJECT_DIR$/../gin_test/controller/home/index.go">
|
||||
<value>
|
||||
<ScannedPath>
|
||||
<option name="lastModified" value="1770255253603" />
|
||||
</ScannedPath>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="file://$PROJECT_DIR$/../gin_test/controller/home/router.go">
|
||||
<value>
|
||||
<ScannedPath>
|
||||
<option name="lastModified" value="1770190557848" />
|
||||
</ScannedPath>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="file://$PROJECT_DIR$/../gin_test/req/new.go">
|
||||
<value>
|
||||
<ScannedPath>
|
||||
<option name="lastModified" value="1770186504009" />
|
||||
<option name="schema">
|
||||
<list>
|
||||
<option value="NewsOne" />
|
||||
<option value="NewsSave" />
|
||||
</list>
|
||||
</option>
|
||||
</ScannedPath>
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="file://$PROJECT_DIR$/../gin_test/router/router.go">
|
||||
<value>
|
||||
<ScannedPath>
|
||||
<option name="lastModified" value="1770191024510" />
|
||||
</ScannedPath>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
<option name="tableStructMapping">
|
||||
|
|
@ -368,6 +445,8 @@
|
|||
<entry key="jwt_config" value="JwtConfig" />
|
||||
<entry key="manager" value="Manager" />
|
||||
<entry key="msg" value="Msg" />
|
||||
<entry key="news_one" value="NewsOne" />
|
||||
<entry key="news_save" value="NewsSave" />
|
||||
<entry key="paginate" value="Paginate" />
|
||||
<entry key="response" value="response" />
|
||||
<entry key="server_config" value="ServerConfig" />
|
||||
|
|
|
|||
|
|
@ -68,10 +68,12 @@ func mysqlInit() {
|
|||
}
|
||||
|
||||
func sqliteInit() {
|
||||
_, err = gfile.Create(dns.String())
|
||||
if err != nil {
|
||||
log.Error("创建数据库文件失败: ", err)
|
||||
return
|
||||
if !gfile.Exists(dns.String()) {
|
||||
_, err = gfile.Create(dns.String())
|
||||
if err != nil {
|
||||
log.Error("创建数据库文件失败: ", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
Type = sqlite.Open(fmt.Sprintf("%s?cache=shared&mode=rwc&_busy_timeout=10000&_fk=1&_journal=WAL&_sync=FULL", dns.String()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,16 +4,41 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// ValidAndStruct 验证参数并返回结构体
|
||||
func ValidAndStruct[T any](c *gin.Context) (object *T) {
|
||||
object = new(T)
|
||||
if err := c.BindJSON(object); err != nil {
|
||||
// ValidToStruct 验证参数并返回结构体
|
||||
func ValidToStruct[T any](c *gin.Context) (object *T) {
|
||||
obj := new(T)
|
||||
if err := c.Bind(obj); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := g.Validator().Data(object).Run(c); err != nil {
|
||||
if err := g.Validator().Data(obj).Run(c); err != nil {
|
||||
panic(gerror.Current(err).Error())
|
||||
}
|
||||
return
|
||||
return obj
|
||||
}
|
||||
|
||||
// ValidToMap 验证参数并返回结构体
|
||||
func ValidToMap[T any](c *gin.Context) (object map[string]any) {
|
||||
obj := new(T)
|
||||
if err := c.Bind(obj); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := g.Validator().Data(obj).Run(c); err != nil {
|
||||
panic(gerror.Current(err).Error())
|
||||
}
|
||||
return gconv.Map(obj)
|
||||
}
|
||||
|
||||
// ValidToStructAndMap 验证参数并返回map
|
||||
func ValidToStructAndMap[T any](c *gin.Context) (stru *T, object map[string]any) {
|
||||
obj := new(T)
|
||||
if err := c.Bind(obj); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := g.Validator().Data(obj).Run(c); err != nil {
|
||||
panic(gerror.Current(err).Error())
|
||||
}
|
||||
return obj, gconv.Map(obj)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue