FAQ
Hi,

If I have a group of global variables, like:
http://play.golang.org/p/xPcgNTzD_- , how can I initialize them inline
without having an extra function call. I know it could be done with init(),
but I'd rather say something like:

const/var config struct {
Str = "abc"
Num = 123
}

Is there a way I'm missing to specify the above?

Thanks,
Peter

PS: Basically what I'm trying to implement is a trivial global
configuration space to put all "hard coded" values so that I don't litter
my whole project with them and then try ang figure out where I put one
thing or another.

--
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/groups/opt_out.

Search Discussions

  • Jan Mercl at Mar 20, 2013 at 3:51 pm

    On Wed, Mar 20, 2013 at 4:48 PM, Péter Szilágyi wrote:
    If I have a group of global variables, like:
    http://play.golang.org/p/xPcgNTzD_- , how can I initialize them inline
    without having an extra function call. I know it could be done with init(),
    but I'd rather say something like:

    const/var config struct {
    Str = "abc"
    Num = 123
    }

    Is there a way I'm missing to specify the above?
    http://play.golang.org/p/TXbsveA9ZI

    -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/groups/opt_out.
  • Maxim Khitrov at Mar 20, 2013 at 3:54 pm

    On Wed, Mar 20, 2013 at 11:48 AM, Péter Szilágyi wrote:
    Hi,

    If I have a group of global variables, like:
    http://play.golang.org/p/xPcgNTzD_- , how can I initialize them inline
    without having an extra function call. I know it could be done with init(),
    but I'd rather say something like:

    const/var config struct {
    Str = "abc"
    Num = 123
    }

    Is there a way I'm missing to specify the above?
    Almost:

    http://play.golang.org/p/lWAgW5Hf-8

    - Max

    --
    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/groups/opt_out.
  • Péter Szilágyi at Mar 20, 2013 at 3:57 pm
    Ah, so *that's* where the = goes :))... thanks!

    On Wed, Mar 20, 2013 at 4:53 PM, Maxim Khitrov wrote:
    On Wed, Mar 20, 2013 at 11:48 AM, Péter Szilágyi wrote:
    Hi,

    If I have a group of global variables, like:
    http://play.golang.org/p/xPcgNTzD_- , how can I initialize them inline
    without having an extra function call. I know it could be done with init(),
    but I'd rather say something like:

    const/var config struct {
    Str = "abc"
    Num = 123
    }

    Is there a way I'm missing to specify the above?
    Almost:

    http://play.golang.org/p/lWAgW5Hf-8

    - Max
    --
    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/groups/opt_out.
  • Kevin Gillette at Mar 20, 2013 at 4:55 pm
    A hypothetical "inferred struct type" would seem useful in these areas
    (note: this code doesn't work)... http://play.golang.org/p/sapiYqaU5J
    On Wednesday, March 20, 2013 9:53:33 AM UTC-6, Maxim Khitrov wrote:
    On Wed, Mar 20, 2013 at 11:48 AM, Péter Szilágyi wrote:
    Hi,

    If I have a group of global variables, like:
    http://play.golang.org/p/xPcgNTzD_- , how can I initialize them inline
    without having an extra function call. I know it could be done with init(),
    but I'd rather say something like:

    const/var config struct {
    Str = "abc"
    Num = 123
    }

    Is there a way I'm missing to specify the above?
    Almost:

    http://play.golang.org/p/lWAgW5Hf-8

    - Max
    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 20, '13 at 3:48p
activeMar 20, '13 at 4:55p
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase