I want to declare a few variables constant. But I guess there is nothing as "Constant" type in GoLang. How do I achieve this in GoLang?
import "fmt"
const (
ExposedConstant = "1" // exposed outside of package
internalConstant = "2" // for use anywhere in package only
)
func main() {
const functionConstant = "3" // usable anywhere in main func
fmt.Println(ExposedConstant, internalConstant, functionConstant)
}Whoops... forgot to add the top line to the code syntax. I really wish you could edit existing posts in this group.
On Tuesday, May 28, 2019 at 10:03:05 AM UTC-5, Trig wrote:package main
import "fmt"
const (
ExposedConstant = "1" // exposed outside of package
internalConstant = "2" // for use anywhere in package only
)
func main() {
const functionConstant = "3" // usable anywhere in main func
fmt.Println(ExposedConstant, internalConstant, functionConstant)
}
package main import "fmt" // Foo is a struct type Foo struct { A int B string } // DefaultFoo returns a useful default struct func DefaultFoo() Foo { return Foo{ A: 1, B: "abcd", } } // Bim does something func Bim() { fmt.Printf("%+v\n", DefaultFoo()) }
On Tuesday, May 28, 2019 at 7:12:06 AM UTC-5, Ashutosh Baghel wrote:Hello folks,I want to declare a few variables constant. But I guess there is nothing as "Constant" type in GoLang. How do I achieve this in GoLang?
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c9b3b7df-b2da-42ce-bd9e-44ee1eb589ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.