[go-nuts] Re: Crash after sending thousands of http requests (go version go1.8.3 windows/amd64)

2017-06-05 Thread brainman
> Exception 0xc005 0x0 0x 0x7ffbea7bc8eb 
> PC=0x7ffbea7bc8ebx 
> 
> syscall.Syscall6(0x7ffbea7b8a80, 0x4, 0x4, 0x1138ad0, 0xc04223d3d0, 
> 0xc04223d3e0, 0x0, 0x0, 0xc0422f1a00, 0x30002, ...) 
> C:/Go/src/runtime/syscall_windows.go:174 +0x6b 
> syscall.CertVerifyCertificateChainPolicy(0x4, 0x1138ad0, 0xc04223d3d0, 
> 0xc04223d3e0, 0x0, 0xc04249d3d8) 
> C:/Go/src/syscall/zsyscall_windows.go:1208 +0xc1 

You called CertVerifyCertificateChainPolicy Windows API, and Windows rasied 
ERROR_ACCESS_DENIED exception while executing your call. I suspect somehow 
your memory got corrupted. Can you provide a sample program that we could 
use to reproduce your error?

Alex

-- 
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: filago: Monitor a Linux process' opening and closing of files, including Unix pipes and sockets

2017-06-05 Thread Glen Newton
The functionality filago provides can be implemented with truss or strace. 

filago offers a simpler (to many) way of getting to this information, and 
can provide it in json as well.

Thanks,
Glen


On Monday, June 5, 2017 at 3:25:20 PM UTC-4, Simon Ritchie wrote:
>
> Does this have some advantage over truss (or under Linux, strace)?

-- 
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] Scheduler time profiling

2017-06-05 Thread Ian Lance Taylor
On Mon, Jun 5, 2017 at 4:24 PM,   wrote:
>
> Hi golang-nuts. I am trying to profile the runtime environment scheduler
> proc.go and have few questions.
>
> 1) I was wondering if the pprof profiler is good for profiling the runtime
> environment or would my numbers be skewed due to the overhead of pprof?

it should be fine.

> 2) regarding the GODEBUG. Till what granularity of time can i trust my
> GODEBUG debug logs?

I'm not sure how to answer this question as the GODEBUG logs generally
don't include any time markings anyhow.  When they do include time,
the time should be accurate and precise.

> 3) Right now, i am trying to understand the runtime especially the relation
> between G,M and P. I am using the _test.go files in src/runtime and taking
> the pprof/GODEBUG logs. Is this a good way to go about it?

It sounds hard.  The GODEBUG logs aren't really intended for that,
although you will something from GODEBUG=schedtrace=1.  I'm not sure
what knowledge you are starting from.  I wrote a brief intro on Quora
at 
https://www.quora.com/How-does-the-golang-scheduler-work/answer/Ian-Lance-Taylor
.

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] Re: filago: Monitor a Linux process' opening and closing of files, including Unix pipes and sockets

2017-06-05 Thread Glen Newton
Sorry about that: link to github: https://github.com/gnewton/filago

Thanks,
Glen

On Friday, June 2, 2017 at 11:56:34 PM UTC-4, Glen Newton wrote:
>
> Monitor open files (via /proc/pid) of a process. Lists time when it first 
> sees the file open (which may be later than when the file actually opened, 
> especially at startup of filago), and when it is no longer open. Stop 
> running when target process ends.
>
> This includes anon_inode and tcp and unix sockets.
>
>
> *Only works on Linux or OSes supporting /proc in this manner.*
>
>
> Usage of ./filago:
>   -d uint
>   Time granularity for checking files, in milliseconds (default 100)
>   -j  Output json (complete json per line)
>   -l  Turn on hostname lookup (default is a "-"
>   -r  Show only real files, i.e. no pipes, sockets, etc.
>
>
> Default simple text output as well as json output containing more 
> extensive information.
>
>
> Example text output on Firefox process:
>
>
> $ ./filago -l -j 3737
>
> 2017-05-07T12:40:40.663016-04:00 open socket:[416916] tcp 
> 198.252.206.25:443 stackoverflow.com. 
> 2017-05-07T12:40:40.663016-04:00 open anon_inode:[eventpoll] 
> 2017-05-07T12:40:40.663016-04:00 open socket:[511791] unix - 
> 2017-05-07T12:40:40.663016-04:00 open 
> /home/bsmith/.cache/event-sound-cache.tdb.9bf539dba0e34f7aaf456bd844b6826e.x86_64-redhat-linux-gnu
>  
>
> 2017-05-07T12:40:40.663016-04:00 open socket:[1265977] unix - 
> 2017-05-07T12:40:40.663016-04:00 open socket:[1574737] tcp 
> 173.194.175.189:443 qs-in-f189.1e100.net. 
> 2017-05-07T12:41:21.110231-04:00 close socket:[1630334] tcp 
> 52.84.139.212:80 server-52-84-139-212.yto50.r.cloudfront.net. 
> 2017-05-07T12:42:35.083678-04:00 open socket:[1635598] 
> 2017-05-07T12:42:35.155006-04:00 close socket:[1635598] 
> 2017-05-07T12:42:35.155006-04:00 open socket:[1630691] tcp 
> 172.217.6.229:443 lga25s55-in-f5.1e100.net.
>
>
> Example json output (complete json per line) on Firefox process:
>
>
> $ ./filago -l -j 3737
> {"filename":"socket:[95066]","type":"unix","socket_info":{"unix_socket":{"num":"8803e6c99f80","refcount":"0003","protocol":"","flags":"","type":"0001","st":"03","inode":95066}},"status":"open","mod_time":"1969-12-31T19:00:00-05:00"}
> {"filename":"socket:[95067]","type":"unix","socket_info":{"unix_socket":{"num":"8803e6c99c00","refcount":"0003","protocol":"","flags":"","type":"0001","st":"03","inode":95067}},"status":"open","mod_time":"1969-12-31T19:00:00-05:00"}
> {"filename":"pipe:[95068]","type":"pipe","status":"open","mod_time":"2017-06-02T23:20:10.616170585-04:00"}
> {"filename":"/home/bsmith/install/firefox/omni.ja","type":"file","status":"open","mod_time":"2017-05-27T23:24:59.740556075-04:00"}
> {"filename":"/home/bsmith/install/firefox/browser/omni.ja","type":"file","status":"open","mod_time":"2017-05-27T23:25:00.173556279-04:00"}
> {"filename":"pipe:[95069]","type":"pipe","status":"open","mod_time":"2017-06-02T23:19:57.685144488-04:00"}
> {"filename":"pipe:[110949]","type":"pipe","status":"open","mod_time":"2017-06-02T23:19:57.685144488-04:00"}
> {"filename":"socket:[95070]","type":"other","status":"open","mod_time":"1969-12-31T19:00:00-05:00"}
> {"filename":"pipe:[102268]","type":"pipe","status":"open","mod_time":"2017-06-02T23:20:13.688176034-04:00"}
> {"filename":"/home/bsmith/.mozilla/firefox/uqsr6u0q.default/extension-data/ublock0.sqlite","type":"file","status":"open","mod_time":"2017-06-02T23:19:09.638842227-04:00"}
> {"filename":"socket:[110951]","type":"unix","socket_info":{"unix_socket":{"num":"880403259c00","refcount":"0003","protocol":"","flags":"","type":"0001","st":"03","inode":110951}},"status":"open","mod_time":"1969-12-31T19:00:00-05:00"}
> {"filename":"anon_inode:[eventfd]","type":"anon_inode","status":"open","mod_time":"2017-06-02T22:20:43.18337-04:00"}
> {"filename":"anon_inode:inotify","type":"anon_inode","status":"open","mod_time":"2017-06-02T22:20:43.18337-04:00"}
>
> {"filename":"socket:[109319]","type":"tcp","socket_info":{"inode":109319,"tcp_socket":{"rem_hostname":"a23-63-227-177.deploy.static.akamaitechnologies.com.","sl":4,"local_port":58795,"remote_port":80,"st":1,"tr":1,"uid":1000,"tx_queue":296,"tm_when":21,"extra":"3","rem_address":"23.63.227.177","local_address":"192.168.0.101"}},"status":"close","mod_time":"1969-12-31T19:00:00-05:00"}
> {"filename":"socket:[106227]","type":"tcp","socket_info":{"inode":106227,"tcp_socket":{"rem_hostname":"a23-63-227-177.deploy.static.akamaitechnologies.com.","sl":1,"local_port":58796,"remote_port":80,"st":1,"tr":1,"uid":1000,"tx_queue":296,"tm_when":21,"extra":"3","rem_address":"23.63.227.177","local_address":"192.168.0.101"}},"status":"open","mod_time":"1969-12-31T19:00:00-05:00"}
> 

[go-nuts] Scheduler time profiling

2017-06-05 Thread akashina
Hi golang-nuts. I am trying to profile the runtime environment scheduler 
proc.go and have few questions.

1) I was wondering if the pprof profiler is good for profiling the runtime 
environment or would my numbers be skewed due to the overhead of pprof? 

2) regarding the GODEBUG. Till what granularity of time can i trust my 
GODEBUG debug logs? 

3) Right now, i am trying to understand the runtime especially the relation 
between G,M and P. I am using the _test.go files in src/runtime and taking 
the pprof/GODEBUG logs. Is this a good way to go about it?

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] Re: Is there any golang package available for building mongodb query from plain logic expression string or URL?

2017-06-05 Thread Ray Yang
Thanks for letting me know that "left-pad" thing. I didn't know it before 
you mentioned it here.

Parsing a URL string and constructing a BSON object are easy if the 
criteria is like this:

A.B="foo" AND C.D=true

However, if the query is like this, I'm not sure if it still can be done 
correctly without careful attention:

((A.B="foo" AND C.D=true) OR E.F="boo" AND G=1234) OR H.I.J IN "abc def xyz"

So what I meant was to target such complex situation which is commonly used 
in searching large data set. Really appreciate if somebody can point out 
that there is already something available or even some examples in Go.

Thanks.

On Monday, June 5, 2017 at 5:01:03 PM UTC-7, DV wrote:
>
> This seems pretty trivial, tbh. You just parse the URL query string and 
> construct a JSON doc out of it? 
>
> Go's philosophy in general is that it's better to just write the code 
> yourself sometimes, even multiple times, than to pull in a dependency. 
> Especially for something like this. 
>
> Do you remember the Node community's "left-pad" fiasco from last year? 
>
>

-- 
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] how to interpret debug/pprof/heap

2017-06-05 Thread Steven Roth
Hi, folks,

I'm trying to track down a memory leak in a web server application, and I'm
having a hard time making sense of the output of the heap dumps emitted by
the net/http/pprof handlers.  One of the dumps starts with:

heap profile: 5: 192080 [47408: 90679856] @ heap/1048576
1: 155648 [1: 155648] @ 0x583a0f ...
1: 32768 [1: 32768] @ 0x6f2aab ...
1: 2048 [1: 2048] @ 0x5b47ff ...

If I understand this correctly, there are 5 in-use objects on the heap,
taking up 192kB, and 47,408 allocated objects taking up 90MB.  And then
there is a line and a stack trace for each one of those 47,408, showing
where it was allocated.

Already this seems unbelievable:  I can't imagine a web server that's been
running for days could possibly only have 5 heap objects that are in use.
Perhaps I'm misunderstanding what "in use" means...

But where it really gets crazy is the comparison with the runtime.MemStats
at the bottom:
# Alloc = 5812304
# Sys = 20642040
# HeapAlloc = 5812304
# HeapSys = 12877824
# HeapIdle = 5267456
# HeapInuse = 7610368
# HeapReleased = 0
# HeapObjects = 54025
# Stack = 1146880 / 1146880
# MSpan = 95608 / 163840
# MCache = 7200 / 16384
# BuckHashSys = 4371655
# GCSys = 796672
# OtherSys = 1268785
# NextGC = 9006400
# NumGC = 14832

So, this says there's only 5.8MB allocated, where the top part said 90MB.
This says there are 7.6MB in use on the heap, where the top part said
192kB.  This says there are 54k objects on the heap, where the top part
said 47k.

I'm totally flummoxed at understanding these numbers, and particularly how
they correlate to the object list in the top part of the output.  I'd
greatly appreciate explanations, or pointers to same.

My real goal, BTW, is to compare two of these dumps, taken 12 hours apart,
and try to figure out where my memory is leaking.  But I can't be confident
of doing that when I clearly don't understand how to interpret the
numbers.  If the top half is correct and only 5 of my objects are in use, I
may not have a real memory leak at all — but in that case, why does
HeapAlloc keep growing?

Many thanks in advance...
Steve

-- 
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 any golang package available for building mongodb query from plain logic expression string or URL?

2017-06-05 Thread DV
This seems pretty trivial, tbh. You just parse the URL query string and 
construct a JSON doc out of it? 

Go's philosophy in general is that it's better to just write the code yourself 
sometimes, even multiple times, than to pull in a dependency. Especially for 
something like this. 

Do you remember the Node community's "left-pad" fiasco from last year? 

-- 
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: In-memory secondary index

2017-06-05 Thread Dragos Harabor
Something like this?
https://github.com/hashicorp/go-memdb

Though it may have more features than you need. Or features that you don't 
yet know you want :-)

On Monday, June 5, 2017 at 3:28:33 AM UTC-7, James Pettyjohn wrote:
>
> I'm loading a set of structs in memory and will be frequently using them 
> throughout the lifetime of the application and doing frequent 'queries' 
> against the set to get those where certain fields have certain values.
>
> Are there are any native go libraries which do this kind of sort of 
> "secondary index" on in memory data structures?
>
>

-- 
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: Confusing type rules

2017-06-05 Thread conrad via golang-nuts
Thanks both!

On Saturday, June 3, 2017 at 5:22:20 PM UTC-7, Xio Fen wrote:
>
> To answer the first point - the keyword is "*assignable*" here - an slice 
> []int{1,23} is not assignable to a slice []I where I is a type of int. See 
> https://golang.org/ref/spec#Assignability 
>
> ( also golang treats slices as types in themselves ie 
> https://golang.org/ref/spec#SliceType )
>
> ..However..
>
> This or very similar has definitely been asked before (including by me I'm 
> sure, maybe I should try to find the thread) - it does seem reasonable and 
> useful - but it doesn't work (and may never)
>
>  for example your suggestion would work very well with the whole fmt 
> package - which often takes []interface as parameters, and then reflects on 
> that array to find type .. however passing []int etc doesn't currently 
> work, and requires an 'annoying' intermediate assign of each element to the 
> interfacial struct.
>
> Some links to previous discussions (of the more general case using 
> []interface{} as the receiving type)
>
> https://groups.google.com/forum/#!topic/golang-nuts/0qWnorUuct8
>
> and
>
> https://groups.google.com/forum/#!topic/golang-nuts/yZqFmd7z82Y
>
> had reasonable discussions - the second also points out that this is 
> covered in the FAQ - maybe around here 
> https://golang.org/doc/faq#convert_slice_of_interface
>
>
> Personally I'd like to see this implemented too - it has good use.
>

-- 
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: Copy map with empty interfaces

2017-06-05 Thread Egon
On Monday, 5 June 2017 18:11:00 UTC+3, Chun Zhang wrote:
>
> Unfortunately it does not give any info. :(
>

Can you upload the code somewhere?

Other ideas:

1. set environment variable GODEBUG to cgocheck=2
2. try valgrind - maybe it picks something up (not sure how well it works)
3. try sanitizers - search `go build -msan`... I've never used it, but you 
can see some tests for it in 
https://github.com/golang/go/tree/master/misc/cgo/testsanitizers

Other than that, yeah... try to get the example as small as possible and so 
that you can show it.

+ Egon


> Thanks,
> Chun
>
> On Saturday, June 3, 2017 at 1:16:18 PM UTC-4, Egon wrote:
>>
>> Does race detector say something useful?
>>
>> On Friday, 2 June 2017 21:18:31 UTC+3, Chun Zhang wrote:
>>>
>>> I am trying to store some complicated data structure with a map, and 
>>> eventually search and use it. 
>>> Since the structure can change with different applications, and it has 
>>> to work with multiple thread, I defined a generic map like follows
>>>
>>> type IndexedMap struct {
>>> sync.RWMutex
>>> DataNode  map[interface{}]interface{}
>>> }
>>>
>>> Insert is defined as 
>>>
>>> func (m *IndexedMap) Insert(dataIndex interface{}, data interface{}) error {
>>>
>>>var err error
>>>
>>>m.Lock()
>>>
>>>//if the node exist
>>>if _, ok := m.DataNode[dataIndex]; ok {
>>>   m.Unlock()
>>>   return m.Update(dataIndex, data)
>>>} else {
>>>   //insert new node
>>>   m.DataNode[dataIndex] = data
>>>}
>>>
>>>m.Unlock()
>>>
>>>return err
>>> }
>>>
>>>
>>> ** For now, the data being inserted is a structure, not the pointer to 
>>> the structure and the key/index is a string.**
>>>
>>>
>>> Then when I need to find a piece of data, I tried to get a snapshot of 
>>> the database first and then look for it
>>>
>>> v, ok : = m.SnapShotData()[key] where
>>>
>>> func (m *IndexedMap) SnapShotData() map[interface{}]interface{} {
>>>
>>>ret := make(map[interface{}]interface{})
>>>
>>>m.Lock()
>>>for k, v := range m.DataNode {
>>>   ret[k] = v
>>>}
>>>m.Unlock()
>>>
>>>return ret
>>> }
>>>
>>>
>>> Then the data v is used to do other things, never modified though. 
>>>
>>> This works but the performance is abysmal when the database getting 
>>> large. So, I tried to search without copying 
>>>
>>> v, ok := m.DataSearch(key)
>>>
>>> func (m *IndexedMap) DataSearch(dataIndex interface{}) (interface{}, bool) {
>>>
>>>var data interface{}
>>>var ok bool
>>>
>>>m.Lock()
>>>
>>>data, ok = m.DataNode[dataIndex]
>>>
>>>m.Unlock()
>>>
>>>return data, ok
>>> }
>>>
>>>
>>>
>>> However, with this implementation, I always get crash after running the 
>>> program just a little bit with the following error
>>>
>>> *** Error in `./colordecoder': double free or corruption (fasttop): 
>>> 0x7f943c26f590 ***
>>> SIGABRT: abort
>>> PC=0x7f946c2eac37 m=4
>>> signal arrived during cgo execution
>>>
>>> I guess somewhere along the line the copy is a not a hard copy but just 
>>> a reference copy. However, I couldn't understand the difference between 
>>> above two approaches, seems that in SnapShotData I did exactly the same 
>>> thing, but no crash ever. 
>>>
>>> Can somebody tell me where I did wrong? 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] filago: Monitor a Linux process' opening and closing of files, including Unix pipes and sockets

2017-06-05 Thread Simon Ritchie
Does this have some advantage over truss (or under Linux, strace)?

-- 
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] {CGO,VM}-free SQLite (ATM Linux/Intel only, pre-alpha)

2017-06-05 Thread Jan Mercl
https://github.com/cznic/sqlite

-- 

-j

-- 
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 get in parallel

2017-06-05 Thread mhhcbon
hi,

in immediate terms, assuming you have something like
go get a
go get b
go get c

Can this https://github.com/mh-cbon/cct#usage be of help ?

I did not tested, but it should be,

cct -add -timeout 20 go get a
cct -a 1 go get b
...

cct -wait 1


I m sorry it looks likes i have not implemented exit code management yet
https://github.com/mh-cbon/cct/issues/1 ... : /

On Monday, June 5, 2017 at 6:43:34 PM UTC+2, David Prime wrote:
>
> Hi All,
>
> I've got a few jenkins jobs that end up doing quite a lot of go-getting as 
> part of a clean build process. I find the slowest bit of the whole process 
> is go get sequentially resolving/downloading everything. Would making this 
> parallel be doable? Would it be desirable? Am I doing something wrong in 
> the first place which means I probably shouldn't need parallel getting?
>
> Thanks,
> 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] go get in parallel

2017-06-05 Thread Ian Lance Taylor
On Mon, Jun 5, 2017 at 8:14 AM,   wrote:
>
> I've got a few jenkins jobs that end up doing quite a lot of go-getting as
> part of a clean build process. I find the slowest bit of the whole process
> is go get sequentially resolving/downloading everything. Would making this
> parallel be doable? Would it be desirable? Am I doing something wrong in the
> first place which means I probably shouldn't need parallel getting?

I think that most people vendor their dependencies to avoid the
left-pad problem.  That said, I agree that `go get` ought to download
multiple arguments, and dependencies, in parallel.  It's not a trivial
change to the code, but it's certainly something someone could work on
for the 1.10 release.  It's https://golang.org/issue/11821.

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] Crash after sending thousands of http requests (go version go1.8.3 windows/amd64)

2017-06-05 Thread Cheyi Lin
Hi,

I’m writing a http poller that send concurrent HTTP requests to
retrieve the monitoring data, put the results into a queue then
consume them by several workers that send HTTP requests to our log
aggregators.

At the beginning everything works well, about 9 hours later the
program crashes and leaves the following messages:

The weird thing I don’t understand is that there is no panic or system
level messages.

Exception 0xc005 0x0 0x 0x7ffbea7bc8eb
PC=0x7ffbea7bc8ebx

syscall.Syscall6(0x7ffbea7b8a80, 0x4, 0x4, 0x1138ad0, 0xc04223d3d0,
0xc04223d3e0, 0x0, 0x0, 0xc0422f1a00, 0x30002, ...)
C:/Go/src/runtime/syscall_windows.go:174 +0x6b
syscall.CertVerifyCertificateChainPolicy(0x4, 0x1138ad0, 0xc04223d3d0,
0xc04223d3e0, 0x0, 0xc04249d3d8)
C:/Go/src/syscall/zsyscall_windows.go:1208 +0xc1
crypto/x509.checkChainSSLServerPolicy(0xc04238d200, 0x1138ad0,
0xc04223d808, 0x38e8f10, 0xc04249d548)
C:/Go/src/crypto/x509/root_windows.go:117 +0xfd
crypto/x509.(*Certificate).systemVerify(0xc04238d200, 0xc04249d808,
0x0, 0x0, 0x0, 0x0, 0x0)
C:/Go/src/crypto/x509/root_windows.go:212 +0x484
crypto/x509.(*Certificate).Verify(0xc04238d200, 0xc042448940, 0x13,
0xc042251500, 0x0, 0xed0c3b03e, 0x25245214, 0xbb0b80, 0x0, 0x0, ...)
C:/Go/src/crypto/x509/verify.go:279 +0x86c
crypto/tls.(*clientHandshakeState).doFullHandshake(0xc04223de50,
0xc042203380, 0x51)
C:/Go/src/crypto/tls/handshake_client.go:300 +0x4c0
crypto/tls.(*Conn).clientHandshake(0xc0422ef500, 0x969ae0, 0xc0422ef620)
C:/Go/src/crypto/tls/handshake_client.go:228 +0xf97
crypto/tls.(*Conn).Handshake(0xc0422ef500, 0x0, 0x0)
C:/Go/src/crypto/tls/conn.go:1307 +0x1aa
net/http.(*Transport).dialConn.func3(0x0, 0xc0422ef500, 0xc04200e9c0,
0xc0424201e0)
C:/Go/src/net/http/transport.go:1082 +0x49
created by net/http.(*Transport).dialConn
C:/Go/src/net/http/transport.go:1087 +0xff3
...

This is the main program, blocked by channel selecting, waiting for
signals. (SIGINT, SIGTERM and SIGQUIT)

goroutine 1 [chan receive, 732 minutes]:
cheyi/myprog/lib/poller.main(0xc042079b00, 0xc042146940, 0x0, 0x4)
D:/Golang/src/cheyi/myprog/lib/poller/entry.go:52 +0x17c
cheyi/myprog/vendor/github.com/spf13/cobra.(*Command).execute(0xc042079b00,
0xc042146900, 0x4, 0x4, 0xc042079b00, 0xc042146900)
D:/Golang/src/cheyi/myprog/vendor/github.com/spf13/cobra/command.go:648
+0x23b
cheyi/myprog/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xba9fc0,
0xc04201c0b8, 0x0, 0x1)
D:/Golang/src/cheyi/myprog/vendor/github.com/spf13/cobra/command.go:734
+0x340
cheyi/myprog/vendor/github.com/spf13/cobra.(*Command).Execute(0xba9fc0,
0x850bc3, 0x946c4b)
D:/Golang/src/cheyi/myprog/vendor/github.com/spf13/cobra/command.go:693
+0x32
cheyi/myprog/cmd.Execute()
D:/Golang/src/cheyi/myprog/cmd/entry.go:28 +0x38
main.main()
D:/Golang/src/cheyi/myprog/main.go:11 +0x27

goroutine 5 [syscall, 732 minutes]:
os/signal.signal_recv(0x0)
C:/Go/src/runtime/sigqueue.go:116 +0x10b
os/signal.loop()
C:/Go/src/os/signal/signal_unix.go:22 +0x29
created by os/signal.init.1
C:/Go/src/os/signal/signal_unix.go:28 +0x48
...

After the backtrace of poller and output worker goroutines are the
backtrace of http related goroutines

goroutine 58972 [IO wait]:
net.runtime_pollWait(0x32b0780, 0x72, 0xb74500)
C:/Go/src/runtime/netpoll.go:164 +0x60
net.(*pollDesc).wait(0xc042408a60, 0x72, 0xb74500, 0x0)
C:/Go/src/net/fd_poll_runtime.go:75 +0x3f
net.(*ioSrv).ExecIO(0xc0421ea008, 0xc042408920, 0x949b9c, 0x7,
0x9692d0, 0x1, 0x0, 0xc04295d820)
C:/Go/src/net/fd_windows.go:196 +0xfe
net.(*netFD).Read(0xc0424088c0, 0xc04249e000, 0x2000, 0x2000, 0x0, 0x0, 0x0)
C:/Go/src/net/fd_windows.go:452 +0x13d
net.(*conn).Read(0xc042232158, 0xc04249e000, 0x2000, 0x2000, 0x0, 0x0, 0x0)
C:/Go/src/net/net.go:181 +0x77
crypto/tls.(*block).readFromUntil(0xc04219c6c0, 0x32b0fc0,
0xc042232158, 0x5, 0xc042232158, 0x4200da00)
C:/Go/src/crypto/tls/conn.go:488 +0x9f
crypto/tls.(*Conn).readRecord(0xc0423a4000, 0xc04295db14, 0x52dd0e,
0xc0424088c0)
C:/Go/src/crypto/tls/conn.go:590 +0xcb
crypto/tls.(*clientHandshakeState).readFinished(0xc04295de50,
0xc0423a40f5, 0xc, 0xc, 0x0, 0x0)
C:/Go/src/crypto/tls/handshake_client.go:584 +0x5a
crypto/tls.(*Conn).clientHandshake(0xc0423a4000, 0x969ae0, 0xc0423a4120)
C:/Go/src/crypto/tls/handshake_client.go:244 +0x10a6
crypto/tls.(*Conn).Handshake(0xc0423a4000, 0x0, 0x0)
C:/Go/src/crypto/tls/conn.go:1307 +0x1aa
net/http.(*Transport).dialConn.func3(0x0, 0xc0423a4000, 0xc042146e80,
0xc04218ee40)
C:/Go/src/net/http/transport.go:1082 +0x49
created by net/http.(*Transport).dialConn
C:/Go/src/net/http/transport.go:1087 +0xff3

goroutine 58945 [select]:
net/http.setRequestCancel.func3(0x0, 0xc0421b87b0, 0xc04200e8c0,
0xc0421b689c, 0xc0421b59e0)
C:/Go/src/net/http/client.go:320 

[go-nuts] Re: Golang, SQL and ORM avoidance techniques

2017-06-05 Thread Ren Thraysk

Wrote something similar recently.

One difference is that I moved the rows.Scan call into the passed in 
function.


type Scannable interface {
  Scan(...interface{}) error
}

func scanIntoUser(u *store.User) func(s Scannable) error {
 return func(s Scannable) error {
 return s.Scan(, , , )
 }
}

func (s *userStore) UserByName(name string) (*store.User, error) {
 u := {}
 err := ExpectOneRow(s.db, scanIntoUser(u), "CALL spUserByName(?)", name)
 if err != nil {
 return nil, err
 }
 return u, nil
}


 Idea being gives an opportunity to do some mapping by scanning into local 
variables and then assign them into the object, for instance dealing with 
NULLs. Scan into a sql.Null* variable, and modify whatever struct as see 
appropriate.

Ren




On Friday, 2 June 2017 13:55:12 UTC+1, brylant wrote:
>
>
> I've been trying hard (well.. as much as I can considering my lack of 
> in-depth go knowledge or - to be perfectly honest - lack of in-depth 
> knowledge of anything) to find suitable go+sql technique that would not 
> require a lot of code repetition, not use reflection and not use ORMs of 
> any sort... Could somebody please tell me if there's anything particularly 
> wrong with the following:
>
>
> type ScannerFunc func() []interface{}
>
> func (db *DB) ScanSome(stmt string, sf ScannerFunc, params ...interface{}) 
> error {
>  rows, err := db.Query(stmt, params...)
>  if err != nil {
>  return err
>  }
>  defer rows.Close()
>  for rows.Next() {
>  err = rows.Scan(sf()...)
>  if err != nil {
>  return err
>  }
>  }
>  if err = rows.Err(); err != nil {
>  return err
>  }
>  return nil
> }
>
> Having the above I could then implement the following for each of my 
> 'models' (User being an example below). This could easily be 'go 
> generate'-d for each model
>
>
> type User struct {
> UserID  int64
> Namestring
> Roleint
> // (...)
> }
>
> func ScanUsersFunc(users *[]*User) ScannerFunc {
> return ScannerFunc(func() []interface{}) {
> u := User{}
> *users = append(*users, )
> var r []interface{} = []interface{}{, , , 
> (more 
> properties)}
> return r
> }
> }
>
>
> and finally use it like this: 
>
>
> const (
> sqlUsersByRole = "SELECT user_id,name,role, (more if needed) FROM 
> user WHERE role=?"
> sqlAllUsers= "SELECT user_id,name,role FROM user"
> )
>
> func (db *DB) UsersByRole(role int) ([]*User, error) {
> users := make([]*User, 0)
> err := db.ScanSome(sqlUsersByRole, ScanUsersFunc(), role)
> if err != nil {
> return nil, err
> }
> return users, nil
> }
>
> func (db *DB) AllUsers() ([]*User, error) {
> users := make([]*User, 0)
> err := db.ScanSome(sqlAllUsers, ScanUsersFunc())
> if err != nil {
> return nil, err
> }
> return users, nil
> }
>
>
> Alternatively (to avoid scanning/returning all results) a callback could 
> be provided to ScanSome and called after each scan.
>
> Obviously I could also implement ScanOne for situations where I only 
> expect one row of results...
>
>
> So - any obvious issues with the above 'technique'...?
>
>
> Thanks,
>
> adam
>
>
>
>

-- 
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] go get in parallel

2017-06-05 Thread david
Hi All,

I've got a few jenkins jobs that end up doing quite a lot of go-getting as 
part of a clean build process. I find the slowest bit of the whole process 
is go get sequentially resolving/downloading everything. Would making this 
parallel be doable? Would it be desirable? Am I doing something wrong in 
the first place which means I probably shouldn't need parallel getting?

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


[go-nuts] Re: Copy map with empty interfaces

2017-06-05 Thread Tamás Gulácsi
Can you simplify it with map[string]interface{}?

Otherwise, the error indicates impedance mismatch between C++ and Go.
This is hard to debug - put printf everywhere, print the 
allocated/freed/sent/received pointers (%p), and _reduce_ the program 
line-by-line, till the error vanishes.

-- 
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: Copy map with empty interfaces

2017-06-05 Thread Chun Zhang
Hi, Tamas,

Thanks for the reply!

The key is a string for my current use. 

After the data v is retrieved, it is compared with a new data coming from 
the wire. And then based on the comparison, the new data, which is a newly 
created piece of memory contains same type of data, will be sent to a C++ 
library for further processing.  The database is then updated after the 
processing, using the insert/update method. 

Best Regards,
Chun


On Saturday, June 3, 2017 at 2:54:27 AM UTC-4, Tamás Gulácsi wrote:
>
> How is cgo involved here? What kind of keys are you using?

-- 
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: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-06-05 Thread Egon
On Monday, 5 June 2017 16:26:25 UTC+3, utyug...@mail.com wrote:
>
> I gave you a simple problem, don't over think it. A Set data structure 
> with a simple api that can work out-of-the-box - just as slices and maps 
> with the builtins. I kept the requirements minimal. I'd like to see your 
> solution.
>

As I've already mentioned, my current problem-free approach is not 
out-of-the-box solution. Maybe, you misunderstood what I meant by 
problem-free. I mean that this is something I don't care about when writing 
code and the workaround is trivial-low-effort work...

I didn't know what the set was intended for; so I wasn't able to add 
Universe -- or don't have a good idea how you would construct one in Go for 
infinite constrained type. Not sure what you meant by superset/subset; -- 
if that one set contains another set, then there would be more code similar 
to Add/Sub. If you meant a superset that returns all possible supersets, 
then it would need Universe.

By no means I would consider it a good set implementation / API, but since 
that wasn't one of the criteria.



I ran into 3/4 bugs while renaming types:
1. I forgot to save the file.
2. I forgot to remove the original set entry type.
3. I forgot what the original set api was
4. Confused a,b,c and x,y in the demo.

At the moment I had to specially write generic code for Set, because it 
seems in ~5 years I've never found it worthwhile to write one. I had a 
delta-encoded intset, sparse-set, different bitset implementations, but 
nothing else.

I know the video is not 3minutes long, the rest of 3-minutes I would have 
used for searching the general purpose set, if I had one.

*Depending on the situation the actual approach may vary..*

+ Egon

On Monday, June 5, 2017 at 12:52:47 AM UTC-4, Egon wrote:
>>
>>
>>
>> On Monday, 5 June 2017 06:59:46 UTC+3, utyug...@mail.com wrote:
>>>
>>>
>>>
>>> On Sunday, June 4, 2017 at 12:25:17 PM UTC-4, Egon wrote:

 I think you are missing the point of my comment.

 I'm all for generics, but I also can survive without them without much 
 of a problem. (I'm even maintaining 
 https://docs.google.com/document/d/1vrAy9gMpMoS3uaVphB32uVXX4pi-HnNjkMEgyAHX4N4
  
 to understand the problem better)

>>>
>>> create a custom container type that I can use with any type 
>>> out-of-the-box.
>>>
>>> for example: iset := make(Set[int],9); sset := make(Set[string],9); pset 
>>> := make(Set[Person]);
>>>
>>> right now, my solution is to rewrite the source with go generate calling 
>>> a tool i wrote which grew out from a great talk from robert griesemer. The 
>>> video: https://www.youtube.com/watch?v=vLxX3yZmw5Q
>>>
>>> This solution has nearly twice the performance increase over maps with 
>>> almost every type used so far. Now I could have just written the 500 lines 
>>> of code over and over again for every type needed until the end of time(or 
>>> copy and paste and edit until the end of time), or I could use empty 
>>> interfaces which throws type safety out the window, but I chose to write a 
>>> tool, and when go generate came to be I chose to use that tool like a 
>>> simple script executed within a '//go:generate go run..' tag.
>>>
>>>
>>> Over time golang(I do this now to annoy the zealots) provided the 
>>> tools(reflection, /go packages, go generate) that made creating custom 
>>> generic type safe containers easier. These things weren't always this easy, 
>>> and these things could be easier.
>>>
>>> And I am serious about create a custom container type that I can use 
>>> with any type out-of-the-box. Please indulge me, how would you solve this 
>>> problem. Provide a solution for a simple type-safe container type Set that 
>>> takes any type, with a simple api of 
>>> insert,remove,contain,union,difference,intersection, 
>>> complement,superset,subset.
>>>
>>
>> I would use copy-paste. That action to specialize and clean-up API is 
>> pretty trivial, it might take me 3min (probably less), but it isn't a 
>> problem. I often spend more time on tweaking CSS or figuring out what the 
>> customer needs. Copy-pasteing code is annoying, but it's trivial low-effort 
>> work... so it's not a problem. *There of course are probably domains 
>> where this 3min might be a problem*. Then you might use a 
>> reflect/interface based solution and create a type-safe wrapper. Or use 
>> code-generation.
>>
>> 3min writing code, isn't a problem for me.
>>
>> There's also a subtle problem here, I consider 
>> "insert,remove,contain,union,difference,intersection,complement,superset,subset"
>>  
>> API somewhat unclear... it loses domain knowledge and may provide more 
>> functions than strictyl necessary... this of course it depends on the 
>> context.
>>
>> Also, where will this set be used? Set data-structures have a ton of 
>> different trade-offs. I really 

[go-nuts] Re: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-06-05 Thread mhhcbon


On Sunday, June 4, 2017 at 6:25:17 PM UTC+2, Egon wrote:
>
> I think you are missing the point of my comment.
>
> I'm all for generics, but I also can survive without them without much of 
> a problem. (I'm even maintaining 
> https://docs.google.com/document/d/1vrAy9gMpMoS3uaVphB32uVXX4pi-HnNjkMEgyAHX4N4
>  
> to understand the problem better)
>

that s actually a good pointer.
 

>
> The issue I was trying to highlight was that you are proposing solutions 
> to a problem, but other people don't know what your exact problem is. Hence 
> my 3 lines version are equivalent in their result and value, because the 
> problem is missing. 
>
 
if i m right you argue the fact i did not come up with a complete 
formalized approach.
I did not intended to, i think i tried to force open door of what is hiding 
under the noise, to think out loud.
In the end i expect to either provide one example where its a definitive 
no-go and its possible to explain why.
or sufficient expected real world use cases to start consider it for later 
implementation.
But in one-way-communication this obviously can not happen.
 

>
> Similarly, when we don't have a concrete problem we could over-engineer 
> the generics or alternatively solve the wrong problems.
>
> For example, when the solution you propose only solves 5% of the problems 
> that generics needs to solve... or vice-versa... a generics solution 100x 
> simpler would solve 99% of the cases... then what is the value of the 
> proposed solution?
>
> So, which of the 147 different generics approaches/implementations works 
> better for Go and why? (I'm also counting the ones that aren't known yet :D)
>
> When you would use a real-world example and problem, it would be possible 
> to argue that one approach is better than the other... without one, this 
> discussion doesn't lead to anywhere.
>
> + Egon
>
>
Just to clarify, 
i m not really in favor of generics per se,
i have enough to deal with right now to not add more complexity here.
In *here* I mean both declarer and consumer sides of an api programming.

But still i can t go with the existing, 
so i did try to solve the problem on my hand, 
but it happens it simply require a more in depth solution, 
the current superficial solution i can think about will always be limited 
by what has been well resumed earlier by utyug 
"or I could use empty interfaces which throws type safety out the window".
 

> On Sunday, 4 June 2017 19:09:17 UTC+3, mhh...@gmail.com wrote:
>>
>> given the fact that actually everybody disagrees on that idea, 
>> or even something similar according to some feedback.
>>
>> I want to put the question differently.
>>
>> My mean is to say that golang is a basis to build upon in general that is 
>> better
>> than other existing solutions.
>>
>> imho, golang is governed by its compatibility requirement,
>> and, an extremely vertical approach,
>> which blocks every possible update to the dogma: 
>> is it go 1.0 compatible ?
>>
>> And because its vertical, is it to my taste ?
>>
>> The go 1.0 compatibility requirement makes everybody very happy.
>>
>> Still, I dont believe the language is considered as finalized by a 
>> majority of users.
>> Some will say it misses generics, some other (..) will try different 
>> approach.
>>
>> Why should it be that much of frictions ?
>>
>> Why can t we evaluate a solution where multiple vision co exists ?
>> Handle the change.
>>
>> Aint there existing case of such kind of symbiosis which benefits each 
>> other on the long term ?
>>
>> A solution where the go 1.0 requirement is kept valuable, 
>> and a new language target where this requirement has been removed.
>> A transpiler to go 1.0 compatible code ? 
>> So both can exist ?
>>
>> my 2 cents, 
>> that close and negative answer i got,
>> is not helpful nor inclusive,
>> its like take or leave attitude,
>>
>> it d just be more inclusive to say that 
>> it is ok to make a transpiler/or whatever it should be/ implementing your 
>> idea, 
>> check that resource for further implementation come back here for 
>> questions.
>>
>> Other consideration, 
>> the idea that golang 1.0 is used to build a different language target 
>> that compiles back to go1.0, 
>> looks cool.
>>
>> On Saturday, June 3, 2017 at 6:24:31 PM UTC+2, mhh...@gmail.com wrote:
>>>
>>> for the fun, with early return,
>>>
>>> https://play.golang.org/p/I9AORKOYQm
>>>
>>> On Saturday, June 3, 2017 at 12:34:15 PM UTC+2, mhh...@gmail.com wrote:

 > Generics enable more than just replacing loops. For example, they can 
 enable libraries of generic algorithms to be used with any type of array. 
 Here's an example:

 in my demonstration every type got this kind of method,
 the problem become how do you jump from Type A to type B.
 in []A to []B or A -> B

 indeed it works on the item level, no more on the collections.

 This question is solved in two ways,
 - interface definitions (not interface value)
 - static 

[go-nuts] Re: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-06-05 Thread mhhcbon
as anyway the thread has completely derived,
its the right place to put about that.

I recently read about stanford choosing to use JS over Java
for some its courses.
https://www.theregister.co.uk/2017/04/24/stanford_tests_javascript_in_place_of_java/

I can t understand.
If a beginner ask me which language he should learn,
i d say go,
i d say him, stay put, its unfortunately not easy to enter, but its gonna 
be a great learning place.

I was an heavy user of javascript, 
i loved it for its stream api,
i hated it because of its stream api.

I say its not a good language for beginners,
its apparent ease hides a much greater complexity,
and it does not teach the traditional programming science,
but it has those good things like 
its a local problem solver rather than a define all the world approach.

Anyway, my point is to say that i see in this decision of the stanford 
university 
the proof that something has to happen.

THey were teaching Java before, how it come they chosen JS over go ?

On Wednesday, May 24, 2017 at 9:52:27 AM UTC+2, mhh...@gmail.com wrote:
>
> see the title, only for what s needed 
> Slice/Splice/Each/Map/First/Last/Reverse/Sort ect ect not len, for reason. 
> so interface system serves the userland by its definition of struct, and 
> the basic slice type provided by the language is fully operational, without 
> breaking, btw. i don t go further in evaluation, i leave that to the 
> reader, just trying to work decently.
>

-- 
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: idea: generic methods on slices with some generic type support []string.Map(string) []string => [].Map() []

2017-06-05 Thread mhhcbon
I want to emphases that go generate 
is so far an awesome solution, 
but not a definitive answer.

Yes, it could made easier,
about that, its already great that all the tools we need 
are written in go itself, this is really really really helpful.

On Monday, June 5, 2017 at 5:59:46 AM UTC+2, utyug...@mail.com wrote:
>
>
>
> On Sunday, June 4, 2017 at 12:25:17 PM UTC-4, Egon wrote:
>>
>> I think you are missing the point of my comment.
>>
>> I'm all for generics, but I also can survive without them without much of 
>> a problem. (I'm even maintaining 
>> https://docs.google.com/document/d/1vrAy9gMpMoS3uaVphB32uVXX4pi-HnNjkMEgyAHX4N4
>>  
>> to understand the problem better)
>>
>
> create a custom container type that I can use with any type out-of-the-box.
>
> for example: iset := make(Set[int],9); sset := make(Set[string],9); pset 
> := make(Set[Person]);
>
> right now, my solution is to rewrite the source with go generate calling a 
> tool i wrote which grew out from a great talk from robert griesemer. The 
> video: https://www.youtube.com/watch?v=vLxX3yZmw5Q
>
> This solution has nearly twice the performance increase over maps with 
> almost every type used so far. Now I could have just written the 500 lines 
> of code over and over again for every type needed until the end of time(or 
> copy and paste and edit until the end of time), or I could use empty 
> interfaces which throws type safety out the window, but I chose to write a 
> tool, and when go generate came to be I chose to use that tool like a 
> simple script executed within a '//go:generate go run..' tag.
>
>
> Over time golang(I do this now to annoy the zealots) provided the 
> tools(reflection, /go packages, go generate) that made creating custom 
> generic type safe containers easier. These things weren't always this easy, 
> and these things could be easier.
>
> And I am serious about create a custom container type that I can use with 
> any type out-of-the-box. Please indulge me, how would you solve this 
> problem. Provide a solution for a simple type-safe container type Set that 
> takes any type, with a simple api of 
> insert,remove,contain,union,difference,intersection, 
> complement,superset,subset.
>
> I've seen you provide solutions in the past, so I would like to see your 
> solution to this not-much-of-a-problem.
>  
>
>>
>> The issue I was trying to highlight was that you are proposing solutions 
>> to a problem, but other people don't know what your exact problem is. Hence 
>> my 3 lines version are equivalent in their result and value, because the 
>> problem is missing.
>>
>> Similarly, when we don't have a concrete problem we could over-engineer 
>> the generics or alternatively solve the wrong problems.
>>
>> For example, when the solution you propose only solves 5% of the problems 
>> that generics needs to solve... or vice-versa... a generics solution 100x 
>> simpler would solve 99% of the cases... then what is the value of the 
>> proposed solution?
>>
>> So, which of the 147 different generics approaches/implementations works 
>> better for Go and why? (I'm also counting the ones that aren't known yet :D)
>>
>> When you would use a real-world example and problem, it would be possible 
>> to argue that one approach is better than the other... without one, this 
>> discussion doesn't lead to anywhere.
>>
>> + Egon
>>
>> On Sunday, 4 June 2017 19:09:17 UTC+3, mhh...@gmail.com wrote:
>>>
>>> given the fact that actually everybody disagrees on that idea, 
>>> or even something similar according to some feedback.
>>>
>>> I want to put the question differently.
>>>
>>> My mean is to say that golang is a basis to build upon in general that 
>>> is better
>>> than other existing solutions.
>>>
>>> imho, golang is governed by its compatibility requirement,
>>> and, an extremely vertical approach,
>>> which blocks every possible update to the dogma: 
>>> is it go 1.0 compatible ?
>>>
>>> And because its vertical, is it to my taste ?
>>>
>>> The go 1.0 compatibility requirement makes everybody very happy.
>>>
>>> Still, I dont believe the language is considered as finalized by a 
>>> majority of users.
>>> Some will say it misses generics, some other (..) will try different 
>>> approach.
>>>
>>> Why should it be that much of frictions ?
>>>
>>> Why can t we evaluate a solution where multiple vision co exists ?
>>> Handle the change.
>>>
>>> Aint there existing case of such kind of symbiosis which benefits each 
>>> other on the long term ?
>>>
>>> A solution where the go 1.0 requirement is kept valuable, 
>>> and a new language target where this requirement has been removed.
>>> A transpiler to go 1.0 compatible code ? 
>>> So both can exist ?
>>>
>>> my 2 cents, 
>>> that close and negative answer i got,
>>> is not helpful nor inclusive,
>>> its like take or leave attitude,
>>>
>>> it d just be more inclusive to say that 
>>> it is ok to make a transpiler/or whatever it should be/ implementing 
>>> your idea, 
>>> check that 

[go-nuts] Re: Need some help on my basic "Backup size" calculator

2017-06-05 Thread Egon
See filepath.Walk (https://golang.org/pkg/path/filepath/#Walk)

If you wish to recurse with ioutil.ReadDir or File.Readdir 
(https://golang.org/pkg/os/#File.Readdir), you have to do it manually.

Nested structs -- it depends what you are doing.

I would simplify it to:

type Stat struct {
FileCount int64
DirCount  int64
Bytes int64
}

When I want to keep per directory, then I would use:

type Info struct {
Pathstring
Total   Stat
Current Stat
Dirs[]Info
}

type Stat struct {
FileCount int64
DirCount  int64
Bytes int64
}

Btw. have you done the Go tour? (https://tour.golang.org/moretypes/1)

On Monday, 5 June 2017 08:38:59 UTC+3, Giovanni Francesco wrote:
>
> Hi there,
>
> I'm very new to Golang, and quite honestly haven't coded in a long time so 
> bear with me if this is an very basic question.
>
> I'm trying to build a basic backup program, which will take a path 
> (string) and then calculate the total "backup size" of the entire backup 
> (and all the child folders, etc).
>
> I found out by starting to write the basics of the program that 
> ioutil.ReadDir does not recursively go deeper into child folders so the 
> code I will show you is only calculating the size for any files in the root 
> only.
>
> I already have an idea on how to fix it but I have a much deeper question: 
> would using nested structs be a good idea?
>
> I'm basically defining the program like so:
>
> type Backup struct {
> Files
> Directories
> byteSize int64
> humanSize string
> }
>
> type Directories struct {
> name string
> containsBytes float64
> constainsFiles int64
> }
>
> type Files struct {
> parent Directories
> name string
> byteSize int64
> humanSize string
> }
>
> Do I need to make "Directories" and "Files" be a slice / map or something 
> for my purposes? I am a little confused here and I don't know how I could 
> make my struct (which holds multiple values) be an array/slice, how would 
> that work?
>
> What if I wanted to "search" for a file or folder later on my program? 
>
> My code that works for top-level folder calculation: 
> https://gist.github.com/TheLinuxGuy/2dd8ed958d14c491bf86e2f5f3d4688d
>
> Thanks!
> Giovanni
>

-- 
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.