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 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签)
  • ¥50 sft下载大文阻塞卡死
  • ¥15 机器人轨迹规划相关问题