使用 go-module 包管理器

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

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

$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


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

查看所有标签

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

Looking For a Challenge

Looking For a Challenge

the University of Warsaw / the University of Warsaw / 2012-11 / 0

LOOKING FOR PROGRAMMING CHALLENGES? Then this book is for you! Whether it's the feeling of great satisfaction from solving a complex problem set, or the frustration of being unable to solve a task,......一起来看看 《Looking For a Challenge》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

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

正则表达式在线测试