登录
首页 >  Golang >  Go问答

赃物开始首饰无畏,道路毫无痕迹

来源:stackoverflow

时间:2024-02-13 15:27:23 351浏览 收藏

本篇文章主要是结合我之前面试的各种经历和实战开发中遇到的问题解决经验整理的,希望这篇《赃物开始首饰无畏,道路毫无痕迹》对你有很大帮助!欢迎收藏,分享给更多的需要的朋友学习~

问题内容

我正在尝试使用 swag init 生成 swagger.json。这是我的代码:

package main

import (
    _ "album/docs"
    "context"
    "fmt"
    "net/http"
    "os"

    "github.com/gin-gonic/gin"
    "github.com/jackc/pgx/v5"

    swaggerfiles "github.com/swaggo/files"
    ginswagger "github.com/swaggo/gin-swagger"
)

// album represents data about a record album.

// @title          gin album service
// @version        1.0
// @description    a albums management service api in go using gin framework.
// @termsofservice https://example.dev

// @contact.name  santosh kumar
// @contact.url   https://twitter.com/example
// @contact.email [email protected]

// @license.name apache 2.0
// @license.url  http://www.apache.org/licenses/license-2.0.html

// @host     localhost:8080
// @basepath /
func main() {

}

// getalbums godoc
// @summary  retrieves user based on given id
// @produce  json
// @router   /albums/ [get]
func getalbums(c *gin.context) {
    
}

然后在

 swag init 
之后我有 swagger.json 文件:
{
    "swagger": "2.0",
    "info": {
        "description": "A albums management service API in Go using Gin framework.",
        "title": "Gin Album Service",
        "termsOfService": "https://example.dev",
        "contact": {
            "name": "Santosh Kumar",
            "url": "https://twitter.com/example",
            "email": "[email protected]"
        },
        "license": {
            "name": "Apache 2.0",
            "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
        },
        "version": "1.0"
    },
    "host": "localhost:8080",
    "basePath": "/",
    "paths": {}
}

为什么“路径”是空的?我的 getalbums 注释有什么问题?

看来我按照来源做了所有事情:https://github.com/swaggo/swag


正确答案


我找到了解决问题的方法。当我使用

 /usr/lib/go-1.18/src/album/swag init 
时创建了错误的 json 但当它是
 /usr/lib/go/src/album/swag init 

一切正常,json 正确。我不知道为什么会这样。 “go”只是“go-1.18”的链接

好了,本文到此结束,带大家了解了《赃物开始首饰无畏,道路毫无痕迹》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>