Hello World

1>     Gin是一个golang的微框架,封装比较优雅,API友好。具有快速灵活,容错方便等特点。Gin自身的net/http足够简单,性能也非常不错。

2>     安装Gin环境.在命名行中输入如下的命名: go get github.com/gin-gonic/gin.

 Gin-Go学习笔记一:Hello World

 

3>     创建第一个Gin项目,新建一个GinOne.go文件。其代码如下:

 

package main

import (
    
"github.com/gin-gonic/gin"   
"net/http"

)



func main(){
    
    

   router := gin.Default()

    

   router.GET("/", func(c *gin.Context) {
        
      c.String(http.StatusOK, "Hello World")
   
   })
    
   router.Run(":8000")
 

}

  

4>     编译运行效果如下:

 Gin-Go学习笔记一:Hello World

 

在浏览器中输入如下的地址:localhost:8000,查看效果

 Gin-Go学习笔记一:Hello World

 

5>     下一章讲搭建Gin的web框架。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
  • 2021-12-14
  • 2021-07-22
  • 2022-12-23
  • 2021-10-15
  • 2022-01-11
猜你喜欢
  • 2021-04-22
  • 2021-10-22
  • 2021-04-17
  • 2021-08-28
  • 2021-07-05
  • 2021-11-25
  • 2021-12-04
相关资源
相似解决方案