fix: 修改代码目录结构

This commit is contained in:
chenwj 2023-05-27 17:32:56 +08:00
parent 3d50388ee7
commit 885f5a44d6
7 changed files with 39 additions and 3 deletions

View File

@ -3,7 +3,7 @@ package v1
import(
"log"
"github.com/gin-gonic/gin"
"wx-backend-go/util"
"wx-backend-go/src/utils"
)
const Token = "aaa325"

View File

@ -6,4 +6,5 @@ func InitRouters(prefix string, e *gin.Engine) {
g := e.Group(prefix)
g.GET("", Greeting)
g.GET("/league/list", GetLeagueList)
g.GET("/tabs", GetTabsList)
}

View File

@ -4,7 +4,7 @@ import (
"time"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"wx-backend-go/models"
"wx-backend-go/src/models"
)
@ -23,6 +23,11 @@ type FootballLeague struct {
CreatedAt time.Time `json:"created_at"`
}
type Tabs struct {
ID int `json:"id"`
Name string `json:"name"`
}
func GetLeagueList(c *gin.Context) {
session := models.DB.Session(&gorm.Session{})
@ -33,4 +38,20 @@ func GetLeagueList(c *gin.Context) {
"data": leagueList,
})
}
func GetTabsList(c *gin.Context) {
session := models.DB.Session(&gorm.Session{})
var tabsList []Tabs
session.Model(&models.Tabs{}).Find(&tabsList)
// var result map[string]map
c.JSON(200, gin.H{
"data": tabsList,
})
}

View File

@ -11,7 +11,7 @@ import (
var DB *gorm.DB
func init() {
dsn := "root:Chenweijia113!@(172.17.0.1:3306)/lottery?charset=utf8mb4&parseTime=True&loc=Local"
dsn := "root:123456@(127.0.0.1:3306)/weixin?charset=utf8mb4&parseTime=True&loc=Local"
var err error
DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {

14
src/models/tabs.go Normal file
View File

@ -0,0 +1,14 @@
package models
type Tabs struct {
ID int `gorm:"primaryKey;column:id;type:int;not null"`
Name string `gorm:"column:name;type:varchar(255);default:null"`
}
// TableName 解决gorm表明映射
func (Tabs) TableName() string {
return "tabs"
}