FAQ
Hi all,

I'm a new developer in Go. I am a grad student in computational science and
I'm working on creating a library for local search in Go. I know that if I
want to pass in a flag such as "race" to the compiler, i can run my Go
program with "go build -gcflags '-race' myprogram.go". But I am trying to
figure out how to pass in multiple flags. I looked at the compiler code and
couldn't find it. I'll search more, but i figure that someone here is
likely to know the quick answer.

The reason I am doing this is because I modified the compiler source code
so that I can disable errors from unused variables, which makes developing
much faster for me. I understand why unused variables are a bad idea, so I
only want this as a compiler option, therefore my need for passing in
flags. So for example, I'll run my program with "go build -gcflags
'-unused_vars_ok' myprogram.go", and it won't give me errors for unused
variables. However, I'd like to extend this so that I can also ignore
unused imported packages, but first i need to figure out how to pass in
multiple flags :)

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

  • Dan Kortschak at Mar 27, 2014 at 3:55 am
    Have you tried using goimports and Jan Merkl's technique of defining a
    use func in your tests suite so you can safely ignore non-use during
    testing?

    in foo_test.go:

    func use(_ ...interface{}) {}

    then in foo.go:

    func warble() {
      var bar, baz, shmoo int

      // vars I'm messing with right now:
      use(bar, baz, shmoo)

      // stuff I'm breaking.
    }

    This will allow bar, baz and shmoo to be unused during testing, but the
    package will fail to compile for a build - as it should.

    --
    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.
  • Dan Kortschak at Mar 27, 2014 at 4:15 am

    On Thu, 2014-03-27 at 14:25 +1030, Dan Kortschak wrote:
    Merkl
    s/Merkl/Mercl/

    Sorry, Jan.


    --
    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.
  • Minux at Mar 27, 2014 at 3:57 am

    On Mar 26, 2014 11:45 PM, wrote:
    Hi all,

    I'm a new developer in Go. I am a grad student in computational science
    and I'm working on creating a library for local search in Go. I know that
    if I want to pass in a flag such as "race" to the compiler, i can run my Go
    program with "go build -gcflags '-race' myprogram.go". But I am trying to
    figure out how to pass in multiple flags. I looked at the compiler code and
    couldn't find it. I'll search more, but i figure that someone here is
    likely to know the quick answer.
    -gcflags "-l -m"
    The reason I am doing this is because I modified the compiler source code
    so that I can disable errors from unused variables, which makes developing
    much faster for me. I understand why unused variables are a bad idea, so I
    only want this as a compiler option, therefore my need for passing in
    flags. So for example, I'll run my program with "go build -gcflags
    '-unused_vars_ok' myprogram.go", and it won't give me errors for unused
    variables. However, I'd like to extend this so that I can also ignore
    unused imported packages, but first i need to figure out how to pass in
    multiple flags :)
    this is highly discouraged. I'd go so far as to say that disable that
    feature means you're not using Go.

    --
    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.
  • Daniel Newman at Mar 27, 2014 at 4:18 am
    minux, I certainly understand your point of view and I definitely can see
    why this might no longer be considered "Go" since it goes against the
    language's specs (albeit with an option flag, not with the default, which I
    plan to use when finalizing my code). I'm very new to Go and I certainly am
    not at the point yet where I can make judgments about the various aspects
    of the language. But as an educational exercise, I am having fun and
    learning a lot by looking through and making changes to the compiler. I
    appreciate the responses to my question so far.

    As to my original question, if anyone knows how to pass in multiple flags,
    that would still be useful for me to know! Thanks!

    On Wed, Mar 26, 2014 at 11:57 PM, minux wrote:

    On Mar 26, 2014 11:45 PM, wrote:

    Hi all,

    I'm a new developer in Go. I am a grad student in computational science
    and I'm working on creating a library for local search in Go. I know that
    if I want to pass in a flag such as "race" to the compiler, i can run my Go
    program with "go build -gcflags '-race' myprogram.go". But I am trying to
    figure out how to pass in multiple flags. I looked at the compiler code and
    couldn't find it. I'll search more, but i figure that someone here is
    likely to know the quick answer.
    -gcflags "-l -m"
    The reason I am doing this is because I modified the compiler source
    code so that I can disable errors from unused variables, which makes
    developing much faster for me. I understand why unused variables are a bad
    idea, so I only want this as a compiler option, therefore my need for
    passing in flags. So for example, I'll run my program with "go build
    -gcflags '-unused_vars_ok' myprogram.go", and it won't give me errors for
    unused variables. However, I'd like to extend this so that I can also
    ignore unused imported packages, but first i need to figure out how to pass
    in multiple flags :)
    this is highly discouraged. I'd go so far as to say that disable that
    feature means you're not using Go.
    --
    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.
  • Dan Kortschak at Mar 27, 2014 at 4:21 am

    On Thu, 2014-03-27 at 00:18 -0400, Daniel Newman wrote:
    As to my original question, if anyone knows how to pass in multiple
    flags, that would still be useful for me to know! Thanks!
    minux answered that: e.g. -gcflags "-l -m" (space separated list of
    flags).

    --
    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.
  • Daniel Newman at Mar 27, 2014 at 4:23 am
    Didn't see... That's easy. Thank you!

    On Thu, Mar 27, 2014 at 12:21 AM, Dan Kortschak wrote:
    On Thu, 2014-03-27 at 00:18 -0400, Daniel Newman wrote:
    As to my original question, if anyone knows how to pass in multiple
    flags, that would still be useful for me to know! Thanks!
    minux answered that: e.g. -gcflags "-l -m" (space separated list of
    flags).
    --
    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
postedMar 27, '14 at 3:45a
activeMar 27, '14 at 4:23a
posts7
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase