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

个人域名怎么做社交网站嘉兴seo排名外包

个人域名怎么做社交网站,嘉兴seo排名外包,dedecms做网站,建设银行网站查询企业年金【狂神说】Gin框架一小时上手 | 快速转型GoWeb开发 | Go语言零基础教程_哔哩哔哩_bilibili 1.介绍 2.简单程序 1)gin.GET/POST/PUT/DELETE函数 Go Gin 简明教程 | 快速入门 | 极客兔兔 (geektutu.com) 我的理解是:这类函数就像是在监听接口一样&…

【狂神说】Gin框架一小时上手 | 快速转型GoWeb开发 | Go语言零基础教程_哔哩哔哩_bilibili

1.介绍

2.简单程序

1)gin.GET/POST/PUT/DELETE函数

Go Gin 简明教程 | 快速入门 | 极客兔兔 (geektutu.com)

我的理解是:这类函数就像是在监听接口一样,执行后一直在等待,没有捕捉到对应参数就没任何影响,捕捉到了就调用其对应的执行函数。

2)gin.Context

代表上下文信息,是一个结构体,一般用来处理Http请求和响应

Gin源码分析系列之Context篇 - 知乎 (zhihu.com)

20210814学习牛逼的gin.Context - 知乎 (zhihu.com)

3)context.JSON

给前端响应一个JSON信息

4)ginServer.Use(favicon.New("./day.ico")) 

给页面标签加一个ico

5)restful api

6)http状态码

const (StatusContinue           = 100 // RFC 9110, 15.2.1StatusSwitchingProtocols = 101 // RFC 9110, 15.2.2StatusProcessing         = 102 // RFC 2518, 10.1StatusEarlyHints         = 103 // RFC 8297StatusOK                   = 200 // RFC 9110, 15.3.1StatusCreated              = 201 // RFC 9110, 15.3.2StatusAccepted             = 202 // RFC 9110, 15.3.3StatusNonAuthoritativeInfo = 203 // RFC 9110, 15.3.4StatusNoContent            = 204 // RFC 9110, 15.3.5StatusResetContent         = 205 // RFC 9110, 15.3.6StatusPartialContent       = 206 // RFC 9110, 15.3.7StatusMultiStatus          = 207 // RFC 4918, 11.1StatusAlreadyReported      = 208 // RFC 5842, 7.1StatusIMUsed               = 226 // RFC 3229, 10.4.1StatusMultipleChoices   = 300 // RFC 9110, 15.4.1StatusMovedPermanently  = 301 // RFC 9110, 15.4.2StatusFound             = 302 // RFC 9110, 15.4.3StatusSeeOther          = 303 // RFC 9110, 15.4.4StatusNotModified       = 304 // RFC 9110, 15.4.5StatusUseProxy          = 305 // RFC 9110, 15.4.6_                       = 306 // RFC 9110, 15.4.7 (Unused)StatusTemporaryRedirect = 307 // RFC 9110, 15.4.8StatusPermanentRedirect = 308 // RFC 9110, 15.4.9StatusBadRequest                   = 400 // RFC 9110, 15.5.1StatusUnauthorized                 = 401 // RFC 9110, 15.5.2StatusPaymentRequired              = 402 // RFC 9110, 15.5.3StatusForbidden                    = 403 // RFC 9110, 15.5.4StatusNotFound                     = 404 // RFC 9110, 15.5.5StatusMethodNotAllowed             = 405 // RFC 9110, 15.5.6StatusNotAcceptable                = 406 // RFC 9110, 15.5.7StatusProxyAuthRequired            = 407 // RFC 9110, 15.5.8StatusRequestTimeout               = 408 // RFC 9110, 15.5.9StatusConflict                     = 409 // RFC 9110, 15.5.10StatusGone                         = 410 // RFC 9110, 15.5.11StatusLengthRequired               = 411 // RFC 9110, 15.5.12StatusPreconditionFailed           = 412 // RFC 9110, 15.5.13StatusRequestEntityTooLarge        = 413 // RFC 9110, 15.5.14StatusRequestURITooLong            = 414 // RFC 9110, 15.5.15StatusUnsupportedMediaType         = 415 // RFC 9110, 15.5.16StatusRequestedRangeNotSatisfiable = 416 // RFC 9110, 15.5.17StatusExpectationFailed            = 417 // RFC 9110, 15.5.18StatusTeapot                       = 418 // RFC 9110, 15.5.19 (Unused)StatusMisdirectedRequest           = 421 // RFC 9110, 15.5.20StatusUnprocessableEntity          = 422 // RFC 9110, 15.5.21StatusLocked                       = 423 // RFC 4918, 11.3StatusFailedDependency             = 424 // RFC 4918, 11.4StatusTooEarly                     = 425 // RFC 8470, 5.2.StatusUpgradeRequired              = 426 // RFC 9110, 15.5.22StatusPreconditionRequired         = 428 // RFC 6585, 3StatusTooManyRequests              = 429 // RFC 6585, 4StatusRequestHeaderFieldsTooLarge  = 431 // RFC 6585, 5StatusUnavailableForLegalReasons   = 451 // RFC 7725, 3StatusInternalServerError           = 500 // RFC 9110, 15.6.1StatusNotImplemented                = 501 // RFC 9110, 15.6.2StatusBadGateway                    = 502 // RFC 9110, 15.6.3StatusServiceUnavailable            = 503 // RFC 9110, 15.6.4StatusGatewayTimeout                = 504 // RFC 9110, 15.6.5StatusHTTPVersionNotSupported       = 505 // RFC 9110, 15.6.6StatusVariantAlsoNegotiates         = 506 // RFC 2295, 8.1StatusInsufficientStorage           = 507 // RFC 4918, 11.5StatusLoopDetected                  = 508 // RFC 5842, 7.2StatusNotExtended                   = 510 // RFC 2774, 7StatusNetworkAuthenticationRequired = 511 // RFC 6585, 6
)

3.给前端响应

发送请求和响应

给前端发送json和页面(静态资源)

package mainimport ("net/http""github.com/gin-gonic/gin""github.com/thinkerou/favicon"
)func main() {//·1.创建一个服务ginServer := gin.Default()ginServer.Use(favicon.New("./day.ico")) //加网站小icon//连接数据库之类,之后可以作为一个接口就可以给前端返回数据// //2.访问地址,处理我们的请求Request Response// //发送一个GET请求,如果url有hello,会执行后面的函数给前端返回信息// ginServer.GET("/hello", func(context *gin.Context) {// 	context.JSON(200, gin.H{"msg": "helloworld"})// })// ginServer.POST("/user", func(c *gin.Context) {// 	//返回json数据,状态码200就是http.StatusOK// 	c.JSON(200, gin.H{"msg": "post,user"})// })// ginServer.PUT("/user")// ginServer.DELETE("/user")//3.响应页面给前端//加载静态页面ginServer.LoadHTMLGlob("templates/*")//ginServer.LoadHTMLFiles("templates/index.html") //加载单个//4.加载资源文件(资源文件位置,根目录位置)ginServer.Static("/static", "./static")ginServer.GET("/index", func(c *gin.Context) {//返回页面c.HTML(http.StatusOK, "index.html", gin.H{"msg": "这是go后台传递来的数据...",})})//服务器端口,给一个服务端口,默认8080ginServer.Run(":8080") //一定有个冒号
}

4.获取请求中的参数

1)前端表单

package mainimport ("encoding/json""net/http""github.com/gin-gonic/gin""github.com/thinkerou/favicon"
)/*
固定格式:请求,处理请求函数
ginServer.POST("/user", func(c *gin.Context) {
})
*/
func main() {//·1.创建一个服务ginServer := gin.Default()ginServer.Use(favicon.New("./day.ico")) //加网站小icon//连接数据库之类,之后可以作为一个接口就可以给前端返回数据//3.响应页面给前端//加载静态页面ginServer.LoadHTMLGlob("templates/*")//ginServer.LoadHTMLFiles("templates/index.html") //加载单个//4.加载资源文件(资源文件位置,根目录位置)ginServer.Static("/static", "./static")ginServer.GET("/index", func(c *gin.Context) {//返回页面c.HTML(http.StatusOK, "index.html", gin.H{"msg": "这是go后台传递来的数据...",})})//7.获取前端表单数据ginServer.POST("/user/add", func(c *gin.Context) {//拿到数据username := c.PostForm("username")password := c.PostForm("password")//数据校验// if username == {// }//给前端返回数据c.JSON(http.StatusOK, gin.H{"msg":      "Ok","password": password,"username": username,})})//服务器端口,给一个服务端口,默认8080ginServer.Run(":8080") //一定有个冒号
}

 2)前端给后端传json

package mainimport ("encoding/json""net/http""github.com/gin-gonic/gin""github.com/thinkerou/favicon"
)/*
固定格式:请求,处理请求函数
ginServer.POST("/user", func(c *gin.Context) {
})
*/
func main() {//·1.创建一个服务ginServer := gin.Default()ginServer.Use(favicon.New("./day.ico")) //加网站小icon//前端给后端传jsonginServer.POST("/json", func(c *gin.Context) {//request.bodydata, _ := c.GetRawData()  //从请求体获取数据var m map[string]interface{}_ = json.Unmarshal(data, &m) //解析后端接收的json//给前端发送回去c.JSON(http.StatusOK,m)})//服务器端口,给一个服务端口,默认8080ginServer.Run(":8080") //一定有个冒号
}

3)?&传参

package mainimport ("net/http""github.com/gin-gonic/gin""github.com/thinkerou/favicon"
)/*
固定格式:请求,处理请求函数
ginServer.POST("/user", func(c *gin.Context) {
})
*/
func main() {//·1.创建一个服务ginServer := gin.Default()ginServer.Use(favicon.New("./day.ico")) //加网站小icon//?传参// url输入 /user/info?userid=xxx&username=kuangshenginServer.GET("/user/info", func(c *gin.Context) {userid := c.Query("userid") //接收前端问号传参的值username := c.Query("username")//返回json数据,状态码200就是http.StatusOKc.JSON(http.StatusOK, gin.H{"userid":   userid,"username": username,})})//服务器端口,给一个服务端口,默认8080ginServer.Run(":8080") //一定有个冒号
}

4)RESTful风格传参

package mainimport ("net/http""github.com/gin-gonic/gin""github.com/thinkerou/favicon"
)/*
固定格式:请求,处理请求函数
ginServer.POST("/user", func(c *gin.Context) {
})
*/
func main() {//·1.创建一个服务ginServer := gin.Default()ginServer.Use(favicon.New("./day.ico")) //加网站小icon//RESTful风格传参,冒号后自动接收参数//url输入 /user/info/1/ kuangshenginServer.GET("/user/info/:userid/:username", func(c *gin.Context) {userid := c.Param("userid")username := c.Param("username")//返回json数据,状态码200就是http.StatusOKc.JSON(http.StatusOK, gin.H{"userid":   userid,"username": username,})})//服务器端口,给一个服务端口,默认8080ginServer.Run(":8080") //一定有个冒号
}

5.路由,重定向

1)普通路由

该案例自动跳转必应

// 路由
func route(ginServer *gin.Engine) {ginServer.GET("test", func(context *gin.Context) {//重定向状态301context.Redirect(http.StatusMovedPermanently, "https://www.bing.com")})
}

2).404

只要输入的访问路径不被已知的请求处理,那么就是404状态,会被该请求捕获并跳转到404.

404页面需要提前加载一下静态资源

// 404页面
func noRoute(ginServer *gin.Engine) {ginServer.NoRoute(func(context *gin.Context) {context.HTML(http.StatusNotFound, "404.html", nil) //会从指定的静态资源路径下去找})

3)路由组

对一个路径下的不同分路径请求进行处理

// 路由组,相当于对一个路径下不同分路径一起做处理
func routeGroup(ginServer *gin.Engine) {userGroup := ginServer.Group("/user"){userGroup.GET("/add")userGroup.GET("/login")userGroup.GET("/logout")}orderGroup := ginServer.Group("/order"){orderGroup.GET("/add")orderGroup.GET("/delete")}}

6.拦截器

1)自定义中间件

流程:定义,注册,指定(可有可无)

注册中间件之后默认给所有请求使用,如果在某个请求里指定了,就只给这一个请求使用。

package mainimport ("encoding/json""log""net/http""github.com/gin-gonic/gin""github.com/thinkerou/favicon"
)// 自定义go中间件拦截器
func myHandler() gin.HandlerFunc {return func(context *gin.Context) {//自定义中间件设置的值,在后续处理只要调用了这个中间件的都可以拿到这里的参数context.Set("usersession", "userid-1")if true { //放行context.Next()} else { //阻止context.Abort()}}
}// 使用自定义中间件
func handler(ginServer *gin.Engine) {//这样请求被方法接收之前会先被中间件拦截处理,如果通过,才会被方法接收处理//?传参// url输入 /user/info2?userid=xxx&username=kuangshenginServer.GET("/user/info2",myHandler(), func(c *gin.Context) {//取出中间件的值usersession := c.MustGet("usersession").(string)log.Println(usersession)    //后台打印userid := c.Query("userid") //接收前端问号传参的值username := c.Query("username")c.JSON(http.StatusOK, gin.H{"userid":   userid,"username": username,})})
}func main() {//·1.创建一个服务ginServer := gin.Default()//注册中间件ginServer.Use(myHandler())ginServer.Use(favicon.New("./day.ico")) //加网站小icon//连接数据库之类,之后可以作为一个接口就可以给前端返回数据//使用自定义中间件handler(ginServer)//服务器端口,给一个服务端口,默认8080ginServer.Run(":8080") //一定有个冒号
}

http://www.wangmingla.cn/news/710.html

相关文章:

  • 去哪个网站可以做写手百度学术论文查重
  • 容桂均安网站建设天津百度网络推广
  • 做网站公众号要多少钱今日时事新闻
  • 中国建设工程信息网官网清欠成都网站排名优化公司
  • 企业内部系统网站制作班级优化大师免费下载
  • 网站建设市场介绍湖南省人民政府官网
  • 企业网站设计与实现seo推广平台
  • 商业网站排名网络推广公司方案
  • 河南高端网站建设开网店如何运营和推广
  • wordpress esc html网站优化公司收费
  • 网站开发分层seo怎么优化关键词排名
  • 网站创建风格上海怎么做seo推广
  • 网站设计制作都有哪些百度知道免费提问
  • 遵义公司网站制作哪家好近两年成功的网络营销案例及分析
  • 营养早餐网站的设计与制作公司建网站多少钱
  • 网站建设合同搜索引擎优化简历
  • wordpress多站点必备插件网站有吗免费的
  • 做外贸批发有哪些网站有哪些做高端网站公司
  • 微信网站开发推广seo优化公司
  • 西安seo外包服务上海整站seo
  • wordpress网站防伪查询模板市场营销的八个理论
  • 网站建设公司做销售前景好不好?丈哥seo博客
  • 武汉百度做网站seo岗位是什么意思
  • 合肥手机网站建设营销策略怎么写范文
  • 我要学习做网站上海站优云网络科技有限公司
  • 网站被降权表现营销策略分析论文
  • 南通医院网站建设方案网络营销做得好的公司
  • 长沙网站设网络营销企业培训
  • 公司有域名 如何做网站app软件开发
  • 网站建设视频教程网站手机百度安装下载