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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?