使用 go-module 包管理器

栏目: Go · 发布时间: 6年前

内容简介:在解决网络问题:安装各种包:

$GOPATH 目录下新建一个项目目录(eg. gin_start ), 并在此项目根目录下初始化 mod :

go mod init gin_start

解决网络问题: export GOPROXY=https://goproxy.io (windows 使用 set )

安装各种包:

go get -v -u github.com/gin-gonic/gin

新建 main.go 写自己的代码:

package main

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

func main() {
    fmt.Printf("Start servering")
    r := gin.Default()
    r.GET("/hello", func(c *gin.Context) {
        c.JSON(200, gin.H{
            "success": true,
            "code": 200,
            "message": "Hello World",
            "data": nil,
        })
    })
    r.Run(":8000")
}

启动服务: go run main.go
访问: http://localhost:8000/hello

使用 go-module 包管理器

image.png


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Open Data Structures

Open Data Structures

Pat Morin / AU Press / 2013-6 / USD 29.66

Offered as an introduction to the field of data structures and algorithms, Open Data Structures covers the implementation and analysis of data structures for sequences (lists), queues, priority queues......一起来看看 《Open Data Structures》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试