package main import ( "GINDEMO/routers" "fmt" "html/template" "time" "github.com/gin-gonic/gin" ) func UnixToTime(timestamp int) string { fmt.Println(timestamp) t := time.Unix(int64(timestamp), 0) return t.Format("2006-01-02 15:04:05") } func main() { //创建一个默认的路...
go get -u github.com/gin-gonic/gin或者 执行 go mod tidy下载依赖import ("github.com/gin-gonic/gin")func main() {r := gin.Default() //拿到一个 *gin.Enginer.GET("ping", func(ctx *gin.Context) { //获取GET请求ctx.JSON(200, gin.H{ //响应页面"msg": "pong",})})r.Run() //...
"github.com/gin-gonic/gin" ) func main() { //初始化路由 router := gin.Default() //加载templates中所有模板文件, 使用不同目录下名称相同的模板,注意:一定要放在配置路由之前才得行 router.LoadHTMLGlob("templates/*") //router.LoadHTMLFiles("templates/template1.html", "templates/template2.html"...
一般大部分项目中都会有配置文件用来配置数据库连接字符串, 日志等级等. 这里我们创建conf/config.go packageconfimport("github.com/pelletier/go-toml/v2""io""os")typeRedisConfstruct{Addrstring`toml:"addr"`Passwordstring`toml:"password"`}typeConfigstruct{Debugbool`toml:"debug"`Portint64`toml:"port"`D...
1packagemain23import(4"fmt"5"net/http"6"text/template"7"time"89"github.com/gin-gonic/gin"10)1112funcmain() {13TestTemelates()14}1516funcUnixToTime(timestampint) (resultstring, errerror) {17fmt.Println(timestamp)18t := time.Unix(int64(timestamp),0)19returnt.Format("2006-01-02 15:...
"github.com/gin-gonic/gin" ) type myForm struct { Colors []string `form:"colors[]"` } func main() { r := gin.Default() r.LoadHTMLGlob("template/*") r.GET("/", indexHandler) r.POST("/", formHandler) r.Run(":8080") ...
Kratos基于插件机制开发,极其容易对其进行扩展(看我的kratos-transport,我甚至插入了Gin、FastHttp、Hertz等Web框架)。 综上,是我的理由。在做技术选型的时候,我是横向对比了市面上几乎所有的框架,最终选择了Kratos。 还有一点就是,微服务的开发过程,并不是一步到位的——微服务的开发是渐进的,正所谓:一生二,二生三...
runtemplate - 一个非常简单的用于执行 Go 模板的命令行工具,对于与go generate. runtemplate - 用于执行 Go 模板以支持为您的类型生成 Go 代码的简单工具。 sift - 快速而强大的开源替代品grep tecla - 命令行编辑库 Terracognita - 从现有的云提供商(反向 Terraform)读取并生成您的基础设施作为 Terraform 配置...
"/gin-gonic/gin" ) type myForm struct { Colors []string `form:"colors[]"` } func main() { r := gin.Default() r.LoadHTMLGlob("template/*") r.GET("/", indexHandler) r.POST("/", formHandler) r.Run(":8080") } func indexHandler(c *gin.Context) { ...
packagemainimport("fmt""net/http""os""path/filepath""text/template""github.com/gin-gonic/gin")typeProductstruct{Idint64`json:"id"`//字段一定要大写不然各种问题Namestring`json:"name"`}//模拟从数据库查询过来的消息varallproduct[]*Product=[]*Product{{1,"苹果手机"},{2,"苹果电脑"},{3,"...