golang+ginswagger

本文档介绍了如何使用Golang和Gin-Swagger搭建RESTful API。首先通过`go mod init`创建项目,然后利用`go mod vendor`下载依赖。在`main.go`中设置Swagger元数据并引入必要包。定义了名为`Print`的HTTP GET路由,然后使用`swag init`命令生成相关Swagger文件。最后运行服务器监听8001端口。
摘要由CSDN通过智能技术生成

1. step 1  related command(download swagger, then use related command)

go mod init xxx(this name you can give any name, up to you)------ generate go.mod automatically

Go build main.go (update go.mod file and create go.sum file automatically)

When you import a new package, you need to use command "go mod vendor" to download

 

2. step 2  main.go code

package main

import (

    

    // "github.com/swaggo/swag/example/celler/controller"

    // _ "github.com/swaggo/swag/example/celler/docs"

    _ "xxx/docs"

 

    "github.com/gin-gonic/gin"

    swaggerFiles "github.com/swaggo/files"

    ginSwagger "github.com/swaggo/gin-swagger"

    "fmt"

    "net/http"<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值