able | 21 May 2013 23:44
Picon

[go-nuts] Im carzy agent… bytes.Buffer : truncation out of range

Download the attachment , export to you go/src/ .  you need to run  cd  webgame/server/message && go get  



cd  gameai   and go build  in the folder ,.

1. ./gameai & 

2.  go test -v 


after 100000 circulations  :


panic: bytes.Buffer: truncation out of range

goroutine 29 [running]:
bytes.(*Buffer).Truncate(0xc20069aee0, 0x02013/05/2)
/usr/local/go11/src/pkg/bytes/buffer.go:65 +0xc7
bytes.(*Buffer).Read(0xc20069aee0, 0xc2007267a2, 0x2, 0x6, 0x0, ...)
/usr/local/go11/src/pkg/bytes/buffer.go:255 +0x6c
io.ReadAtLeast(0xc2000fb1b0, 0xc20069aee0, 0xc2007267a0, 0x4, 0x8, ...)
/usr/local/go11/src/pkg/io/io.go:284 +0xf7
io.ReadFull(0xc2000fb1b0, 0xc20069aee0, 0xc2007267a0, 0x4, 0x8, ...)
/usr/local/go11/src/pkg/io/io.go:302 +0x6f
encoding/binary.Read(0xc2000fb1b0, 0xc20069aee0, 0xc200151c60, 0x3d, 0x217980, ...)
/usr/local/go11/src/pkg/encoding/binary/binary.go:136 +0xf2
webgame/server/gamelib.func·002(0xc20014ecb0, 0xc20014e955, 0x22, 0x3f)
/Users/gao/code/mygo/src/webgame/server/gamelib/server.go:37 +0x2ab
webgame/server/gamelib.(*ServerMex).connDataSplit(0xc2000bf9b0)
/Users/gao/code/mygo/src/webgame/server/gamelib/server.go:129 +0x40a
created by webgame/server/gamelib.(*ServerMex).RunServer
/Users/gao/code/mygo/src/webgame/server/gamelib/server.go:180 +0xa4

goroutine 1 [IO wait]:
net.runtime_pollWait(0x5fde60, 0x72, 0x0)
/usr/local/go11/src/pkg/runtime/znetpoll_darwin_amd64.c:118 +0x82
net.(*pollDesc).WaitRead(0xc2000d42c0, 0x23, 0xc2000fb690)
/usr/local/go11/src/pkg/net/fd_poll_runtime.go:75 +0x31
net.(*netFD).accept(0xc2000d4240, 0x38bc90, 0x0, 0xc2000fb690, 0x23, ...)
/usr/local/go11/src/pkg/net/fd_unix.go:385 +0x2c1
net.(*TCPListener).AcceptTCP(0xc200159068, 0x3032d, 0x750ec8, 0x3032d)
/usr/local/go11/src/pkg/net/tcpsock_posix.go:229 +0x45
net.(*TCPListener).Accept(0xc200159068, 0xc20014ecb0, 0xc20014ecb0, 0xc20014ecb0, 0x0, ...)
/usr/local/go11/src/pkg/net/tcpsock_posix.go:239 +0x25
webgame/server/gamelib.(*ServerMex).RunServer(0xc2000bf9b0, 0xc2000fb2a0, 0x2, 0x5, 0xc2000fb2a0, ...)
/Users/gao/code/mygo/src/webgame/server/gamelib/server.go:185 +0x113
main.main()
/Users/gao/code/mygo/src/webgame1111/server/gameai/server.go:36 +0x90

goroutine 2 [syscall]:




but but but  but but but but !!!! well I can assure you there is always a method to my madness. 

gamelib/server.go  in line 33 ,

},
HEAD_14B: func(r *Request, b []byte) {
if len(b) < 14 {
return
}
Log.Println(b) // Now … the pain not exists! 
buf := bytes.NewBuffer(b)
tbuf = bytes.NewBuffer(buf.Next(2))
binary.Read(tbuf, binary.BigEndian, &r.Cid)
tbuf = bytes.NewBuffer(buf.Next(4))
binary.Read(tbuf, binary.BigEndian, &r.Rid)

tbuf = bytes.NewBuffer(buf.Next(4))
binary.Read(tbuf, binary.BigEndian, &r.Uid)

tbuf = bytes.NewBuffer(buf.Next(2))
binary.Read(tbuf, binary.BigEndian, &r.Typ)
tbuf = bytes.NewBuffer(buf.Next(2))
binary.Read(tbuf, binary.BigEndian, &r.Mlen)
r.Msg = buf.Next(int(r.Mlen))
},


My system ……
Darwin gaomatoMacBook-Air.local 12.3.0 Darwin Kernel Version 12.3.0: Sun Jan  6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64

--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Attachment (webgame.zip): application/zip, 67 KiB
tomwilde | 21 May 2013 23:44
Picon

How to parse variable-length month number with time.Parse

Hi,


I have a date format that looks like this:

4/9/2008T17:01:00

representing "the 9th of April of 2008, at 5:01 PM".

time.Parse understands "_2" as a day number that might or might not have a leading zero.

is there an equivalent for months?

I tried parsing using the layout "_1/_2/2006T15:04:05" but that doesn't work.

> error: parsing time "4/9/2008T17:01:00" as "_1/_2/2006T15:04:05": cannot parse "4/9/2008T17:01:00" as "_"

Cheers,

- Tom

--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Nate Finch | 21 May 2013 23:01
Picon
Gravatar

[ANN] npipe - Go wrapper for Windows named pipes

If you like Windows named pipes (and who doesn't? ...don't answer that ;) now you can use them in Go:




The package is built to be used just like the net package in the stdlib, so you have Dial, Listen, and Accept. Note, the Read and Write timeouts on the Connection object are only supported in Windows Vista and above due to a Windows API limitation.

I actually learned a bunch of interesting things writing this package, like the fact that a perl script is used to generate the syscall implementations in package syscall (boo for the Go authors making me install perl! ;) ... and that all Go-initiated IO on Windows XP and previous versions is shuttled off into a single, well-known thread, exactly to get around the Windows API issue I mentioned above (which, if you're curious, is that WinXP will only let you cancel IO from the same thread that it was called from).

The package should be considered beta quality software... there are sufficient tests that I think the code is fairly stable, but it has not been put to regular, strenuous use. I encourage pull requests.

-Nate

--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
droyo | 21 May 2013 21:14
Picon
Favicon

XML Unmarshalling

Hello,


I'm having a little trouble parsing XML. I'm trying to parse output from Dell's SOAP inventory service (see http://xserv.dell.com/services/assetservice.asmx?op=GetAssetInformation). My example program tries to pull out relevant info and print out CSV-formatted  lines for each service agreement:

    http://play.golang.org/p/nJSBNyCaXB

There's a number of things I'm unsure about:

- I'm reading a sub-element of the XML. Do I have to specify its parents in a tag somewhere?
- Should I specify the namespace in every element, just the containing elements, or at all?
- When parsing nested XML, should I tag the field in the containing struct, or put an XMLname field in the substruct?

Unfortunately I have to parse a lot of nasty XML at my job. I would love to be able to use Go to do it.

Cheers,
David

--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Will Norris | 21 May 2013 17:19
Picon
Favicon
Gravatar

default package names and hyphens

I know that the default name for an imported package is the last path component in the full package name.  So "a/b/c" is, by default, imported using the name "c".  

However, I just realized that go will split on hyphens as well.  So "a/b-c" is, by default, also imported using the name "c".  I've never seen this documented anywhere, so wanted to confirm that this is in fact intended behavior that won't be accidentally removed at some point.  Is it generally acceptable to use this naming convention, or is it discouraged?  (it does generally help clean up the imports of many packages that are named "go-package").

Thanks.

--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Bienlein | 21 May 2013 17:34
Picon

What's the point in compiling to the metal?

Hello,

my question may seem odd at first sight. But I think it is a valid one, because VMs meanwhile offer very good performance and portability anyway. Is generating machine code in Go a deliberate decision to get as much performance as possible or is it maybe simply a side-effect, because that's what the Plan 9 compiler puts out anyway?

Regards, Bienlein

--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Brian Ketelsen | 21 May 2013 17:33
Picon
Gravatar

GopherAcademy Job Board

I'm happy to announce the open beta of Gopher Academy's Job Board[1]  Jobs are always free to search, but may
have a nominal fee to post in the future.  In addition to the ongoing organization of GopherCon 2014[2],
this is part of Gopher Academy's ongoing effort to help build community resources for Go developers.

Best Regards,
The Gopher Academy Team

[1] http://www.gopheracademy.com/jobs
[2] http://www.gophercon.com

--

-- 
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@...
For more options, visit https://groups.google.com/groups/opt_out.

Toni Cárdenas | 21 May 2013 16:10
Gravatar

net/url#URL.Path has '%2F' turned into '/'

And, as ServeMux uses req.URL.Path for matching URLs against patterns, /foo%2Fbar leads to the same page as /foo/bar. 


Is that expected and correct? It's not this way with, say, Apache.


--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
mattn | 21 May 2013 15:22
Picon
Gravatar

[ANN] Gost: Deploying with gtihub push

Hi list.


I added new program "gost" in my repo.

https://github.com/mattn/gost

This is a small program that can deploy web service with github push. When this web application receive github push, it run following tasks.

1. Stop an updated service via goreman's RPC.
  This service should be run via goreman.
  See: https://github.com/mattn/goreman

2. Run command like git pull
  So you should specify git repo as http:// scheme not git <at> .

3. Start a service 

For example:

Procfile
---
web1: bundle exec ruby web.rb
gost: gost -c gost.json
gorem: gorem -c gorem.json
---

gorem.json
---
{
  "mattn": {
    "address": "127.0.0.1:80",
    "entries": {
      { "path": "/deploy/", "backend": "127.0.0.1:8100" },
      { "path": "/app1/", "backend": "127.0.0.1:8101" },
    }
  }
}
---
# You can change port of gorem to nginx upstream.

gost.json
---
{
  "addr": "127.0.0.1:8100",
  "apps": {
    "web1": {
      "proc": "my-ruby-app",
      "path": "/home/mattn/dev/my-ruby-app/"
    }
  }
}
---

At the last, you must add webhook for the repository of my-ruby-app on github. You can deploy it with github push.

Thanks.

--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
mattn | 21 May 2013 14:39
Picon
Gravatar

[ANN] Easy way to select JSON element

Hi list.


I wrote small library to select JSON element from interface{}.
Go require struct for scaning data from JSON. As you know, it's possible with interface{}, but it's harder to select deepy structure like:

var a interface{}
json.NewDecoder(os.Stdin).Decode(&a)
a.(map[string]interface{})["foo"].(interface[string]interface{})["bar"].([]interface{})[2].(string)

I'm thinking go-scan is useful to select deepy structure in interface{}.
For example:

1. Scan string

   // { "foo": { "bar": "baz" } }
   var s string
   scan.ScanTree(a, "/foo/bar", &s) // s should be "baz"

2. Scan float64

   // { "foo": { "bar": 3 } }
   var f float64
   scan.ScanTree(a, "/foo/bar", &f) // s should be 3.0

3. Scan bool

   // { "foo": { "bar": true } }
   var b bool
   scan.ScanTree(a, "/foo/bar", &b) // s should be true

4. Scan slice of string

   // { "foo": { "bar": ["go", "lang"] } }
   var s []string
   scan.ScanTree(a, "/foo/bar", &s) // s[0] should be "go", s[1] should be "lang"


Thanks.

--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Bastien Dejean | 21 May 2013 11:34
Picon
Gravatar

[ANN] z.go -- Wu wei terminal directory jumping

I just wrote my first Go program:
    https://github.com/baskerville/z.go

The main advantages of z.go over z are speed and bendability.

Greetings,
-- 
 b.d
(| |)
 ^ ^

--

-- 
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@...
For more options, visit https://groups.google.com/groups/opt_out.


Gmane