初入门

命令总结

# 创建项目文件夹
mkdir transaction-link

# 创建go.mod
go mod init word-dect-go

# 引入gin框架
go get -u github.com/gin-gonic/gin

# 引入日志框架 - 暂时不确定是不是好用
go get -u github.com/cihub/seelog

创建启动文件

package main

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

// 参考:https://blog.csdn.net/wanderstarrysky/article/details/113752721

func main() {
    // 1.创建路由
    r := gin.Default()
    // 2.绑定路由规则,执行的函数
    // gin.Context,封装了request和response
    r.GET("/", func(c *gin.Context) {
        c.String(http.StatusOK, "hello World!")
    })
    // 3.监听端口,默认在8080
    // Run("里面不指定端口号默认为8088")
    r.Run(":8088")
}

注意:

package必须为main,否则会报错

posted @ 2021-07-31 22:44  杏仁拌饭  阅读(39)  评论(0)    收藏  举报