猿问

Godooc不会读取我的代码,或者godoc无法读取anonymouse函数?

最近我试图记录我的代码,但我在使用时遇到了一些麻烦,因为当我运行时没有出现一些函数godocgodoc -http:localhost:6060


这是我的代码的样子:


type MongoDBInterface interface {

    ExecuteTransaction(operation func(mongoClient MongoDBInterface) error) error

    Count(tableName string, clause bson.M) (int, error)

    Distinct(tableName, fieldName string, clause bson.M) ([]interface{}, error)

    InsertOrUpdate(tableName string, clause bson.M, data models.BaseModelInterface) (primitive.ObjectID, error)

    InsertOrUpdateFields(tableName string, clause bson.M, data interface{}) (primitive.ObjectID, error)

    Insert(tableName string, data models.BaseModelInterface) (primitive.ObjectID, error)

    Update(tableName string, clause bson.M, data models.BaseModelInterface) error

    UpdateFields(tableName string, clause bson.M, data interface{}) error

    FindOne(tableName string, clause, opt bson.M, result interface{}) error

    FindMany(tableName string, clause, opt bson.M, result interface{}) error

    Truncate(tableName string) error

    Delete(tableName string, clause bson.M) error

    Aggregate(tableName string, pipelines interface{}, result interface{}) error

    EnsureCollections() error

}


type mongoDB struct {

    session              mongo.Session

    db                   *mongo.Database

    ctx                  context.Context

    isTransactionEnabled bool

    isConnected          bool


    connString string

}


// NewMongoDB definition

func NewMongoDB() MongoDBInterface {

    mongoClient := new(mongoDB)

    mongoClient.ctx = context.Background()


    dbHost := os.Getenv("DB_HOST")

    if dbHost == "" {

        dbHost = "localhost"

    }

    dbUser := os.Getenv("DB_USERNAME")

    if dbUser == "" {

        dbUser = "dbadmin"

    }


问题是永远不会渲染,但我需要它被记录下来,你们能向我解释一下发生了什么吗?或者,也许您可以给我一些记录Go代码的解决方案和提示。godocfunc (s *mongoDB) 


慕标琳琳
浏览 91回答 1
1回答

杨__羊羊

您可以参考此文档:https://pkg.go.dev/golang.org/x/tools/cmd/godocThe presentation mode of web pages served by godoc can be controlled with the "m" URL parameter; it accepts a comma-separated list of flag names as value:- all   show documentation for all declarations, not just the exported ones- methods   show all embedded methods, not just those of unexported anonymous fields- src   show the original source code rather than the extracted documentation- flat  present flat (not indented) directory listings using full pathsFor instance, https://golang.org/pkg/math/big/?m=all shows the documentation for all (not just the exported) declarations of package big. ?m=all文件所有申报,包括非出口方式
随时随地看视频慕课网APP

相关分类

Go
我要回答