账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Godoc 无法在浏览器中"像浏览官方包一样" 浏览自定义包
    72
    0

    目的 & 重新步骤 & 错误内容

    通过godoc命令来在浏览器中浏览自己编写的包,浏览效果和官方提供的包一样;通过查找资料得出以下操作步骤
    1 cd /Users/xxx/Desktop/redis-go/src/hosts 切换到自定义包
    2 godoc -goroot=. 开启godoc服务
    2019/08/06 16:22:34 updateMetadata: open doc: no such file or directory

    3 浏览器中输入 http://localhost:6060/pkg/hosts/ 显示的是:cannot find package "." in: /src/hosts
    4 浏览器中输入 http://localhost:6060 显示的内容是: 自定包的目录

    环境说明

    IDE:VSCode Version:1.36.1
    
    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/Users/xxx/Library/Caches/go-build"
    GOEXE=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOOS="darwin"
    `GOPATH="/Users/xxx/go:/Users/xxx/Desktop/GTR"`
    GOPROXY=""
    GORACE=""
    `GOROOT="/usr/local/Cellar/go/1.12.3/libexec"`
    GOTMPDIR=""
    GOTOOLDIR="/usr/local/Cellar/go/1.12.3/libexec/pkg/tool/darwin_amd64"
    GCCGO="gccgo"
    CC="clang"
    CXX="clang++"
    CGO_ENABLED="1"
    `GOMOD="/Users/xxx/Desktop/redis-go/src/go.mod"`
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    PKG_CONFIG="pkg-config"
    GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/rj/pf1q28gj4t38brccjq037ksc0000gn/T/go-build859309463=/tmp/go-build -gno-record-gcc-switches -fno-common"
    

    代码组织

    ---src
       ---hosts
          --- host.go
          --- doc.go
       ---main
          --- main.go
       --- go.mod
       --- go.sum
      
    1. src目录,go.mod,go.sum 在同一级
    2. hosts是自定义包

    期待答案

    • 给出思路与参考内容
    • 自己的使用经验

    各个文件代码

    • host.go
    package hosts
    
    import (
        "fmt"
    )
    
    //SayHello printf Hell0
    func SayHello(){
        fmt.Println("Hello!")
    }
    

    doc.go

    /*
    Package hosts implements custom printf method.
    */
    package hosts // import "stephanie.io/hosts"

    如发现问题描述语句不通顺,用词不当,问题不清楚等问题,你可以直接修改,或者在下面评论区说明,尽力使这个问题帮助更多的小伙伴 ゝ

    关于godoc使用的内容

    Your own code can present good documentation just by having comments as described above. Any Go packages installed inside $GOROOT/src/pkg and any GOPATH work spaces will already be accessible via godoc's command-line and HTTP interfaces, and you can specify additional paths for indexing via the -path flag or just by running "godoc ." in the source directory. See the godoc documentation for more details.

    reference:

    https://blog.golang.org/godoc-documenting-go-code

    3
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 一只只蛛 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部