dqmnueuu459279
2018-07-31 11:52
浏览 43
已采纳

如何在Golang中窥视导入的软件包

Programming languages such as Javascript allow you to peek through a library/package by just passing the package into console.log(). I tried doing the same in Go, but that did not work.

package main

import "fmt"
import "os"


func main() {
    fmt.Print(os)
}

Is this not the right approach?

图片转代码服务由CSDN问答提供 功能建议

像Javascript这样的编程语言使您可以通过将包传递到 console来浏览库/包。 .LOG()。 我尝试在Go中执行相同的操作,但这没用。

 包main 
 
import“ fmt” 
import“ os” 
 
 
func main(  ){
 fmt.Print(os)
} 
   
 
 

这不是正确的方法吗?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtl85148 2018-07-31 12:02
    已采纳

    In when you use something like const assert = require('assert'); you are importing object which was exported from assert script.

    But in import it's something like namespace which you're going to use in your package. And that's why you just can't do what you wish, because namespace it is not object instance.

    You can create object instance from os package and inspect it like in your example with console.log(), it should looks like:

    package main
    
    import (
        "fmt"
        "os"
    )
    
    func main() {
        ps := os.ProcessState{}
        fmt.Printf("%+v", ps)
    }
    

    With purpose to inspect whole os package you can check https://golang.org/pkg/os/, here you can find all info about go packages (functions, structures, methods, constants, etc).

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题