14 Star 207 Fork 31

杰克 / elk-blog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
index.go 1.79 KB
一键复制 编辑 原始数据 按行查看 历史
jikeytang 提交于 2022-08-02 22:31 . 增加文章评论,删除无用图片
package admin
import (
"gitee.com/jikey/elk-blog/pkg/response"
"gitee.com/jikey/elk-blog/pkg/utils"
"github.com/flosch/pongo2"
"github.com/gin-gonic/gin"
"github.com/vjeantet/jodaTime"
"runtime"
"time"
)
type Index struct{}
func (_ *Index) Index(c *gin.Context) {
data := make(map[string]interface{})
data["site"] = Site
info := map[string]interface{}{
"语言": runtime.Version(),
"版本": "v-0.1",
"当前时间": utils.GetTime(),
"北京时间": jodaTime.Format("yyyy年MM月dd HH:mm:ss", time.Now()),
"服务器域名/IP": c.ClientIP(),
"操作系统": runtime.GOOS,
"Host": c.ClientIP(),
}
c.HTML(200, "admin/index/index.html", pongo2.Context{
"info": info,
"data": data,
})
}
// Welcome 欢迎
func (_ *Index) Welcome(c *gin.Context) {
info := map[string]interface{}{
"语言": runtime.Version(),
"版本": "v-0.1",
"当前时间": utils.GetTime(),
"北京时间": jodaTime.Format("yyyy年MM月dd HH:mm:ss", time.Now()),
"服务器域名/IP": c.ClientIP(),
"操作系统": runtime.GOOS,
"Host": c.ClientIP(),
}
c.HTML(200, "admin/index/welcome.html", pongo2.Context{
"info": info,
})
}
type Student struct {
Name string `json:"name"`
Age int
Class *Class `json:"class"`
}
type Class struct {
Name string
Grade int `json:"grade"`
}
type Rank struct {
// 用到json记得一定大写首字母
UserId string `json:"userId"`
Name string `json:"name"`
}
// Test 欢迎
func (_ *Index) Test(c *gin.Context) {
// fmt.Println("Test test")
student := Student{
Name: "李四",
Age: 14,
}
//
class := new(Class)
class.Name = "608班"
class.Grade = 6
student.Class = class
//
if err := c.ShouldBind(&student); err != nil {
response.JSON(c, student)
return
}
response.JSON(c, student)
}
Go
1
https://gitee.com/jikey/elk-blog.git
git@gitee.com:jikey/elk-blog.git
jikey
elk-blog
elk-blog
d402f94cccdf

搜索帮助