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?

  • 写回答

1条回答 默认 最新

  • dtl85148 2018-07-31 12:02
    关注

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

    But in go 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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题