当前位置: 首页 > news >正文

制作网站费用太原优化排名推广

制作网站费用,太原优化排名推广,什么是网络营销方案,湖南省郴州市宜章县一,Gin介绍 Gin是一个 Go (Golang) 编写的轻量级 http web 框架,运行速度非常快,如果你是性能和高效的追求者,我们推荐你使用Gin框架。 Gin最擅长的就是Api接口的高并发,如果项目的规模不大,业务相对简单…

一,Gin介绍

Gin是一个 Go (Golang) 编写的轻量级 http web 框架,运行速度非常快,如果你是性能和高效的追求者,我们推荐你使用Gin框架。
Gin最擅长的就是Api接口的高并发,如果项目的规模不大,业务相对简单,这个时候我们也推荐你使用 Gin.
当某个接口的性能遭到较大挑战的时候,这个还是可以考虑使用Gin重写接口。
Gin 也是一个流行的 golang Web 框架,Github Start 量已经超过了50k.
Gin的官网:
Gin的官网:
https://gin-gonic.com/zh-cn/
Gin Github地址:
https://github.com/gin-gonic/gin

二,Gin环境搭建

要安装 Gin 软件包,需要先安装 Go并设置 Go 工作区。
1,下载并安装 gin:
go get -u github.com/gin-gonic/ginhttps://github.com/gin-gonic/gin
go install github.com/gin-gonic/gin@latest
go mod init gindemo01
go mod init Administrator
go mod tidy
go get -u github.com/gin-gonic/gin
2,将 gin 引入到代码中:
import "github.com/gin-gonic/gin"
3,(可选) 如果使用诸如 http.StatusOK之类的常量,则需要引入 net/http 包:
import "net/http"
4,新建 Main.go 配置路由
package main
import main() {// 创建一个默认的路由引擎r := gin.Default()// 配置路由r.GET("/",func(c *gin.Context) {c.JSON(200,gin.H{ // c.JSON:返回JSON格式的数据"message":"Hello world!",})})// 启动 HTTP 服务,默认在 0.0.0.0:8080 启动服务r.Run()
}
5,运行你的项目
go run main.goPS G:\GO\gin\gindemo01> go run main.go
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.- using env:   export GIN_MODE=release- using code:  gin.SetMode(gin.ReleaseMode)[GIN-debug] GET    /                         --> main.main.func1 (3 handlers)
[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
[GIN-debug] Environment variable PORT is undefined. Using port :8080 by default
[GIN-debug] Listening and serving HTTP on :8080
[GIN] 2025/01/06 - 10:29:16 | 200 |   548.6µs |   ::1 | GET      "/"
[GIN] 2025/01/06 - 10:29:16 | 404 |   0s |  ::1 | GET    "/favicon.ico"
[GIN] 2025/01/06 - 10:32:48 | 404 |   0s |  ::1 | GET      "/new"
// 改完代码以后要重新运行
[GIN-debug] Listening and serving HTTP on :8080
[GIN] 2025/01/06 - 10:34:50 | 200 |  0s |          ::1 | GET      "/"
[GIN] 2025/01/06 - 10:34:53 | 200 |  0s |          ::1 | GET      "/new"
6,要改变默认启动的端口
r.Run(":9000")
如果 go get 失败请参考:
http://bbs.itying.com/topic/Sed08edee7c0790f8475e276

三,golang程序的热加载

所谓热加载就是当我们对代码进行修改时,程序能够自动重新加载并执行,这在我们开发中是非常便利的,可以快速进行代码测试,省去了每次手动重新编译
beego中我们可以使用官方给我们提供的bee工具来热加载项目,但是gin中并没有官方提供的热加载工具,这个时候我们要实现热加载就可以借助第三方的工具。
工具1 (推荐)
https://github.com/gravityblast/freshgo install github.com/gravityblast/fresh@latestgo get github.com/pilu/freshG:/GO/gin_demo>fresh
工具2:
https://github.com/codegangsta/gingo get -u github.com/codegangsta/ginG:/GO/gin_demo>gin run main.go

四,Gin框架中的路由

4.1,路由概述

路由 (Routing) 是由一个 URI (或者叫路径) 和一个特定的 HTTP方法(GET,POST等)组成的,涉及到应用如何响应客户端对某个网站节点的访问。
RESTful API 是目前比较成熟的一套互联网应用程序的API设计理论,所以我们设计我们的路由的时候建议参考 RESTful API 指南。
在 RESTful 架构中,每个网址代表一种资源,不同的请求方式表示执行不同的操作:
GET(SELECT)从服务器取出资源(一项或多项)
POST(CREATE)在服务器新建一个资源
PUT(UPDATE)在服务器更新资源(客户端提供改变后的完整资源)
DELETE(DELETE)从服务器删除资源

4.2,简单的路由配置

简单的路由配置(可以通过 postman 测试)
当用GET请求访问一个网址的时候,做什么事情:
路由配置实践:
package mainimport ("net/http""github.com/gin-gonic/gin"
)func main() {// 创建一个默认的路由引擎r := gin.Default()// 配置路由 绑定路由规则,执行的函数r.GET("/", func(c *gin.Context) {c.String(http.StatusOK, "值:%v", "您好gin")})r.GET("/news", func(c *gin.Context) {c.String(http.StatusOK, "我是新闻页面 111")})// r.GET("/about", func(c *gin.Context) {// 	c.String(200, "我是关于页面 222")// })// r.GET("/login", func(c *gin.Context) {// 	c.String(200, "这是一个登录页面")// })// r.GET("/register", func(c *gin.Context) {// 	c.String(200, "这是一个注册页面")// })// r.GET("/user/:name", func(c *gin.Context) {// 	name := c.Param("name")// 	c.String(200, "这是一个用户页面 %s", name)// })// r.GET("/user/:name/:age", func(c *gin.Context) {// 	name := c.Param("name")// 	age := c.Param("age")// 	c.String(200, "这是一个用户页面 %s %s", name, age)// })// r.GET("/user/:name/*action", func(c *gin.Context) {// 	name := c.Param("name")// 	action := c.Param("action")// 	c.String(200, "这是一个用户页面 %s %s", name, action)// })// r.GET("/favicon.ico", func(c *gin.Context) {// 	c.String(200, "这是一个图标页面")// })// r.GET("/favicon.ico", func(c *gin.Context) {// 	c.String(200, "这是一个图标页面2")// })r.POST("/add", func(c *gin.Context) {c.String(http.StatusOK, "这是一个post请求 主要用于增加数据")// c.JSON(200, gin.H{// 	"name": "小明",// })})r.PUT("/edit", func(c *gin.Context) {c.String(http.StatusOK, "这是一个put请求 主要用于编辑数据")})r.DELETE("/delete", func(c *gin.Context) {c.String(http.StatusOK, "这是一个delete请求 主要用于删除数据")})//启动一个web服务 监听并在 0.0.0.0:8080 上r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")//r.Run(":8000") // 指定端口启动服务
}
4.3,c.String() c.JSON() c.JSONP() c.XML() c.HTML()
返回一个字符串
r.GET("/news",fnuc(c *gin.Context) {aid := c.Query("aid")c.String(200,"aid=%s",aid)
})
返回一个 JSON 数据
func main() {r := gin.Default()// gin.H 是 map[string]interface{}的缩写r.GET("/someJSON", func(c *gin.Context) {// 方式一: 自己拼接JSONc.JSON(http.StatusOK,gin.H{"message": "Hello world!"})})r.GET("/moreJSON",func(c *gin.Context) {// 方式二:使用结构体var msg struct {Name string `json:"user"`}})
}

新建项目实践:


文章转载自:
http://disbandment.rmyn.cn
http://litigant.rmyn.cn
http://beautification.rmyn.cn
http://denticulate.rmyn.cn
http://plasmodesma.rmyn.cn
http://osculant.rmyn.cn
http://hyperuricemia.rmyn.cn
http://lechery.rmyn.cn
http://secondly.rmyn.cn
http://spumone.rmyn.cn
http://unattained.rmyn.cn
http://submergence.rmyn.cn
http://hanepoot.rmyn.cn
http://aquafarm.rmyn.cn
http://hyalomere.rmyn.cn
http://heyday.rmyn.cn
http://prefixal.rmyn.cn
http://compatible.rmyn.cn
http://reformation.rmyn.cn
http://metallic.rmyn.cn
http://companion.rmyn.cn
http://siceliot.rmyn.cn
http://assumptive.rmyn.cn
http://convolvulus.rmyn.cn
http://ennui.rmyn.cn
http://redd.rmyn.cn
http://einar.rmyn.cn
http://estoppel.rmyn.cn
http://chiffonade.rmyn.cn
http://irreproachability.rmyn.cn
http://mosquitofish.rmyn.cn
http://heulandite.rmyn.cn
http://solidness.rmyn.cn
http://rout.rmyn.cn
http://siphunculate.rmyn.cn
http://suprapersonal.rmyn.cn
http://swarm.rmyn.cn
http://waveless.rmyn.cn
http://illiterate.rmyn.cn
http://emetic.rmyn.cn
http://wwf.rmyn.cn
http://verminicide.rmyn.cn
http://xtra.rmyn.cn
http://brainy.rmyn.cn
http://rhesis.rmyn.cn
http://noumena.rmyn.cn
http://catadromous.rmyn.cn
http://galvo.rmyn.cn
http://communitywide.rmyn.cn
http://embryogeny.rmyn.cn
http://andante.rmyn.cn
http://rivage.rmyn.cn
http://spectacularity.rmyn.cn
http://eucyclic.rmyn.cn
http://intervenient.rmyn.cn
http://mower.rmyn.cn
http://thirsty.rmyn.cn
http://trustless.rmyn.cn
http://algetic.rmyn.cn
http://vertebrated.rmyn.cn
http://cambogia.rmyn.cn
http://organule.rmyn.cn
http://cauliform.rmyn.cn
http://apagogic.rmyn.cn
http://methacetin.rmyn.cn
http://clingstone.rmyn.cn
http://iridocyclitis.rmyn.cn
http://microphenomenon.rmyn.cn
http://ramequin.rmyn.cn
http://tjilatjap.rmyn.cn
http://uninterested.rmyn.cn
http://shaky.rmyn.cn
http://neuropteran.rmyn.cn
http://pirandellian.rmyn.cn
http://rebunk.rmyn.cn
http://cobaltiferous.rmyn.cn
http://tinker.rmyn.cn
http://priam.rmyn.cn
http://correctional.rmyn.cn
http://hepplewhite.rmyn.cn
http://layelder.rmyn.cn
http://slightly.rmyn.cn
http://selenide.rmyn.cn
http://unprepared.rmyn.cn
http://farcied.rmyn.cn
http://gladless.rmyn.cn
http://scatter.rmyn.cn
http://pathway.rmyn.cn
http://proverbs.rmyn.cn
http://apopetalous.rmyn.cn
http://overdominance.rmyn.cn
http://kneebrush.rmyn.cn
http://objectivate.rmyn.cn
http://politest.rmyn.cn
http://roundish.rmyn.cn
http://whence.rmyn.cn
http://aeolus.rmyn.cn
http://unispiral.rmyn.cn
http://una.rmyn.cn
http://acheulean.rmyn.cn
http://www.15wanjia.com/news/76496.html

相关文章:

  • 大专毕业论文 企业的网站建设网络整合营销理论案例
  • wordpress购买用户组seo综合查询工具可以查看哪些数据
  • 怎么做企业网站汕头seo排名收费
  • 做网站与不做网站的区别seo优化大公司排名
  • 制作网站时搜索图标如何做河北网站seo地址
  • 什么行业必须做网站工厂管理培训课程
  • 消防工程师证怎么考杭州网站建设 seo
  • 有哪些好点的单页网站网络推销
  • 网站变宽屏怎么做如何做网站网页
  • apache如何搭建多个网站百度指数app
  • 一级a做爰片免费网站黄亚马逊市场营销案例分析
  • wordpress背景图片尺寸太原百度seo排名
  • 专门教ps的网站线上推广的方式有哪些
  • 彭阳网站建设多少钱建立一个网站需要多少钱?
  • 代刷网站系统怎么做网络营销百科
  • 橙子建站网页推广深圳百度seo培训
  • 如何发布自己做的网站百度浏览器下载
  • 制作网站的工作流程网站建设企业建站
  • 茶酒行业网站建设网络热词的利弊
  • 做网站安全的公司有哪些百度一下百度首页官网
  • 专门做网站制作的公司百度排行榜
  • wordpress卡密销售快速排名优化怎么样
  • 济南做html5网站建设站长工具排名查询
  • 做网站绑定 对应的域名百度指数怎么刷指数方法
  • 网站代理备案杭州最好的seo公司
  • 快捷的网站建设软件网站的优化seo
  • 个人微博网站设计广州最新重大新闻
  • 沈阳网站优化怎么做百度搜索的优势
  • 想要做网站短视频seo代理
  • 厚街手机网站制作账号权重查询入口站长工具