[go-nuts] How can I read bytes from C.Array(three levels) by using Cgo

2016-12-08 Thread Wanghb Wang
my C code Array for example:
const uint8_t** kPacketMaskRandomTbl[48] = {
  kPacketMaskRandom1,
  kPacketMaskRandom2,
  kPacketMaskRandom3,
.
};
const uint8_t* kPacketMaskRandom1[1] = {
  kMaskRandom1_1
};
const uint8_t kMaskRandom1_1[2] = {
  0x80, 0x00
};
.


I want to read bytes from 
kPacketMaskRandomTbl
by using cgo, How can I do?

I write code like this

qq := 
((*uint8)(unsafe.Pointer((uintptr((*uint8)(unsafe.Pointer(uintptr(unsafe.Pointer(p))+uintptr(1
 + uintptr((unsafe.Sizeof(*uint8)))

It is not right!
How can I do?

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: converting slice of items into nested array

2016-12-08 Thread Mikael Gustavsson
There's no need to use maps, you want to follow this pattern:

for i := range items {
  if i==0 || !grouped(i-1, i) {
appendToResult
  }
  appendToGroup
}

Here's the full example: https://play.golang.org/p/1e0rDDmq7b

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] liteide x30.3 released

2016-12-08 Thread visualfc
IA==

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


re:[go-nuts] liteide x30.3 released

2016-12-08 Thread visualfc
IA==

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: converting slice of items into nested array

2016-12-08 Thread Marvin Renich
* Mikael Gustavsson  [161208 03:55]:
> There's no need to use maps, you want to follow this pattern:
> 
> for i := range items {
>   if i==0 || !grouped(i-1, i) {
> appendToResult
>   }
>   appendToGroup
> }
> 
> Here's the full example: https://play.golang.org/p/1e0rDDmq7b

Note that this only works if the input slice is sorted, which it is in
the example data given by the OP, but that constraint was not explicitly
stated.  If the input is not sorted, you must either sort it first, use
a map, or perform a search in each iteration.

If the input data is not guaranteed to be sorted, minimal changes to the
above would work: https://play.golang.org/p/4GsVUV_fBs

The map is only used to perform the search efficiently, and is no longer
used after the for loop.

...Marvin

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Handling nil embedded interfaces

2016-12-08 Thread Traun Leyden

After chatting w/ some gophers on twitter, I ended up with:

https://play.golang.org/p/UJu4WAmkHk

It defaults the embedded interface to an "no-op" implementation 
(NilEventLog) rather than nil, which was the best approach for my 
particular issue.

On Wednesday, December 7, 2016 at 11:32:42 AM UTC-8, Traun Leyden wrote:
>
>
> What's the best practice around handling embedded interfaces that are nil?
>
> For example:
>
> https://play.golang.org/p/EcqV7h9cNU
>
> Is there a better way than wrapping the embedded interface's methods and 
> forwarding down as long as it's not nil?
>
> I guess another approach would be to create a NoOpEventLog in the 
> NewService() function which would ignore any calls to service.SaveEvent().  
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] converting slice of items into nested array

2016-12-08 Thread Tamás Gulácsi
Use capitalized field names and struct tags - lowercase is not exported, 
encoding/json does not 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Idiomatic way of handling http requests in separate goroutines

2016-12-08 Thread Tamás Gulácsi
I think this is not bad.
But you can try context.Context, or simply pass in a new chan, which will be 
closed by the worker - so you can select, timeout on 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: go install seems to do a lot of rebuilding in a container

2016-12-08 Thread shaun
> Docker add, or whatever is pushing files into your container is probably 
not respecting timestamps so the .a files are older with respect to .go 
files (pkg sorts above src)

I'm bind-mounting the pkg dir in there so it shouldn't be a question of 
timestamps (not ruling out something going on there).  Those are the "real" 
files.

> Why do you want to build inside a container, is that just adding an extra 
level of indirection to what is a simple process?

Using containers gives us a lot of control over the build without mandating 
a lot of set-up on each developer's machine (they need make and docker 
installed).  For example, using a container locks the build to the correct 
libc and version of go and it ensures the that project documents (in code) 
all the required dependencies and doesn't depend on local dev environment. 
 It also lets developers use Linux Mac or Windows and still be able to 
build the product in the right environment.  Beyond that, it lets us build 
all kinds of artefacts that previously would have required several 
dedicated (crufty) build machines: we can use a container to build debs and 
RPMs, on a Mac, for example.

On Wednesday, December 7, 2016 at 9:57:51 PM UTC, Dave Cheney wrote:
>
> Docker add, or whatever is pushing files into your container is probably 
> not respecting timestamps so the .a files are older with respect to .go 
> files (pkg sorts above src)
>
> Why do you want to build inside a container, is that just adding an extra 
> level of indirection to what is a simple process?
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] validating self-signed certs

2016-12-08 Thread Steve Roth
I have an application that needs to talk to numerous external devices, each 
of which has only a self-signed cert.  We can't simply accept all 
self-signed certs with insecureSkipVerify; instead, as part of configuring 
the application for each new external device, we need to import its 
self-signed cert into our trust store.  (Yes, I know this is gross, but 
it's outside my control.)  I can't figure out a way to do this in Go other 
than by creating a new Transport with a new tls.Config for each external 
device.  But the docs for Transport explicitly advise reuse rather than 
creating lots of them.  Is there a trick I haven't found that would let me 
safely add a cert to the tls.Config for DefaultTransport?  Or in some other 
way avoid the need to create dozens of Transports (and therefore also 
Clients)?

Thanks in advance...

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] How can I read bytes from C.Array(three levels) by using Cgo

2016-12-08 Thread Ian Lance Taylor
On Thu, Dec 8, 2016 at 12:48 AM, Wanghb Wang  wrote:
> my C code Array for example:
> const uint8_t** kPacketMaskRandomTbl[48] = {
>   kPacketMaskRandom1,
>   kPacketMaskRandom2,
>   kPacketMaskRandom3,
> .
> };
> const uint8_t* kPacketMaskRandom1[1] = {
>   kMaskRandom1_1
> };
> const uint8_t kMaskRandom1_1[2] = {
>   0x80, 0x00
> };
> .
>
>
> I want to read bytes from
> kPacketMaskRandomTbl
> by using cgo, How can I do?
>
> I write code like this
>
> qq :=
> ((*uint8)(unsafe.Pointer((uintptr((*uint8)(unsafe.Pointer(uintptr(unsafe.Pointer(p))+uintptr(1
> + uintptr((unsafe.Sizeof(*uint8)))
>
> It is not right!
> How can I do?

The top level array should have the type of a Go array, but it's true
that the inner levels will be pointer types, and of course Go, unlike
C, does not permit array-style access for pointer types.  I would
suggest simply writing little helper functions in Go to do the array
accessing using unsafe.Pointer.

Ian

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] validating self-signed certs

2016-12-08 Thread Andy Balholm
Why not make a tls.Config that trusts all the self-signed certs for all the 
different devices, and make one Transport with that config?

Andy

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] validating self-signed certs

2016-12-08 Thread Steven Roth
Well, because when someone wants to import a new device, I can't change the
existing Transport.  The docs explicitly say not to change it once it's in
use.

Steve


On Thu, Dec 8, 2016 at 8:42 AM, Andy Balholm  wrote:

> Why not make a tls.Config that trusts all the self-signed certs for all
> the different devices, and make one Transport with that config?
>
> Andy

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] xml omitempty for sub-elements

2016-12-08 Thread Peter Kleiweg
Four years later, and this still hasn't been fixed. The conversation you 
are linking to has been locked. What can we do? File a new bug report?


Op donderdag 15 november 2012 13:41:55 UTC+1 schreef Vladimir Mihailenco:
>
> I guess you have to vote for 
> http://code.google.com/p/go/issues/detail?id=4168 .
>
> For now I do post processing like replace("", ""), because 
> xml schema validators does not accept such constructs.
>
>
> On Thu, Nov 15, 2012 at 1:49 PM, OmarShariffDontLikeIt <
> omarsharif...@gmail.com > wrote:
>
>> http://play.golang.org/p/E65WSpB8BY
>>
>> How can I Marshal an instance of the above structure and have the
>> "" element omited if it contains no items in the array? I want
>> the following output:
>>
>> My Project
>>
>> Any suggestions?
>>
>> Cheers,
>> Ben
>>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] validating self-signed certs

2016-12-08 Thread Andy Balholm
So the set of devices keeps changing. 

I think you can make an http.Transport with a custom DialTLS function that 
always uses an up-to-date TLS config.

Andy

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Deleting the /r/golang subreddit

2016-12-08 Thread Russ Cox
Although this conversation started out on the wrong foot, it did end up
being a valuable discussion. If you haven't seen the posts yet, the
conversation continued on /r/golang. I want to update this thread to point
at my latest post there, proposing that the Googlers who are moderators all
step back, leaving dgryski to establish a new set of moderators drawn from
the active users there. If you want to discuss that proposal, please do it
on the Reddit post, not here.

https://www.reddit.com/r/golang/comments/5h87u6/proposal_dgryski_for_top_mod/

Thanks.
Russ

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] validating self-signed certs

2016-12-08 Thread Steven Roth
Sounds like a good solution.  Thanks!
Steve

On Thu, Dec 8, 2016 at 9:12 AM, Andy Balholm  wrote:

> So the set of devices keeps changing.
>
> I think you can make an http.Transport with a custom DialTLS function that
> always uses an up-to-date TLS config.
>
> Andy

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Go @ Work

2016-12-08 Thread jeffr


On Friday, March 30, 2012 at 10:27:36 AM UTC-7, hcatlin wrote:
>
> Just thought I'd stop in and post something saying "hi" to the group. 
> I work at 
> Moovweb where we power some of the biggest e-commerce sites' mobile 
> experience 
> on our platform. Our platform has super strong demands on it and our 
> business is 
> growing at a nearly exponential rate. 
>
> This past summer, I made the decision to switch all of our internal 
> software to Go 
> after being persuaded by our Senior Architect, Zhigang Chen. Of 
> course, knowing that Go 
> was beta and that the future of the company was being bet on Go was 
> (and is) amazingly 
> stressful. 
>
> The library ecosystem was a little weak for our needs when we first 
> showed up so 
> we've since released a Regexp library called Rubex that makes regular 
> expressions 
> 2-3x faster, we've released Gokogiri which is a libxml wrapper library 
> for XML/HTML 
> parsing, and GVM the go version manager so that we can work with code 
> bases 
> on various versions of Go. 
>
> A couple observations: 
> * New users/employees have learned Go very quickly. +20! 
> * Found out about breakage in 32-bit while in production. -10! 
> * Had to write our own libraries for some basic stuff. -5! 
> * Performs very well in production (only on 64-bit). +10! 
>
> Man, so much to say... this bullet list might go on and on. 
>
> I mostly just wanted to say that to us Go is not a hobbyist language. 
> Its a complex 
> build environment for us with dependency management and 5 full time 
> developers 
> writing code daily in it. 
>
> We didn't build "some small part" of our platform in Go... its the 
> heart of our tech. 
> Our SDK is a compiled binary that we are packaging and sending out to 
> our 
> clients and integration partners. Our production system is handling 
> millions of pages 
> a day and millions of dollars of ecommerce a month. 
>
> We've bet on Go big time... and will continue to bet on it. We will 
> continue to release 
> new code and we will continue to try and mature the community and tool 
> set so that 
> we can deal with real life issues. 
>
> I'd love to hear if other companies are doing a similar thing. 
>
> http://site.moovweb.com // public site 
> http://github.com/moovweb // public software repo 
>
> -hampton (@hcatlin) 
>
>
> Hi  Hampton,

I can assure you some big bets are being laid on Go as it has so much going 
for it. My thoughts are here (I'm product guy at ActiveState) and why we at 
ActiveState are "all-in" on Go: http://bit.ly/2gD4zxp

Cheers,

-JR

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] go install seems to do a lot of rebuilding in a container

2016-12-08 Thread shaun
I've started with a clean pkg dir.

It's odd; the mtimes look correct (same inside/outside container).  the 
"buildid" to the compile commands s the same on each run too.

Does anyone know if there's a way to print out the "StaleReason" that the 
code collects, that might help me find out what gate I'm failing.

On Wednesday, December 7, 2016 at 11:08:14 PM UTC, andrey mirtchovski wrote:
>
> it's also possible that you need to do "go build -i" just in case your 
> dependencies are outdated. i had the same issue today with a windows 
> piece of code that rebuilt sqlite3 every time. 
>
>
> On Wed, Dec 7, 2016 at 2:57 PM, Dave Cheney  > wrote: 
> > Docker add, or whatever is pushing files into your container is probably 
> not respecting timestamps so the .a files are older with respect to .go 
> files (pkg sorts above src) 
> > 
> > Why do you want to build inside a container, is that just adding an 
> extra level of indirection to what is a simple process? 
> > 
> > -- 
> > 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 . 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] go generate "pipelines"

2016-12-08 Thread Paul Jolly

>
> I'm quite happy with the semantics as described by `go generate --help`. 
> All I think I need is a simple wrapper to automate this pipeline approach 
> and make it non-project specific; for us it's come up in a couple of 
> places, but admittedly never more than a two-step pipeline.
>

I've pulled together a working (but very much work-in-progress) prototype:

https://github.com/myitcv/gg

Any thoughts, feedback gratefully received.  

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Downloading go1

2016-12-08 Thread Edward Muller
Thank You!

On Fri, Dec 2, 2016 at 5:25 PM Brad Fitzpatrick  wrote:

> Thanks!
>
>
> On Fri, Dec 2, 2016 at 4:53 PM, Will Norris  wrote:
>
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go.go1.darwin-386.pkg
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go.go1.darwin-amd64.pkg
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go.go1.freebsd-386.tar.gz
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go.go1.freebsd-amd64.tar.gz
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go.go1.linux-386.tar.gz
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go.go1.linux-amd64.tar.gz
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go.go1.src.tar.gz
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go.go1.windows-386.msi
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go.go1.windows-386.zip
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go.go1.windows-amd64.msi
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go.go1.windows-amd64.zip
>
> On Fri, Dec 2, 2016 at 4:17 PM, Brad Fitzpatrick 
> wrote:
>
> I've asked for a list of our objects under that prefix.
>
>
> On Thu, Dec 1, 2016 at 1:56 PM, Edward Muller 
> wrote:
>
> For $reasons I need to download the original linux amd64 version of go1.
>
> Older go versions are stored under
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/
>
> I have retrieved go1.0.1 (
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go1.0.1.linux-amd64.tar.gz)
> and later successfully.
>
> But I can't seem to find the right key for go1. I've tried:
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go1.linux-amd64.tar.gz
> 
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go1-linux-amd64.tar.gz
> 
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go1.0.linux-amd64.tar.gz
> 
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go1.0-linux-amd64.tar.gz
> 
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go1.0.0.linux-amd64.tar.gz
> 
>
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/go1.0.0-linux-amd64.tar.gz
> 
>
> All respond with:
>  encoding='UTF-8'?>NoSuchKeyThe specified key
> does not exist.
>
> I've also tried the getting an index (
> https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go
> /),
> like you can with https://storage.googleapis.com/golang/ (where modern go
> releases are stored), but that just returns the same error.
>
> Can anyone point me to the right https://storage.googleapis.com url for
> the go1 release?
>
> 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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: http2 client/server reversal performance

2016-12-08 Thread jonathan . gaillard
Anyone mind lending some weight/priority to a fix for the issue above? :D

On Saturday, November 19, 2016 at 6:19:50 PM UTC-8, jonathan...@gmail.com 
wrote:
>
> https://github.com/golang/go/issues/17985 
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] go install seems to do a lot of rebuilding in a container

2016-12-08 Thread Ian Lance Taylor
On Thu, Dec 8, 2016 at 10:13 AM,   wrote:
> I've started with a clean pkg dir.
>
> It's odd; the mtimes look correct (same inside/outside container).  the
> "buildid" to the compile commands s the same on each run too.
>
> Does anyone know if there's a way to print out the "StaleReason" that the
> code collects, that might help me find out what gate I'm failing.

go list -f '{{.StaleReason}}'

Ian

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] xml omitempty for sub-elements

2016-12-08 Thread C Banning
https://play.golang.org/p/aMtZhha073

On Thursday, December 8, 2016 at 10:09:17 AM UTC-7, Peter Kleiweg wrote:
>
> Four years later, and this still hasn't been fixed. The conversation you 
> are linking to has been locked. What can we do? File a new bug report?
>
>
> Op donderdag 15 november 2012 13:41:55 UTC+1 schreef Vladimir Mihailenco:
>>
>> I guess you have to vote for 
>> http://code.google.com/p/go/issues/detail?id=4168 .
>>
>> For now I do post processing like replace("", ""), because 
>> xml schema validators does not accept such constructs.
>>
>>
>> On Thu, Nov 15, 2012 at 1:49 PM, OmarShariffDontLikeIt <
>> omarsharif...@gmail.com> wrote:
>>
>>> http://play.golang.org/p/E65WSpB8BY
>>>
>>> How can I Marshal an instance of the above structure and have the
>>> "" element omited if it contains no items in the array? I want
>>> the following output:
>>>
>>> My Project
>>>
>>> Any suggestions?
>>>
>>> Cheers,
>>> Ben
>>>
>>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Golang text template - time.Format epoch

2016-12-08 Thread Marvin Renich
* 'Sergey Krutsko' via golang-nuts  [161208 
02:12]:
> Thanks Marvin!
> 
> that's exactly what i need
> 
> bwt, is there any way to get current timestamp inside the template (without 
> referencing to the data structure) ?
> 
> something like that:
> "timestamp: {{time.Now.Unix}}"

You can use a template.FuncMap.

If, by "without referencing to the data structure", you mean without
adding anything additional to the data structure, then you will have to
use a FuncMap.   If you mean "without adding the current time as a value
to the data structure", but will allow adding functions to the data
structure, then there is another way.  Add a field (or map element) to
the data of some func type (e.g. func() time.Time) and use call inside
the template.

The playground link https://play.golang.org/p/9rsVDBPzy2 demonstrates
both methods.

When using a FuncMap, it must be defined on the template (with a call to
Funcs) before parsing any template that uses it.  If you are using
ParseFiles or ParseGlob, rather than Parse, this is a little tricky, and
the template documentation could be improved significantly to address
the issue.

The helper functions ParseFiles and ParseGlob (at the package level,
rather than the methods on *Template) cannot be used because there is no
way to pass a FuncMap before parsing.

If you try something like

var t, err = template.New("").Funcs(fm).ParseFiles(file)
// handle error, then...
err = t.Execute(os.Stdout, data)

you will get an error containing

... "" is an incomplete or empty template;...

The problem is that t is an empty template with name "", and the
template(s) resulting from ParseFiles is only an associated template
with a name derived from the file name.  So t.Execute() attempts to
execute the empty template.  There are at least two ways to make it
work.  One way is to replace the first line above with

var t, err = template.New(filepath.Base(file)).Funcs(fm).ParseFles(file)

and the other is to replace the Execute line above with

err = t.ExecuteTemplate(os.Stdout, t.Templates()[0].Name(), data)

A third way would be to use ioutil.ReadFile to read the whole file and
then call t.Parse on the string obtained from that.  Using this method,
the result of Parse is used as the template t, not as an associated
template with a different name.

...Marvin

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Idiomatic way of handling http requests in separate goroutines

2016-12-08 Thread Pablo Rozas-Larraondo
Thank you Tamás, 

I like the concept of blocking on select in the handler until a worker 
closes the channel. I don't know why but every time I use a WaitGroup I 
have the impression that the same thing can be done better.

I'll try to implement it with the context library first as I'm very 
intrigued about it.

Cheers,
Pablo

On Friday, December 9, 2016 at 1:33:14 AM UTC+11, Tamás Gulácsi wrote:
>
> I think this is not bad.
> But you can try context.Context, or simply pass in a new chan, which will 
> be closed by the worker - so you can select, timeout on 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] is there bug with keyword "select" implementation?

2016-12-08 Thread Freeman Feng
Hello,

I found that if I use timeout mixed with another chan which is heavily 
communicated with other goroutines, it could lead to dead lock or something 
inside select

Here is the codes:

for {
select {
case x := <-ch:
// handling business logic begin (about 38+ message pushed to this chan at 
the same time) 
...
// handling business logic end
* case <-btimeout:*
* stop <- 1*
* stats(requests, done, fails, time.Duration(bench_timeout), starttimes, 
endtimes)*
* return*
* case <-timeout:*
* switch {*
* case totals == 0:*
* stop <- 1*
* stats(requests, done, fails, time.Duration(duration), starttimes, 
endtimes)*
* return*
* default:*
* stop <- 0*
* init_timeout_trigger(duration, timeout)*
}
}
When I run the code and the communication between channel "ch" up to 4600+, 
the "select" handling will run into dead
When I commented the two case of "*btimeout*" and "*timeout*", then 
everything will be OK

So, I suspect if the "select" keyword may have bug in scheduling each true 
case fairly while timeout event not triggered at all 

Could anyone explain to me if it is a bug with "select" or just my usage is 
incorrect? 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Upload streaming (chunking) with net/http/httputil's ReverseProxy?

2016-12-08 Thread Gabi Zuniga
ReverseProxy seems to forward the request only once the body is completely 
received. 
In fact it seems like the http.Handler semantics are the same.
Is there a way to handle each chunk as it is received by the server, kind 
like node.js does?
Otherwise are there alternative libraries that support this?

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] is there bug with keyword "select" implementation?

2016-12-08 Thread Ian Lance Taylor
On Thu, Dec 8, 2016 at 7:44 PM, Freeman Feng  wrote:
>
> I found that if I use timeout mixed with another chan which is heavily
> communicated with other goroutines, it could lead to dead lock or something
> inside select
>
> Here is the codes:
>
> for {
> select {
> case x := <-ch:
> // handling business logic begin (about 38+ message pushed to this chan at
> the same time)
> ...
> // handling business logic end
> case <-btimeout:
> stop <- 1
> stats(requests, done, fails, time.Duration(bench_timeout), starttimes,
> endtimes)
> return
> case <-timeout:
> switch {
> case totals == 0:
> stop <- 1
> stats(requests, done, fails, time.Duration(duration), starttimes, endtimes)
> return
> default:
> stop <- 0
> init_timeout_trigger(duration, timeout)
> }
> }
> When I run the code and the communication between channel "ch" up to 4600+,
> the "select" handling will run into dead
> When I commented the two case of "btimeout" and "timeout", then everything
> will be OK
>
> So, I suspect if the "select" keyword may have bug in scheduling each true
> case fairly while timeout event not triggered at all
>
> Could anyone explain to me if it is a bug with "select" or just my usage is
> incorrect? thanks.

A bug in select is fairly unlikely at this point.  Can you show us a
complete program that demonstrates the failure?  In particular, what
is reading from the stop channel?

Ian

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Implement ClusterClient Pipeline with transaction using go-redis package

2016-12-08 Thread plsd01p
My requirement is to implement pipelining and transactions both with a 
clusterclient using go-redis  .How do I do this?

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Isn't the use of Context in db/sql non-diomatic?

2016-12-08 Thread Chandru
Bump

--
Chandra Sekar.S

On Wed, Dec 7, 2016 at 10:24 AM, Chandru  wrote:

> I can understand db/sql using Context for cancellation. It is the optional
> arguments to BeginContext like IsolationLevel and read-only flag, which are
> not request-specific, that seem to contradict context's documentation.
>
> --
> Chandra Sekar.S
>
> On Tue, Dec 6, 2016 at 9:50 PM,  wrote:
>
>> Either the doc should be changed or the std lib should follow the spirit
>> of the doc. But my understanding is that context.Context is not just about
>> HTTP request/response cycle but deals with anything that needs cancellation
>> or a resource clean up signal , some kind of DIY RAII . In any case the
>> documentation should be clarified.
>>
>> Le mardi 6 décembre 2016 16:48:48 UTC+1, Chandra Sekar S a écrit :
>>>
>>> Documentation of the context package says,
>>>
>>> "Use context Values only for request-scoped data that transits processes
>>> and APIs, not for passing optional parameters to functions."
>>>
>>> sql.BeginContext introduced in 1.8, uses Context to receive options like
>>> IsolationLevel and read-only flag. These are neither request-specific nor
>>> cross-cutting. They are options that are typically specific to a type of
>>> operation, but common to all requests.
>>>
>>> Isn't this use in db/sql contradicting the recommendation in context's
>>> doc?
>>>
>>> --
>>> Chandra Sekar.S
>>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.