Movatterモバイル変換


[0]ホーム

URL:


codecamp

Gin HTTP2 server 推送

http.Pusher​ 仅支持 ​go1.8+

package mainimport ("html/template""log""github.com/gin-gonic/gin")var html = template.Must(template.New("https").Parse(`<html><head>  <title>Https Test</title>  <script src="/assets/app.js"></script></head><body>  <h1>Welcome, Ginner!</h1></body></html>`))func main() {r := gin.Default()r.Static("/assets", "./assets")r.SetHTMLTemplate(html)r.GET("/", func(c *gin.Context) {if pusher := c.Writer.Pusher(); pusher != nil {// 使用 pusher.Push() 做服务器推送if err := pusher.Push("/assets/app.js", nil); err != nil {log.Printf("Failed to push: %v", err)}}c.HTML(200, "https", gin.H{"status": "success",})})// 监听并在 https://127.0.0.1:8080 上启动服务r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key")}


Gin AsciiJSON
Gin JSONP
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录
Gin 介绍
Gin 快速入门
Gin RESTful API
Gin HTML渲染
Gin 获取参数
Gin 路由
Gin 中间件
Gin 参数绑定
Gin 文件上传
Gin 重定向
Gin 设置和获取Cookie
Gin 如何记录日志
Gin 在中间件中使用Goroutine
Gin 绑定HTML复选框
Gin AsciiJSON
Gin HTTP2 server 推送
Gin JSONP
Gin PureJSON
Gin SecureJSON
Gin XML/JSON/YAML/ProtoBuf 渲染
Gin 优雅地重启或停止

关闭

MIP.setData({'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false},'pageFontSize' : getCookie('pageFontSize') || 20});MIP.watch('pageTheme', function(newValue){setCookie('pageTheme', JSON.stringify(newValue))});MIP.watch('pageFontSize', function(newValue){setCookie('pageFontSize', newValue)});function setCookie(name, value){var days = 1;var exp = new Date();exp.setTime(exp.getTime() + days*24*60*60*1000);document.cookie = name + '=' + value + ';expires=' + exp.toUTCString();}function getCookie(name){var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null;}
[8]ページ先頭

©2009-2025 Movatter.jp