Re: [go-nuts] what is the best way to to convert c++ std::string to go string in cgo programing?

2017-04-19 Thread hui zhang
for  1) you mean
>
> char *CGetPath() {
> return getpath().c_str();
>   }


this code will work ?

2017-04-19 14:43 GMT+08:00 Konstantin Khomoutov <
flatw...@users.sourceforge.net>:

> On Wed, 19 Apr 2017 14:23:09 +0800
> hui zhang  wrote:
>
> > 1)   getpath()  return a temp string,  its  c_str() pointer will be
> > free out of function. So I use malloc
>
> I'm not completely sure you're correct.  C++ does not implement garbage
> collection and the object on which you have called c_str() continues to
> live on after getpath() returns.  Now let's cite the manual on c_str():
>
> | The pointer obtained from c_str() may be invalidated by:
> | * Passing a non-const reference to the string to any standard library
> |   function, or
> | * Calling non-const member functions on the string, excluding
> |   operator[], at(), front(), back(), begin(), rbegin(), end() and
> |   rend().
>
> So I'd say in the sequence of calls I propose there's no chance of
> anything quoted to happen -- basically the pointer returned by c_str()
> gets passed to Go where C.GoString() copies the memory pointed to by it.
>
> Things may break if you somehow concurrently call into your C++ side
> and those calls may access the same std::string object we're talking
> about.  But if you do this, all bets are already off.
>
> > 2)  Assume we use the malloc way ,  are  C.GoString()   copying the
> > pointer memory ?  for we need C.free() malloc memory.
>
> Yes, C.GoString() copies the memory.
>
> Yes, you always need to free() what was malloc()ed for you -- because
> you own the returned pointer.
>

-- 
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: os.Getwd() on windows changes drive letter casing

2017-04-19 Thread Andreas Reuterberg
I've written a fix for the easyjson library using filepath functions, so 
I'm not worried about that. But I did expect os.Getwd() to return the same 
exact string, regardless of how the test is run.

"go test . -v" os.Getwd() uses the GOPATH variable
"go test . -c" results in a binary where os.Getwd() does not rely on the 
GOPATH variable, or converts the volume name to upper case.

os.TempDir(), for example, does not alter the volume name letter case 
depending on how it's executed. So it's a bit odd.

Andreas

On Tuesday, 18 April 2017 14:03:51 UTC+1, peterGo wrote:
>
> Andreas,
>
> To fix the easyjson library, please provide a simple recipe for 
> reproducing the error. A complete runnable program is good. A link on 
> play.golang.org is best. What did you expect to see? What did you see 
> instead?
>
> Peter
>
>

-- 
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] what is the best way to to convert c++ std::string to go string in cgo programing?

2017-04-19 Thread Frits van Bommel
On Wednesday, April 19, 2017 at 9:10:16 AM UTC+2, hui zhang wrote:
>
> for  1) you mean 
>>
>> char *CGetPath() {
>> return getpath().c_str();
>>   }
>
>
> this code will work ?
>

That depends on whether getpath() returns a std::string or a (const) 
std::string& (a (const) reference). It will work if it returns a reference 
or const reference, but is not guaranteed to work if it doesn't (though it 
may appear to do so in some cases, or for some implementations of the C++ 
standard lib) because the standard lib is not required to use a 
reference-counted dynamic array. For example, it might instead choose to 
copy the array every time or to allocate small strings using an in-object 
buffer to avoid the overhead of dynamic allocation, and in both of those 
cases the return value of c_str() is no longer valid when the function 
returns.

Also, if do you need to copy the string in C++ code: 
strdup(getpath().c_str()) is better than malloc+strcpy (shorter and harder 
to get wrong). Case in point: your implementation malloc'ed str.length() 
bytes, failing to allocate an extra byte for the '\0' at the end.
Even better might be to call GoString(getpath().c_str()) in the CGetPath 
function to ensure only a single copy is made, but I'm not familiar enough 
with cgo to know if that's possible.

 

> 2017-04-19 14:43 GMT+08:00 Konstantin Khomoutov <
> flat...@users.sourceforge.net >:
>
>> On Wed, 19 Apr 2017 14:23:09 +0800
>> hui zhang > wrote:
>>
>> > 1)   getpath()  return a temp string,  its  c_str() pointer will be
>> > free out of function. So I use malloc
>>
>> I'm not completely sure you're correct.  C++ does not implement garbage
>> collection and the object on which you have called c_str() continues to
>> live on after getpath() returns.  Now let's cite the manual on c_str():
>>
>> | The pointer obtained from c_str() may be invalidated by:
>> | * Passing a non-const reference to the string to any standard library
>> |   function, or
>> | * Calling non-const member functions on the string, excluding
>> |   operator[], at(), front(), back(), begin(), rbegin(), end() and
>> |   rend().
>>
>> So I'd say in the sequence of calls I propose there's no chance of
>> anything quoted to happen -- basically the pointer returned by c_str()
>> gets passed to Go where C.GoString() copies the memory pointed to by it.
>>
>> Things may break if you somehow concurrently call into your C++ side
>> and those calls may access the same std::string object we're talking
>> about.  But if you do this, all bets are already off.
>>
>> > 2)  Assume we use the malloc way ,  are  C.GoString()   copying the
>> > pointer memory ?  for we need C.free() malloc memory.
>>
>> Yes, C.GoString() copies the memory.
>>
>> Yes, you always need to free() what was malloc()ed for you -- because
>> you own the returned pointer.
>>
>
>

-- 
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: i/o timeout when using bufio on net connection (tcp)

2017-04-19 Thread Vasiliy Tolstov
2017-04-17 19:05 GMT+03:00 Kevin Johnson :
> Hi Vasiliy,
>
> I spent a few minutes looking at your program and a couple things jumped out
> at me.  As you are probably aware, writes on a network socket usually return
> the number of bytes written,  This is because if the TCP buffer fills, then
> the write call will return only the amount that got added.  I noticed you
> used a timeout on the TCP conn, which probably puts the connection into
> non-blocking mode.  I would be surprised if binary.write was smart enough to
> attempt multiple writes in case of a partial write.  You might try removing
> the time-out and see if that has any effect.  (Network non-blocking writes
> may wait for the entire write to succeed before returning).  You might also
> use the binary.write to write to a local block of bytes and then use the
> conn send to send them manually, resending the parts when the writes only
> partially complete.


Ok, thanks! I'm try to write to buffer and use simple net.Conn Write.

-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
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] Whats the fastest cpu (per $) regarding golang compiler performance?

2017-04-19 Thread 'slinso' via golang-nuts
Hi all,

I'm interested in the compiler performance of different cpus. How much 
impact has the number of cores? Or is higher frequency with a few cores 
better regarding compile time / $.
Maybe someone already owns a new ryzen cpu. Is it worth buying a highend 
Intel cpu (i7 or xeon) for 1000$ or is the highend AMD for 500$ maybe even 
better for go.
My C++ projects would benefit the most from more cores. But that's 
something different because we are talking about 10 minutes or more compile 
time.

I think using Dave Cheneys compiler benchmarks (benchkube 
) and (benchjuju 
)  should provide solid base 
numbers for the performance. Of course smaller projects could behave 
differently. But if a small project compiles in 1s or 2s doesn't matter 
that much to the development cycle.
I have not moved the codebase to a ramdisk, because i would like to see 
numbers from normal dev setups.


go version go1.8.1 linux/amd64

cat /proc/cpuinfo | head | grep "model name"
model name  : Intel(R) Core(TM) i7-6700T CPU @ 2.80GHz
RAM: 16GB
Disk: Samsung 850 Evo

avg. runtime:
benchjuju: 23.7s
benchkube: 21.3s 


-- 
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] Zero value of the map

2017-04-19 Thread Val
That's interesting, though quite different from the map implementation 
we're used to.  Do you know (in any language) such an implementation, and 
would it really be as fast?  Computing hash, accessing some bucket, and 
dealing with collisions seem unavoidable. But I have no idea of the extra 
cost of dealing with a "versioned" immutable map, where each new version is 
not overwriting the previous one.

On Wednesday, April 19, 2017 at 4:12:20 AM UTC+2, Matt Harden wrote:
>
> It seems to me the equivalent of append for maps is merge, which would be 
> a very useful operation to have in its own right. A useful design for map 
> could have been an immutable structure supporting literals, merge, lookup 
> and delete operations, where all except lookup would return a new map 
> value. The obvious zero value would be an empty map. This can be made 
> efficient by sharing underlying data which would be safe since the map was 
> immutable.
>
> On Tue, Apr 18, 2017 at 7:59 AM Tad Vizbaras  > wrote:
>
>> Thank you for detailed explanation.
>>
>> I find myself never using "var a map[int]int" or similar var like map. 
>> Maybe just my limited understanding.
>> But I am glad we end up with map[int]int instead of *map[int]int.
>>
>>
>>
>> -- 
>> 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.


[go-nuts] Re: about the []byte -> string comversion optimization, is it some weird?

2017-04-19 Thread T L


On Wednesday, April 19, 2017 at 3:37:29 AM UTC+8, Keith Randall wrote:
>
> This is a weird corner case in string concatenation optimization.
>
> runtime.concatstrings (what the + in this code gets rewritten to) has an 
> optimization where if all the strings but one that it is concatenating are 
> 0 length, then it returns the remaining one without doing any allocation.
> Because of that optimization, runtime.concatstrings might return its 
> argument.  Thus, we can't do the zero-copy conversion of []byte to string 
> for arguments to runtime.concatstrings.
> Except when we know that at least one of the input strings has non-zero 
> length.  Then we can.  That's what is happening in f2.
>
 
Keith, thanks. But I haven't fully get your explanation.
Do you mean that compiler can't confirm whether or not the optimization 
which might return its argument can be used for f1 at compile time,
but compiler can confirm it can't be used for f2 at compile time?

 

>
> On Monday, April 17, 2017 at 11:06:26 PM UTC-7, T L wrote:
>>
>>
>> package main
>>
>> import "fmt"
>> import "testing"
>>
>> var s string
>> var a = make([]byte, 1000)
>>
>> func f0() {
>> x := string(a)
>> s = x + x + x + 
>> x + x + x + 
>> x + x + x + 
>> x
>> }
>>
>> func f1() {
>> s = string(a) +  string(a) + string(a) +
>>string(a) +  string(a) + string(a) +
>>string(a) +  string(a) + string(a) +
>>string(a)
>> }
>>
>> func f2() {
>> s = (" " +
>>string(a) +  string(a) + string(a) +
>>string(a) +  string(a) + string(a) +
>>string(a) +  string(a) + string(a) +
>>string(a) )[1:]
>> }
>>
>> func main() {
>> fmt.Println(testing.AllocsPerRun(1, f0)) // 2
>> fmt.Println(testing.AllocsPerRun(1, f1)) // 11
>> fmt.Println(testing.AllocsPerRun(1, f2)) // 1
>> }
>>
>> why doesn't gc make optimization for f1?
>>
>

-- 
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 to set different flags for different os in cgo

2017-04-19 Thread Ian Lance Taylor
On Tue, Apr 18, 2017 at 11:00 PM, hui zhang  wrote:
> I want to set different flags for different os in cgo,  how to do that in
> cgo?
>
>
>> //#cgo amd64 darwin CFLAGS: -Dxxx
>> //#cgo amd64 darwin CXXFLAGS: -Dxxx
>> //#cgo amd64 darwin LDFLAGS: -Lxxx
>> //#cgo arm darwin CFLAGS: -Dxxx
>> //#cgo arm darwin CXXFLAGS: -Dxxx
>> //#cgo arm darwin LDFLAGS: -Lxxx
>>
>> //#include "c2go.h"
>> import "C"

Yes, that is how to do it, as documented at https://golang.org/cmd/cgo.

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: Whats the fastest cpu (per $) regarding golang compiler performance?

2017-04-19 Thread Marvin Stenger
Something you have to consider, this will probably make it into go 1.9:
https://go-review.googlesource.com/?polygerrit=0#/c/40693/

Am Mittwoch, 19. April 2017 11:15:03 UTC+2 schrieb slinso:
>
> Hi all,
>
> I'm interested in the compiler performance of different cpus. How much 
> impact has the number of cores? Or is higher frequency with a few cores 
> better regarding compile time / $.
> Maybe someone already owns a new ryzen cpu. Is it worth buying a highend 
> Intel cpu (i7 or xeon) for 1000$ or is the highend AMD for 500$ maybe even 
> better for go.
> My C++ projects would benefit the most from more cores. But that's 
> something different because we are talking about 10 minutes or more compile 
> time.
>
> I think using Dave Cheneys compiler benchmarks (benchkube 
> ) and (benchjuju 
> )  should provide solid base 
> numbers for the performance. Of course smaller projects could behave 
> differently. But if a small project compiles in 1s or 2s doesn't matter 
> that much to the development cycle.
> I have not moved the codebase to a ramdisk, because i would like to see 
> numbers from normal dev setups.
>
>
> go version go1.8.1 linux/amd64
>
> cat /proc/cpuinfo | head | grep "model name"
> model name  : Intel(R) Core(TM) i7-6700T CPU @ 2.80GHz
> RAM: 16GB
> Disk: Samsung 850 Evo
>
> avg. runtime:
> benchjuju: 23.7s
> benchkube: 21.3s 
>
>
>

-- 
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] Naming projects with multiple words

2017-04-19 Thread Tong Sun
Hi, 

What's the idiomatic way to name Go projects with multiple words? Would it 
be, 

- github.com/my-id/multiple-words, or
- github.com/my-id/multiple_words, or even
- github.com/my-id/does-not_care, or
- github.com/my-id/InOneWord

what's your preference and why? 

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.


Re: [go-nuts] Naming projects with multiple words

2017-04-19 Thread Jan Mercl
On Wed, Apr 19, 2017 at 3:48 PM Tong Sun  wrote:

> what's your preference and why?

example.com/name/onenamenopunctutaionalllowercasetwotoninecharacters

b/c ~ what POSIX recommends for utility names.



-- 

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


Re: [go-nuts] Re: Whats the fastest cpu (per $) regarding golang compiler performance?

2017-04-19 Thread Jesper Louis Andersen
My intuitive hunch is that memory speed is going to affect compilation
speeds a lot as well, so that might be factored into the question as well.
Adding cores has no value unless you can keep them well fed with input they
can compile.


On Wed, Apr 19, 2017 at 3:46 PM Marvin Stenger 
wrote:

> Something you have to consider, this will probably make it into go 1.9:
> https://go-review.googlesource.com/?polygerrit=0#/c/40693/
>
>
> Am Mittwoch, 19. April 2017 11:15:03 UTC+2 schrieb slinso:
>>
>> Hi all,
>>
>> I'm interested in the compiler performance of different cpus. How much
>> impact has the number of cores? Or is higher frequency with a few cores
>> better regarding compile time / $.
>> Maybe someone already owns a new ryzen cpu. Is it worth buying a highend
>> Intel cpu (i7 or xeon) for 1000$ or is the highend AMD for 500$ maybe even
>> better for go.
>> My C++ projects would benefit the most from more cores. But that's
>> something different because we are talking about 10 minutes or more compile
>> time.
>>
>> I think using Dave Cheneys compiler benchmarks (benchkube
>> ) and (benchjuju
>> )  should provide solid base
>> numbers for the performance. Of course smaller projects could behave
>> differently. But if a small project compiles in 1s or 2s doesn't matter
>> that much to the development cycle.
>> I have not moved the codebase to a ramdisk, because i would like to see
>> numbers from normal dev setups.
>>
>>
>> go version go1.8.1 linux/amd64
>>
>> cat /proc/cpuinfo | head | grep "model name"
>> model name  : Intel(R) Core(TM) i7-6700T CPU @ 2.80GHz
>> RAM: 16GB
>> Disk: Samsung 850 Evo
>>
>> avg. runtime:
>> benchjuju: 23.7s
>> benchkube: 21.3s
>>
>>
>> --
> 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: Diameter Base Protocol for Go

2017-04-19 Thread mklimenko
Hello Alex,
Fist of all, thank you for the great effort, time and patience.

Are there any groups or forums related to your project?  
Currently, I have opened an issue 
, but is more like a 
question that others might want to see and ,perhaps, answer.
Where would be the best place to ask questions about go-diameter?

Thanks,
Michael


On Tuesday, 10 September 2013 03:21:35 UTC+3, Alexandre Fiori wrote:
>
> Hi,
>
> I'd like to announce this implementation of the Diameter Base Protocol for 
> Go:
> https://github.com/fiorix/go-diameter
>
> It's fully functional, performs well, and has been tested with some of the 
> 3GPP specs such as 32.299 and 29.212.
> Works for what I need but definitely needs more work and testing.
>

-- 
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] Naming projects with multiple words

2017-04-19 Thread Tong Sun
On Wed, Apr 19, 2017 at 9:59 AM, Jan Mercl <0xj...@gmail.com> wrote:

> On Wed, Apr 19, 2017 at 3:48 PM Tong Sun  wrote:
>
> > what's your preference and why?
>
> example.com/name/onenamenopunctutaionalllowercasetwotoninecharacters
>

 Hmm... does it meant to be sarcasm or actually recommendation? Honestly, I
tried to figure out the words from that long name but gave up after
*several* attempts.


b/c ~ what POSIX recommends for utility names.
>

Any urls maybe?

I was trying to find that myself, and found one page,

Utility Conventions
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

Which says,

Within POSIX.1-2008..., The utility in the example is named *utility_name*,


i.e., separated with an underscore.

-- 
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: Whats the fastest cpu (per $) regarding golang compiler performance?

2017-04-19 Thread 'slinso' via golang-nuts
A lot of factors will affect compilation speeds. And scaling won't be 
linear by adding more cores, I know, but how well does the compiler already 
uses the available cores. How well does the compiler scale? The mentioned 
CL above will provide some nice performance increasements for multicore 
systems.

Without digging too deep I just wanted to know how the compilation speeds 
changes on different cpus.

-- 
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] Naming projects with multiple words

2017-04-19 Thread 'Chris Manghane' via golang-nuts
There's definitely no idiom here. Do what the octokittens do and probably
use the first or second option, in that order. The third seems awkward,
unless the underscore has some specific meaning (like how _unix is used to
compile architecture-specific code). And I'm not really sure if the
capitalization in the fourth actually matters.

Looking at the Go repos themselves, there are examples of both: gofrontend
and sublime-build. It seems like go-frontend and sublimebuild would also be
reasonable names for these as well so do whatever you feel like I guess.

Thanks,
Chris

On Wed, Apr 19, 2017 at 8:05 AM, Tong Sun  wrote:

> On Wed, Apr 19, 2017 at 9:59 AM, Jan Mercl <0xj...@gmail.com> wrote:
>
>> On Wed, Apr 19, 2017 at 3:48 PM Tong Sun  wrote:
>>
>> > what's your preference and why?
>>
>> example.com/name/onenamenopunctutaionalllowercasetwotoninecharacters
>>
>
>  Hmm... does it meant to be sarcasm or actually recommendation? Honestly,
> I tried to figure out the words from that long name but gave up after
> *several* attempts.
>
>
> b/c ~ what POSIX recommends for utility names.
>>
>
> Any urls maybe?
>
> I was trying to find that myself, and found one page,
>
> Utility Conventions
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
>
> Which says,
>
> Within POSIX.1-2008..., The utility in the example is named *utility_name*
>> ,
>
>
> i.e., separated with an underscore.
>
> --
> 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: Naming projects with multiple words

2017-04-19 Thread jmontgomery
I assume by "projects" you mean packages. I understand that multiple word 
package names are sometimes needed, but Effective Go: package-names 
 from the official 
go website recommends:

"By convention, packages are given lower case, single-word names; there 
should be no need for underscores or mixedCaps."

So avoid them when possible.

- Jake

On Wednesday, April 19, 2017 at 9:48:32 AM UTC-4, Tong Sun wrote:
>
> Hi, 
>
> What's the idiomatic way to name Go projects with multiple words? Would it 
> be, 
>
> - github.com/my-id/multiple-words, or
> - github.com/my-id/multiple_words, or even
> - github.com/my-id/does-not_care, or
> - github.com/my-id/InOneWord
>
> what's your preference and why? 
>
> 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] gofmt sort function declarations

2017-04-19 Thread Kamil Dziedzic
Hi,

One thing that annoys me often while going through long source code file is 
that often function declarations are organized in some random order. I was 
thinking about using some tool (at least for my projects) to automatically 
order all function declarations. This seems to be already true for 
generating documentation, e.g. here https://golang.org/pkg/database/sql/ 
you can see declarations are sorted (also grouped - variables first, 
functions second, structs last).

I've put in the title gofmt, as it makes sense such option could be in 
gofmt, but I understand such crazy idea would affect wy to much 
projects :) So I rather think about separate tool.

Did anyone thought about such tool already? Or I'm on my own and probably 
gofmt is best starting point to develop similar tool? It's a bit hard to 
google that as first thing I get are references to "sort" package.

Best, Kamil Dziedzic

-- 
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] Flux - A simple CQRS framework for quick prototyping

2017-04-19 Thread yehohanan7
Hi,
If you are interested in building *simple* applications using event 
sourcing and CQRS, then you could give flux a spin 
 - https://github.com/yehohanan7/flux

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] Installation process of Sizzle

2017-04-19 Thread manisha . kumari . it13
Hello dear,


Can anyone guide me the installation process of Sizzle. Can I operate it on 
windows or Linux is required
 

-- 
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] gofmt sort function declarations

2017-04-19 Thread Ian Lance Taylor
On Wed, Apr 19, 2017 at 9:25 AM, Kamil Dziedzic  wrote:
>
> One thing that annoys me often while going through long source code file is
> that often function declarations are organized in some random order. I was
> thinking about using some tool (at least for my projects) to automatically
> order all function declarations. This seems to be already true for
> generating documentation, e.g. here https://golang.org/pkg/database/sql/ you
> can see declarations are sorted (also grouped - variables first, functions
> second, structs last).
>
> I've put in the title gofmt, as it makes sense such option could be in
> gofmt, but I understand such crazy idea would affect wy to much projects
> :) So I rather think about separate tool.
>
> Did anyone thought about such tool already? Or I'm on my own and probably
> gofmt is best starting point to develop similar tool? It's a bit hard to
> google that as first thing I get are references to "sort" package.

It's intentional that gofmt does not reorder top level declarations.
The programmer is expected to arrange those declarations in some order
that makes sense to people reading the source code.

It shouldn't be hard to use go/parser and go/format to do what you want.

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] runtime: Setting GOMAXPROCS in over-scheduled Contanier Environments

2017-04-19 Thread Josh Roppo
Hi y'all,

I have a question related to improving overall CPU utilization efficiency 
of our CPU intensive distributed workloads. I've also posted this  on the 
Gophers slack but as Dave Cheney pointed out recently, it's not the best 
medium for long winded questions. I haven't been able to find too much 
written on this topic, so I appreciate any advice!

I'd like to improve CPU utilization efficiency of Go processes by 
over-scheduling pods on Kubernetes nodes. The issue is that this workload 
is variable and heterogeneous; so it's very rare that all processes consume 
all the available resources. Allowing specific processes/Pods to burst 
would improve compute resource efficiency, without impairing our processing 
performance.

eg:
Turn 4x Go processes running on 16CPU VMs at average 60% CPU utilization.
Into 1x 64CPU Kubernetes Node, running 6 pods ~96% CPU utilization.
Theoretically this can be achieved by setting each Pods' Scheduler Request 
to 9600milliCPU, and cgroups Limit to 16000milliCPU(via the Pod 
specification).

My question is; what is a safe setting for configuring GOMAXPROCS for each 
Pod to not degrade the Go runtime performance? If it were set to 10, I 
don't think it'd be able burst and take advantage of the extra cgroups 
Limit. 
Conversely, would setting GOMAXPROCS to 16; cause runtime instability if 
all 6 Pods bursted and attempted to utilize full cgroups Limit? Or would 
the kernel allocation simply throttle the performance(and over-threading) 
in a safe manner.

It seems Google is working on dynamic thread changes 
 
for 
their runtimes, but that's more advanced than what we're ready for right 
now.

Stating why this is a horrible idea, is also a helpful response..

Thanks for any advice,
Josh Roppo

<3 Go Community 

-- 
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] pcap.openlive cannot open virtual box VM NIC

2017-04-19 Thread chunzhang
Hi, All, 

I used the following code snippet on a virtual box ubtunu vm trying to 
capture the packet. However, even though "enp3s0" is listed in the device 
list, opening it causes an error as follows. The same code runs on a 
physical box has no problem opening the NIC.

Any suggestions?

TIA

Devices found:

Name:  enp0s3
- IP address:  10.6.105.56
- Subnet mask:  ff00
- IP address:  fe80::d9a:740b:eb92:e270
- Subnet mask:  


open interface failed
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4c4606]

goroutine 1 [running]:
panic(0x5313a0, 0xc42000c0a0)
/usr/local/go/src/runtime/panic.go:500 +0x1a1

fmt.Println("Devices found:")
for _, device := range devices {
   fmt.Println("\nName: ", device.Name)
   //fmt.Println("Description: ", device.Description)
   //fmt.Println("Devices addresses: ", device.Description)
   for _, address := range device.Addresses {
  fmt.Println("- IP address: ", address.IP)
  fmt.Println("- Subnet mask: ", address.Netmask)
   }
}
// Open device
//handle, err = pcap.OpenLive(device, snapshot_len, promiscuous, timeout)

handle, err = pcap.OpenLive("enp3s0", 1600, true, 100)
//pcap.OpenLive("enp0s8", snapshot_len, promiscuous, timeout)
if err == nil {
   fmt.Println("open interface ", device, "successfully")
   defer handle.Close()
} else {
   fmt.Println("open interface failed")
}


-- 
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] Pointer to Container Type

2017-04-19 Thread dc0d
In Go there is no way to pass a reference to an instance of the 
container/enclosing type, to a function of an embedded type. What work 
around do you use for this? Any idiomatic Go way?

Currently I model the shared functionality using an interface. Then the 
implementation is another struct, which takes a pointer to the container 
type and implements that interface - one could just implement the interface 
directly. But this is done for convenience and grouping the similar 
functionality. This implementation struct will then gets embedded inside 
the container/enclosing type.

-- 
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] Pointer to Container Type

2017-04-19 Thread Ian Lance Taylor
On Wed, Apr 19, 2017 at 1:35 PM, dc0d  wrote:
>
> In Go there is no way to pass a reference to an instance of the
> container/enclosing type, to a function of an embedded type. What work
> around do you use for this? Any idiomatic Go way?
>
> Currently I model the shared functionality using an interface. Then the
> implementation is another struct, which takes a pointer to the container
> type and implements that interface - one could just implement the interface
> directly. But this is done for convenience and grouping the similar
> functionality. This implementation struct will then gets embedded inside the
> container/enclosing type.

Typically in Go this is the wrong question.  Wanting to pass a
reference to the enclosing type to a method of an embedded type is
often a symptom of trying to write C++ in Go.

Better to describe the whole problem, and see if people can suggest a
different approach that is more Go-like.

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] main.go:1:1: expected 'package', found 'EOF'

2017-04-19 Thread rameshpdx
Thank you, Nico.

On Friday, January 23, 2015 at 6:16:15 AM UTC-8, Nico wrote:
>
> Did you save before calling GoRun? 
>

-- 
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: OpenGL Fonts

2017-04-19 Thread saif
have found that you can do TTF to OpenVG.
but not sure how gl on go mobile will render slant lines for W.

if you happen to know this is not the ideal way, please suggest. thanks.

On Tuesday, April 18, 2017 at 1:02:02 PM UTC+8, saif wrote:
>
> Hi,
>
> I like to ask for your suggestions.
>
> I found a nice project, and was trying to modify them but got stuck with 
> fonts.
> (github.com/dskinner/material)
>
> I like the fonts to be configurable, but when I tried to parse the fonts 
> at runtime, it seems slow.
>
> The idea from the example is to preparse fonts with 72 fontsize, then 
> create a a texture to be rendered.
> Is there a better way to do this?
>
>
> Thanks,
> 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.


Re: [go-nuts] how to set different flags for different os in cgo

2017-04-19 Thread hui zhang
how ever if I exec

> go build -buildmode=c-archive -o libmug.a ./src

for mac lib build it build both and failed

so does for ios lib ,  it compile fail

>  CC=$PWD/clangwrap.sh CXX=$PWD/clangwrap.sh GOOS=darwin GOARCH=arm
> CGO_ENABLED=1  go build -buildmode=c-archive -o libmug.a ./src


 If I comment each #cgo sperately for defferent build ,  it works fine

2017-04-19 21:31 GMT+08:00 Ian Lance Taylor :

> On Tue, Apr 18, 2017 at 11:00 PM, hui zhang  wrote:
> > I want to set different flags for different os in cgo,  how to do that in
> > cgo?
> >
> >
> >> //#cgo amd64 darwin CFLAGS: -Dxxx
> >> //#cgo amd64 darwin CXXFLAGS: -Dxxx
> >> //#cgo amd64 darwin LDFLAGS: -Lxxx
> >> //#cgo arm darwin CFLAGS: -Dxxx
> >> //#cgo arm darwin CXXFLAGS: -Dxxx
> >> //#cgo arm darwin LDFLAGS: -Lxxx
> >>
> >> //#include "c2go.h"
> >> import "C"
>
> Yes, that is how to do it, as documented at https://golang.org/cmd/cgo.
>
> 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] how dose netpollblock been awaked while sysmon slepp?

2017-04-19 Thread 代君
i have a test code like this:
func main() {
tcpAddress, err := net.ResolveTCPAddr("tcp", ":")
if err != nil {
fmt.Println(err)
}
listener, err := net.ListenTCP("tcp", tcpAddress)

c, e := listener.AcceptTCP()
if e != nil {
fmt.Println(e)
}

t := make([]byte, 0, 1000)
c.Read(t)
}
when the main function blocked on AcceptTCP(),  the runtime.sysmon() 
function will enter sleep soon which is because npidle equal to gomaxprocs. 

and then a tcp connect coming, how acceptTCP been waked? I couldn't find a 
runtime.netpoll() been call anymore.

could some give some advise, effective tools, design document or debug 
method to read golang's source code? I always want to debug some code in 
runtime, but i
conn't find a effective way to do this now; I read these code so hard 
without clearly understand the detail design .

-- 
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 dose netpollblock be awoken while sysmon sleep?

2017-04-19 Thread sydnash
I have a test code like this:
func main() {
tcpAddress, err := net.ResolveTCPAddr("tcp", ":")
if err != nil {
fmt.Println(err)
}
listener, err := net.ListenTCP("tcp", tcpAddress)

c, e := listener.AcceptTCP()
if e != nil {
fmt.Println(e)
}

t := make([]byte, 0, 1000)
c.Read(t)
}
when the main function blocked on AcceptTCP(),  the runtime.sysmon() 
function will enter sleep soon which is because npidle equal to gomaxprocs. 

and then a tcp connection comes, how dose acceptTCP be awoken? I couldn't 
find a runtime.netpoll() been call anymore.

could some give some advise, effective tools, design document or debug 
method to read golang's source code? I always want to debug some code in 
runtime, but i
conn't find a effective way to do this now; I read these code so hard 
without clearly understand the detail design .

-- 
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] x509.Certificate.Verify: "x509: certificate signed by unknown authority"

2017-04-19 Thread dorianlangbeck
Hi,

I have a "simple" issue regarding x509 certificate verification. There are 
two certificates:
- cacert.pem: a self signed certificate
- ek.pem: a certificate that was signed by cacert.pem

The following command works as expected:
$ openssl verify -CAfile cacert.pem ek.pem
ek.pem: OK

But the following code doesn't: https://play.golang.org/p/10KMLs4WWt
*Can't be tested on Go Playground

Any help is appreciated. =)

-- 
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 dose netpollblock been awaked while sysmon slepp?

2017-04-19 Thread Ian Lance Taylor
On Wed, Apr 19, 2017 at 7:42 PM, 代君  wrote:
>
> i have a test code like this:
> func main() {
> tcpAddress, err := net.ResolveTCPAddr("tcp", ":")
> if err != nil {
> fmt.Println(err)
> }
> listener, err := net.ListenTCP("tcp", tcpAddress)
>
> c, e := listener.AcceptTCP()
> if e != nil {
> fmt.Println(e)
> }
>
> t := make([]byte, 0, 1000)
> c.Read(t)
> }
> when the main function blocked on AcceptTCP(),  the runtime.sysmon()
> function will enter sleep soon which is because npidle equal to gomaxprocs.
>
> and then a tcp connect coming, how acceptTCP been waked? I couldn't find a
> runtime.netpoll() been call anymore.

In the findrunnable function, when a P tries to find a G to run, if
there is nothing to run, but there are some goroutines waiting for
network activity, then the P will block in a call to netpoll until
something is ready.

> could some give some advise, effective tools, design document or debug
> method to read golang's source code? I always want to debug some code in
> runtime, but i
> conn't find a effective way to do this now; I read these code so hard
> without clearly understand the detail design .

For the scheduler you can read
https://docs.google.com/document/d/1TTj4T2JO42uD5ID9e89oa0sLKhJYD0Y_kqxDv3I3XMw/view
, although it is somewhat out of date.

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: how dose netpollblock be awoken while sysmon sleep?

2017-04-19 Thread sydnash
I got it. it because there is a blocking netpool in runtime.findrunable() 
function.

-- 
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: OpenGL Fonts

2017-04-19 Thread Egon
On Tuesday, 18 April 2017 08:02:02 UTC+3, saif wrote:
>
> Hi,
>
> I like to ask for your suggestions.
>
> I found a nice project, and was trying to modify them but got stuck with 
> fonts.
> (github.com/dskinner/material)
>
> I like the fonts to be configurable, but when I tried to parse the fonts 
> at runtime, it seems slow.
>
> The idea from the example is to preparse fonts with 72 fontsize, then 
> create a a texture to be rendered.
> Is there a better way to do this?
>

>
> Thanks,
> S
>

Create a glyph or text atlas invalidating, updating, paging it as needed.

For a basic glyph atlas 
https://gist.github.com/egonelbre/fbbf4651a4f75f8450fd4fc2244c283f -- you 
can of course use multiple pages and use better layouting algorithm to 
preserve memory.

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