go从入门到放弃gin从入门到放弃

环境配置

2019-10-15  本文已影响0人  寒云暮雨

环境配置
go下载地址有需要的童鞋请自行下载
执行一下命令建立新项目,生成go.mod文件

go mod init learnGo

修改go.mod增加依赖包

module learnGo

go 1.13

replace (
    cloud.google.com/go => github.com/googleapis/google-cloud-go v0.39.1-0.20190528154449-61166ef30553

    golang.org/x/crypto => github.com/golang/crypto v0.0.0-20190313024323-a1f597ede03a

    golang.org/x/exp => github.com/golang/exp v0.0.0-20190510132918-efd6b22b2522

    golang.org/x/lint => github.com/golang/lint v0.0.0-20190409202823-959b441ac422

    golang.org/x/net => github.com/golang/net v0.0.0-20190318221613-d196dffd7c2b

    golang.org/x/oauth2 => github.com/golang/oauth2 v0.0.0-20190523182746-aaccbc9213b0

    golang.org/x/sync => github.com/golang/sync v0.0.0-20190227155943-e225da77a7e6

    golang.org/x/sys => github.com/golang/sys v0.0.0-20190318195719-6c81ef8f67ca

    golang.org/x/text => github.com/golang/text v0.3.0

    golang.org/x/time => github.com/golang/time v0.0.0-20190308202827-9d24e82272b4

    golang.org/x/tools => github.com/golang/tools v0.0.0-20190529010454-aa71c3f32488

    google.golang.org/appengine => github.com/golang/appengine v1.6.1-0.20190515044707-311d3c5cf937

    google.golang.org/genproto => github.com/google/go-genproto v0.0.0-20190522204451-c2c4e71fbf69

    google.golang.org/grpc => github.com/grpc/grpc-go v1.21.0
)

require (
    github.com/dgrijalva/jwt-go v3.2.0+incompatible
    github.com/gin-gonic/gin v1.4.0
    github.com/go-playground/locales v0.12.1 // indirect
    github.com/go-playground/universal-translator v0.16.0 // indirect
    github.com/go-sql-driver/mysql v1.4.1
    github.com/jinzhu/gorm v1.9.11
    github.com/kr/pretty v0.1.0 // indirect
    github.com/leodido/go-urn v1.1.0 // indirect
    gopkg.in/go-playground/validator.v9 v9.30.0
)


PS 不懂科学上网的同学可以把需要的依赖加到 replace()里面。require 里面引入你需要的依赖库

require (
    github.com/dgrijalva/jwt-go v3.2.0+incompatible
    github.com/gin-gonic/gin v1.4.0
    github.com/go-playground/locales v0.12.1 // indirect
    github.com/go-playground/universal-translator v0.16.0 // indirect
    github.com/go-sql-driver/mysql v1.4.1
    github.com/jinzhu/gorm v1.9.11
    github.com/kr/pretty v0.1.0 // indirect
    github.com/leodido/go-urn v1.1.0 // indirect
    gopkg.in/go-playground/validator.v9 v9.30.0
)

下载依赖文件

go mod  download

执行命令将依赖的文件拷贝到项目相面

go mod  vendor

新建main.go

/*
@Author :   寒云
@Email  :   1355081829@qq.com
@Time : 2019/10/15 11:51
*/
package main

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

func main() {
    router := gin.Default()
    router.GET("/", func(c *gin.Context) {
        c.JSON(200, gin.H{
            "message": "ping",
        })
    })

    _ = router.Run(":8089")
}

最终项目结构如下


image.png

执行命令,启动服务

go run main.go

访问http://127.0.0.1:8089/,输出{"message":"ping"}说明我们的gin框架成功运行起来

上一篇下一篇

猜你喜欢

热点阅读