FAQ
Hi. Does it possible to get list of standard go packages inside
another (external package) ?

--
Vasiliy Tolstov,
e-mail: v.tolstov@selfip.ru
jabber: vase@selfip.ru

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Tomwilde at Jul 17, 2014 at 3:13 pm

    On Thursday, July 17, 2014 1:23:31 PM UTC+2, Vasiliy Tolstov wrote:
    get list of standard go packages inside
    another (external package) ?
    Please explain your question a little bit further. Do you want to build a
    list of strings with package import-paths in it?

    []string {
         "os",
         "io",
         "net",
         "net/http",
         // etc...
    }

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Vasiliy Tolstov at Jul 17, 2014 at 3:38 pm

    2014-07-17 19:13 GMT+04:00 tomwilde <sedevelopers01@gmail.com>:
    Please explain your question a little bit further. Do you want to build a
    list of strings with package import-paths in it?

    []string {
    "os",
    "io",
    "net",
    "net/http",
    // etc...
    }

    I need to get all std packages like go list std displays, but inside
    in my go file.

    --
    Vasiliy Tolstov,
    e-mail: v.tolstov@selfip.ru
    jabber: vase@selfip.ru

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jan Mercl at Jul 17, 2014 at 3:54 pm

    On Thu, Jul 17, 2014 at 5:38 PM, Vasiliy Tolstov wrote:
    2014-07-17 19:13 GMT+04:00 tomwilde <sedevelopers01@gmail.com>:
    Please explain your question a little bit further. Do you want to build a
    list of strings with package import-paths in it?

    []string {
    "os",
    "io",
    "net",
    "net/http",
    // etc...
    }

    I need to get all std packages like go list std displays, but inside
    in my go file.
    I'm not sure I understand the question correctly, but maybe you're
    looking for something like this example (as a starting point only)

    (17:49) jnml@r550:~/src/github.com/cznic/ql$ go list -f '{{range
    .Imports}}{{. | printf "%s\n"}}{{end}}' | grep -v \\.com
    bytes
    crypto/sha1
    database/sql
    database/sql/driver
    encoding/gob
    errors
    fmt
    go/ast
    io
    io/ioutil
    log
    math
    math/big
    math/rand
    net/http
    os
    path
    path/filepath
    reflect
    runtime
    strconv
    strings
    sync
    time
    unicode
    (17:49) jnml@r550:~/src/github.com/cznic/ql$

    -j

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Adonovan at Jul 17, 2014 at 5:02 pm

    On Thursday, 17 July 2014 11:54:26 UTC-4, Jan Mercl wrote:
    On Thu, Jul 17, 2014 at 5:38 PM, Vasiliy Tolstov <v.to...@selfip.ru
    <javascript:>> wrote:
    2014-07-17 19:13 GMT+04:00 tomwilde <sedevel...@gmail.com <javascript:>>:
    Please explain your question a little bit further. Do you want to build
    a
    list of strings with package import-paths in it?

    []string {
    "os",
    "io",
    "net",
    "net/http",
    // etc...
    }

    I need to get all std packages like go list std displays, but inside
    in my go file.
    I'm not sure I understand the question correctly, but maybe you're
    looking for something like this example (as a starting point only)

    (17:49) jnml@r550:~/src/github.com/cznic/ql$ go list -f '{{range
    .Imports}}{{. | printf "%s\n"}}{{end}}' | grep -v \\.com
    bytes
    crypto/sha1
    database/sql
    database/sql/driver
    encoding/gob
    errors
    fmt
    go/ast
    io
    io/ioutil
    log
    math
    math/big
    math/rand
    net/http
    os
    path
    path/filepath
    reflect
    runtime
    strconv
    strings
    sync
    time
    unicode
    (17:49) jnml@r550:~/src/github.com/cznic/ql$

    -j

    Also, take a look at the allPackages function, variants of which appear in
    several tests in the go.tools repository.

    func allPackages() []string {
    var pkgs []string
    root := filepath.Join(runtime.GOROOT(), "src/pkg") +
    string(os.PathSeparator)
    filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
    // Prune the search if we encounter any of these names:
    switch filepath.Base(path) {
    case "testdata", ".hg":
    return filepath.SkipDir
    }
    if info.IsDir() {
    pkg := filepath.ToSlash(strings.TrimPrefix(path, root))
    switch pkg {
    case "builtin", "pkg":
    return filepath.SkipDir // skip these subtrees
    case "":
    return nil // ignore root of tree
    }
    pkgs = append(pkgs, pkg)
    }

    return nil
    })
    return pkgs
    }


    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Vasiliy Tolstov at Jul 18, 2014 at 12:09 pm

    2014-07-17 21:01 GMT+04:00 <adonovan@google.com>:
    Also, take a look at the allPackages function, variants of which appear in
    several tests in the go.tools repository.

    func allPackages() []string {
    var pkgs []string
    root := filepath.Join(runtime.GOROOT(), "src/pkg") +
    string(os.PathSeparator)
    filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
    // Prune the search if we encounter any of these names:
    switch filepath.Base(path) {
    case "testdata", ".hg":
    return filepath.SkipDir
    }
    if info.IsDir() {
    pkg := filepath.ToSlash(strings.TrimPrefix(path, root))
    switch pkg {
    case "builtin", "pkg":
    return filepath.SkipDir // skip these subtrees
    case "":
    return nil // ignore root of tree
    }
    pkgs = append(pkgs, pkg)
    }

    return nil
    })
    return pkgs
    }

    Thanks! Exactly this is need.

    --
    Vasiliy Tolstov,
    e-mail: v.tolstov@selfip.ru
    jabber: vase@selfip.ru

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Vasiliy Tolstov at Jul 18, 2014 at 12:08 pm
    2014-07-17 19:53 GMT+04:00 Jan Mercl (17:49) jnml@r550:~/src/github.com/cznic/ql$ go list -f '{{range
    .Imports}}{{. | printf "%s\n"}}{{end}}' | grep -v \\.com
    bytes
    crypto/sha1
    database/sql
    database/sql/driver
    encoding/gob
    errors
    fmt
    go/ast
    io
    io/ioutil
    log
    math
    math/big
    math/rand
    net/http
    os
    path
    path/filepath
    reflect
    runtime
    strconv
    strings
    sync
    time
    unicode
    (17:49) jnml@r550:~/src/github.com/cznic/ql$

    Yes

    --
    Vasiliy Tolstov,
    e-mail: v.tolstov@selfip.ru
    jabber: vase@selfip.ru

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 17, '14 at 11:23a
activeJul 18, '14 at 12:09p
posts7
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase