Picon

Is possible convert slice byte to a struct?

Hi,
The couchbase SDK, when I want update to document json, return me an []bytes. My app insert document of type struct called UserData to database, and when i want get the same document, i can retrieve it passing a UserData pointer at "Get" function of couchbase SDK. But when I want update the same document (by "Update" function from couchbase SDK), this is a slice bytes. It is possible convert this slice byte to particular struct (UserData in this case)?

Best,
Emilio

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Art Mellor | 15 Apr 20:20 2014
Picon

Sprintf gives error, Printf does not

I'm stumped at what I'm missing here. fmt.Printf(args) works fine, but fmt.Sprintf(args) complains about missing args.

Reproduced problem in the playground
http://play.golang.org/p/iCcBLxG-Nu

I'm thinking I'm missing something obvious, but I can't see it.


--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Fredrik Wallgren | 15 Apr 20:14 2014
Picon

My first library, targz. Looking for feedback.

Hello,

I just put my first Go library up on Github. https://github.com/walle/targz

Just starting out with Go, and I feel that I don't really have error handling figured out. 
I would appreciate it a lot if anyone would like to give me a couple of pointers.

And not just feedback about error handling, any feedback you are willing to give will be appreciated. 

Hope the library will be useful for someone other than me!

Regards,
Fredrik 

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Ken GoNoob | 15 Apr 19:47 2014
Picon

Difference between main() and init()?

Just for curiosity, is there any difference between using init(), which runs prior to main(), and having the same functions as the first thing in main()?  I.e. is:

init() {
    setup1()
    setup2()
    ....
}

main() {
    .....
}

somehow different from:

MyInit() {
    setup1()
    setup2()
    ....
}

main() {
    MyInit()
    ....
}

or different from:
main() {
    setup1()
    setup2()
    ....
}

????
Thanks,
Ken

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Val | 15 Apr 18:48 2014
Picon

App Engine : no way to read datastore.Key.namespace ?

Hello
Here is my problem broken down in chunks :

a) Most professional projects want to have distinct Dev, Staging and Production execution environments.

b) Having 3 versions of the same app in App Engine does not fully address (a) because the Datastore is shared, yet it is highly desirable to have separate Dev and Staging data.

c) A workaround to (b) is to have 3 independant apps "foobar-dev", "foobar-staging", "foobar-production", each having separate code and Datastore.

d) Then we need on a regular basis to copy all data from "foobar-production" to "foobar-dev". But if any entity in Datastore (or other persistant storage e.g. Cloud Storage) contains a string representation of a datastore.Key, then we end up with inconsistant data because keys are tied to a specific AppID and a specific Namespace.

e) A workaround to (d) is (after copying) to convert "foobar-production" keys to proper "foobar-dev" keys.

f) Datastore keys encoded as strings are non-trivial to understand and handle.

g) The field "namespace" of a key is not accessible in Go (although it is possible to get it in Java and Python).

Thus, I cannot complete this viewer app for now : http://datastore-key.appspot.com/?keystring=ag5lfmt1Yml0eS1zZmVpcnIjCxIHQWNjb3VudBjixQgMCxIHUHJvamVjdBiAgICAoJmYCAw ,
nor can I complete my data migration process.

Maybe one of you would have advice for me?
I understand up to a point the "transient" nature of keys and namespaces, but I feel a bit artificially blocked for something as simple as copying data.
Best regards

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Francesc Campoy Flores | 15 Apr 18:47 2014

Some serious Gopher love

Luit van Drongelen ( <at> LuitvD) tweeted this amazing picture today:

There's no going back now! This #golang gopher will stay with me forever. (thanks for the artwork <at> reneefrench) http://t.co/IaqWeq2CsR

(https://twitter.com/LuitvD/status/456099068637237248)

Amazing :-)

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
rinat.abdullin | 15 Apr 16:02 2014
Picon

What is the recommended way to implement multi-node chat server in golang?

Hi All, 

I have question on approaching a problem with golang at its ecosystem.

At happypancake.com we are building a chat server for the next version of our social dating web site. We are trying to stick to golang, since it has really nice concurrency primitives and great web stack.

However, recently we hit a wall with a design problem. This is most likely due to me just being silly. So I hope you could help me out.

So, in our chat two people can engage in a conversation between each other. They can send messages and also see "User X is typing" presence notifications. 

I expect to have 20k people chatting at the same time (based on the numbers from the existing system). Obviously, we don't want to go to database each time a message is sent, user starts typing or every time client asks for new updates (both presence or messages).

As I understand, people solve this problem by caching latest messages in memory and occasionally spilling it to the disk in batches. Majority of requests will be performed against that cache, and will be really fast and cheap.

This approach can probably be implemented in two ways in a cluster (neither of which seems to be supported in golang):

1. Actor style : conversation state is located on one of the nodes in the cluster. All requests for that conversation (post message, get last events since X, notify that user is typing) will be somehow routed to that node. Regularly the node will be save state from memory to the disk (loosing a few messages is OK in our case). In case of crash, the conversation state will be linked to the other node and loaded from memory. All new requests will be from now on routed to that node.

Problem with that approach : As far as I know, there is no tooling in golang ecosystem to deal with this kind of state-aware routing, leader election and actor management functionality.

2. Replicate everywhere : all messages are replicated to all nodes in the cluster (e.g.: via zeromq, nanomsg or http connection between the peers). Each node maintains a copy of conversation state in memory. State between the nodes is in sync (in eventually consistent way).

Problems with that approach : It does not scale out, we would have to deal with managing peer relations (and dealing with fail over) and network partitions.

So the question is : how would you recommend to deal with this design challenge in go? Is there an approach that fits the ecosystem and existing tooling that I missed?

Best regards,
Rinat

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Scott Turnbull | 15 Apr 15:38 2014
Picon

robust task queue solutions in Go?

Hello,

We're looking to implement some background processing in Go but need to managed a chained set of tasks that connect to some systems with high latency (S3 or Glacier).  We're looking for something with good failover and recovery like you get with Celery in python.  Searching around the Go community I'm not sure I see a stand out solution the community is turning to.  I've see go-worker and goworker as well as go-nsq but is anyone using anything successfully that provide good failover and recovery features without having to fully implement it yourself?

Thanks for any feedback.

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Jiacheng Guo | 15 Apr 15:07 2014
Picon

gob can not decode pointer reciever interface

hi,
   In the gob document, the example demonstrate how you can encode and decode a interface value. However, when I change the interface implement from value receiver to pointer receiver. The decode process fail to run.
   http://play.golang.org/p/eMsIt-nwfO
 
   Is this an expected behavior or a bug?

Thanks,
Jiacheng Guo

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
farah | 15 Apr 13:23 2014
Picon

Go buffer allocation memory

Hello!
This is my code in which i create a buffer and receive data in it.
in my code i allocate the buffer in every loop , and while go is a garbage collector language so i don't need to destruct it.
my question is : is there a better solution to create the buffer with a better consumption of memory ,
or should i destruct it every time ??


for {

        buffer1 := make([]byte,512)
        client.ReadClient(buffer1)
        str:=str2+string(buffer1)

        for {
                                posSTX := strings.Index(str, string(0x02))
       posETX := strings.Index(str, string(0x03))
       if(posSTX==-1 || posETX==-1) {
return
}

if (strings.LastIndex(str, string(0x02)) != posSTX || strings.LastIndex(str, string(0x03)) != posETX) {

str1:=str[posSTX+1:posETX]
str2=str[posETX+1:]
str=str2

}else {
   Log("MsgR: ",str[posSTX+1:posETX])
   str2=""
}

if str2=="" ||  strings.Index(str2,string(0x03))==-1  {break}
   }
}

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Jens Tingleff | 15 Apr 10:00 2014

Downloading / compiling godoc into system-wide installation using go get?

All,

aka 'I got the "cannot download, $GOPATH must not be set to $GOROOT." blues'

 

I think this should be an FAQ, but I can't seem to find the answer. Vexing!

 

I learn that GOPATH and GOROOT cannot be the same in order to improve the user experience of the Go user.

 

Okie dokie.

 

What about the sysadmin who would like to install one godoc, into the standard directory where Go binaries live?

 

I tried making a /usr/local/go which is owned by a user which then builds it (it's not the root user, but root has chown'ed the /usr/local/go directory to that user).

 

I build Go and all users can see go in /usr/local/go/bin (and there was much rejoicing). I then, as the building user, try a "go get code.google.com/p/go.tools/cmd/..." and get the above.

 

So, I cannot be the only one who would like a system-wide godoc installation. (So as to launch the webserver on start, for instance.)

 

Any help appreciated

 

Jens

 

Shell history below.

 

 

70 hg clone -u release https://code.google.com/p/go

71 ll go/

72 cd go/src/

73 ./all.bash

74 echo $GOROOT

75 which go

76 go version

77 cd /usr/local/go

79 go get code.google.com/p/go.tools/cmd/...

88 echo $GOPATH

89 cd $GOPATH

91 go get code.google.com/p/go.tools/cmd/...

 

`go env'

 

[builder <at> Jenss-Air go]$ go env

warning: GOPATH set to GOROOT (/usr/local/go) has no effect

GOARCH="amd64"

GOBIN=""

GOCHAR="6"

GOEXE=""

GOHOSTARCH="amd64"

GOHOSTOS="linux"

GOOS="linux"

GOPATH="/usr/local/go"

GORACE=""

GOROOT="/usr/local/go"

GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"

TERM="dumb"

CC="gcc"

GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"

CXX="g++"

CGO_ENABLED="1"

 

--

Key ID 0x09723C12, jensting-wkKmszdrV+9g9hUCZPvPmw@public.gmane.org

Analogue filtering / 5GHz RLAN / Fedora Linux / odds and ends

http://www.tingleff.org/jensting/ +33 9 54 93 68 65

"Great! I'm hearing horses. Parry will be so pleased" Jack, 'The Fisher King'

 

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.


Gmane