Quantcast
Channel: How to set and get fields in struct's method - Stack Overflow
Browsing all 4 articles
Browse latest View live

Answer by Volker for How to set and get fields in struct's method

Setters and getters are not that idiomatic to Go.Especially the getter for a field x is not named GetX but just X.See http://golang.org/doc/effective_go.html#GettersIf the setter does not provide...

View Article



Answer by peterSO for How to set and get fields in struct's method

For example,package mainimport "fmt"type Foo struct { name string}func (f *Foo) SetName(name string) { f.name = name}func (f *Foo) Name() string { return f.name}func main() { p := new(Foo)...

View Article

Answer by Zippo for How to set and get fields in struct's method

Commentary (and working) example:package mainimport "fmt"type Foo struct { name string}// SetName receives a pointer to Foo so it can modify it.func (f *Foo) SetName(name string) { f.name = name}//...

View Article

How to set and get fields in struct's method

After creating a struct like this:type Foo struct { name string}func (f Foo) SetName(name string) { f.name = name}func (f Foo) GetName() string { return f.name}How do I create a new instance of Foo and...

View Article
Browsing all 4 articles
Browse latest View live




Latest Images