Gin-Go学习笔记一:Hello World

Hello World

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

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

 

 

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>     编译运行效果如下:

 

 

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

 

 

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

posted @ 2017-12-18 09:46  夜未央天未明  阅读(4491)  评论(2编辑  收藏  举报