如何在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?

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).