Im writing a small code using Memcache Go API to Get data stored in one of its keys . Here are few of lines of code i used ( got the code from Go app-engine docs )
import "appengine/memcache" item := &memcache.Item { Key: "lyric", Value: []byte("Oh, give me a home"), }
But the line 2 gives me a compilation error "expected declaration, found 'IDENT' item"
I'm new to Go , not able to figure out the problem
The :=
Short variable declaration can only be used inside functions.
So either put the item
variable declaration inside a function like this:
import "appengine/memcache" func MyFunc() { item := &memcache.Item { Key: "lyric", Value: []byte("Oh, give me a home"), } // do something with item }
Or make it a global variable and use the var
keyword:
import "appengine/memcache" var item = &memcache.Item { Key: "lyric", Value: []byte("Oh, give me a home"), }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With