[go-nuts] Is this a bug ?

2021-06-03 Thread Jamil Djadala

https://groups.google.com/g/golang-nuts

package main

import (
"fmt"
)

func main() {
const aa int = 0
var a int
fmt.Println(float64(1

Re: [go-nuts] I think I found a bug?

2021-05-26 Thread Jamil Djadala
minimally changed code that works:

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


On Thursday, May 27, 2021 at 4:11:40 AM UTC+3 johnfor...@gmail.com wrote:

> Here’s the code.  It might be 
> possible to come up with a shorter reproducer, but I’m not sure where to 
> start. The recursion takes place in line 21. The code works for 7 or 
> smaller, and fails for 8 and larger.
>
> J
>
>
> On May 26, 2021, at 20:34, Martin Schnabel  wrote:
>
> Could you send a https://play.golang.org/ link showing a short example?
>
> Without much information it sounds like a you update the same slice at two 
> different indices. It would be interesting to know how you populate the 
> temp slice.
>
> On 27.05.21 01:52, John Olson wrote:
>
> I have a recursive function that seems to be reusing memory it shouldn't. 
> I'm developing in Goland 2021.1.1 with go version 1.16.2.
> I've written a function to generate the partitions of an integer. The 
> partitions of n are all the sets of integers that add up to n, so the 
> partitions of 3 are {3}, {2,1} and {1,1,1}. As n grows, the number of 
> partitions grows exponentially (to be precise, as e^(n^½)). I wrote a 
> recursive function, which works great up to n=7. At n=8, one of the 
> partitions is {2,2,2,1}, which is obviously wrong; and since the function 
> is recursive, every subsequent n is wrong, too.
> I just spent quite a long time stepping through the code, and I found that 
> what seems to be happening is that a slice declared in my recursive 
> function is being reused in two different recursions. Specifically, my 
> function declares
> var temp [][]int
> to build up the list of partitions. When I compute Partitions(8), I have 
> to compute Partitions(4), 5, 6 and 7. I memoize each set of partitions so I 
> only have to compute them once.
> It all goes wrong when I'm working on Partitions(7). At this point, 
> Partitions(8) has already added 6 cases, the last of which is {2,2,2,2}. 
> This is stored in temp[5], the temp corresponding to n=8, of course. Then I 
> compute Partitions(7), which should create a new temp [][]int; I'll call 
> this temp//7. temp[6]//7 gets {2,2,2,1}, and at that point temp[5]//8 
> changes from {2,2,2,2} to {2,2,2,1}. The addresses of temp[6]//7 and 
> temp[5]//8 are different, but the addresses of the /elements/ of these 
> slices are the same.
> This has to be wrong.
> I suspect a bug in go, but I suppose it's possible there's a bug in 
> goland. I'm running on macOS 11.3.1, just in case that's relevant.
> I'm happy to share the source code if anyone is interested.
> Thanks,
> 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...@googlegroups.com <
> mailto:golang-nuts...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/fb9031ba-bfa0-4c92-9cb7-6ad3a8781184n%40googlegroups.com
>  <
> https://groups.google.com/d/msgid/golang-nuts/fb9031ba-bfa0-4c92-9cb7-6ad3a8781184n%40googlegroups.com?utm_medium=email&utm_source=footer
> >.
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/de91d8a7-63eb-40aa-bf20-b1a18897fa84n%40googlegroups.com.


Re: [go-nuts] keep just 2 decimal places in a float64

2020-01-25 Thread Jamil Djadala
On Sat, 25 Jan 2020 19:14:15 -0800 (PST)
"Jason E. Aten"  wrote:

> 
> https://play.golang.org/p/87bDubJxjHO
> 
> I'd like to truncate a float64 to just 2 decimal places (in base 10),
> but math.Trunc is not helping me here... ideally I put 0.29 in and I
> get 0.29 out.
> Suggestions?  Playground examples appreciated.

you can use int types:
https://play.golang.org/p/qLnynemd3S1
-- 
Jamil Djadala

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20200126074011.0f17b4fa%40wolf.home.


Re: [go-nuts] querying whether the go command would run in module mode

2019-12-09 Thread Jamil Djadala
On Mon, 09 Dec 2019 19:57:48 +1030
Dan Kortschak  wrote:

> Thanks.
> 
> When you're not in a module it returns /dev/null on linux. I don't
> suppose this is platform independent?

Hi,
This command:
go env GOMOD

returns 1 emty line,
i dont see any /dev/null ?

-- 
Jamil Djadala

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20191209114053.5bf5bd76%40beast.


Re: [go-nuts] Is anyone aware of a blocking ring buffer implementation?

2019-11-21 Thread Jamil Djadala
On Thu, 21 Nov 2019 22:37:37 -0600
Robert Engels  wrote:

> The OP specifically requested io.Reader/Writer interfaces. 
> 
> A pipe is what he wants. Not a ring buffer. (A pipe essentially has a
> ring buffer in the implementation though). 

from https://golang.org/pkg/io/#Pipe :

The data is copied directly from the Write to the corresponding Read
(or Reads); there is no internal buffering

and looking in implementation, it seems that internally Pipe is using
channel.

-- 
Jamil Djadala

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20191122065315.78316d02%40wolf.home.


Re: [go-nuts] cgo memory fragmetation?

2019-10-07 Thread Jamil Djadala
On Mon, 7 Oct 2019 00:54:32 -0700 (PDT)
miha.vrhov...@gmail.com wrote:

> Hi guys,
> 
> We are having a very weird problem, where the process memory keeps
> rising, but both the pprof and valgrind report no memory leaks. But
> the RSS just keeps rising.The C part is in external so library
> 
> To be more exact, the pprof when the process becomes idle reports a
> few megabytes used and the Valgrind reports 88bytes lost(this are
> global objects) But the RSS for example is ~1G and virtual 4G+
> I've run also run the app with the GODEBUG=madvdontneed=1,gctrace=1
> but madvdontneed doesn't seem to help.
> 
> If I describe the MO of communicating with the library's API (all
> memory is allocated on the library side). 
> 
> for {
>   * initialize the processor 
>   * say to the library to create the blob of size x on it's side
>   * convert the returned pointer to a fake slice (code below)
>   * copy data to the fake slice
>   * instruct processor to do it's thing (e.g make
> calculations/compress the data,...)
>   * process the data on Go side (depending on the processor this
> either makes a copy of the data or creates a fake slice from it)
>   * destroy the processor (this frees the memory on the library's
> side)
>   * upload the data somewhere
> }
> 
> func cVoidPtrToByteSlice(data unsafe.Pointer, size int, bytes
> *[]byte) { header := (*reflect.SliceHeader)(unsafe.Pointer(bytes))
> header.Data = uintptr(data)
> header.Len = size
> header.Cap = size
> }
> 
> BR,
> Miha
> 

Hi, can you try to run your program with GOGC=10 environment ?

-- 
Jamil Djadala

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20191007110422.325e6ae5%40bee.datamax.bg.


[go-nuts] does any known tool for function (text) inlinig ?

2019-06-09 Thread djadala
Hi, 
is there any tool for function text (source code)  inlinig, to be used with 
go generate ?
thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8223e294-ff94-4d91-a537-53125d4e7191%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: constatnt conversion question

2019-05-21 Thread djadala

Thanks all for comments,
 
for me confusion is that 
int( some_float_var)

works, and surprisingly 
int( some_float_constant)

does not. 
 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/50e711ce-6e11-43d7-8e7f-46275e141bdb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] constatnt conversion question

2019-05-20 Thread djadala
Hi,
does this should work ?

package main

import (
"fmt"
)

func main() {
const (
c = 2
z = 3.3
y = c * z
x = int(y) // or x int = y
)

fmt.Println(x)
}


it does not compile with error: 
constant 6.6 truncated to integer

https://play.golang.org/p/f-Q6XSvvcrM

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/736e8b03-d38f-4ec4-adc8-fcb77e0cda7b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread djadala


On Friday, April 26, 2019 at 9:12:06 AM UTC+3, Mike Schinkel wrote:
>
> On Thursday, April 25, 2019 at 10:20:54 AM UTC-4, Sam Whited wrote:
>>
>> On Wed, Apr 24, 2019, at 14:08, Mark Volkmann wrote: 
>> > Are there really developers that find this unreadable? 
>> > 
>> > color := temperature > 80 ? “red” : “green” 
>>
>> Yes. 
>>
>> What is "?"? If I've never seen that before I have no easy way to search 
>> for that, and a random symbol me nothing about what it does. Go 
>> specifically tries to stick to keywords because even if you've never 
>> seen them before it's generally easier to figure out what they do (or to 
>> search for them if you're not sure). 
>>
>
> Given that, I am curious what your thoughts would be if this were possible 
> in Go instead?
>  
>color := if temperature > 80 then “red” else “green” 
>
> And especially if this formatting were valid:
>
>color := if temperature > 80 
>   then “red” 
>   else “green” 
>


Hi,
this is valid now:

color := func() string {
if temperature > 80 {
return "red"
}
return "green"
}()


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

-- 
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: methods on C types

2019-04-18 Thread Jamil Djadala
On Thu, 18 Apr 2019 11:34:25 -0700
Ian Lance Taylor  wrote:

> That said, I have to agree that defining methods on types defined by
> cgo is never necessary and can only cause confusion.  And cgo could
> report an error when it sees it.  So please consider opening an issue
> to change cmd/cgo to issue an error for an attempt to define a method
> on a type defined in the C pseudo-package.  Thanks.
> 
> Ian
> 

Does this is covered by go backward compatibility promise ?
Because i saw package on github, that use this "feature" to implement
error interface on C.int, mapping return error codes from C api to go
errors.
 
-- 
Jamil Djadala

-- 
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: methods on C types

2019-04-18 Thread Jamil Djadala
On Thu, 18 Apr 2019 07:44:53 -0700 (PDT)
peterGo  wrote:

> Cgo translates C types into equivalent unexported Go types.
> https://golang.org/cmd/cgo/


But then, definition of new methods on non-local types is forbidden.
Why it is enabled for cgo types ? 

-- 
Jamil Djadala

-- 
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] methods on C types

2019-04-17 Thread djadala
Hi,
where is documented that methods can be created on C types ?

This works with go1.12.4, linux:
https://play.golang.org/p/gXpHCFOgDDg

package main

import (
"C"
"fmt"
)

func (i *C.int) Inc() {
*i++
}

func main() {
var i C.int
i.Inc()
fmt.Println(i)
}


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] question about modules and VCS

2019-04-01 Thread djadala
Hi,
As i  understand, go get with modules on does't retrieve history from VCS, 
only snapshot of requested/calculated version.
Is there a way to have full history with modules ?

Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: rand.Rand.Seed() vs rand.NewSource()

2019-03-27 Thread djadala
Hi,
I think OP question actually is what is difference  between:
r := rand.New(rand.NewSource(VALUE))

and
r := rand.New(rand.NewSource(ANYTHING))

r.Seed(VALUE)

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

-- 
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] why compiler do not accept elided type in this case ?

2019-03-18 Thread djadala
Hi,
https://play.golang.org/p/hRHEuGG6zAf
why composite literal in line 16 does not work ?
thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: performance optimization

2018-12-19 Thread djadala
see https://github.com/golang/go/issues/27707

-- 
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] regexp: is there a way to match single byte ?

2018-12-15 Thread djadala
Hi
for example i want to match jpeg header:

header :=`\xFF\xD8\xFF\xE0..\x4A\x46\x49\x46\x00`

re := regexp.MustCompile(header)


where in position of '.' i want to match any byte, not any (unicode) char. 
is this possible ?
thanks in advance.
Djadala

-- 
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.WriteFile not writing files in long running process

2018-08-24 Thread djadala
Hi,
did you write files in /tmp on linux ?
(and there is daemon that clean old files in /tmp ?)

Regards,
Djadala


-- 
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] filepath.WalkFunc documentation question

2018-08-10 Thread djadala
Hi,
documentation of filepath.WalkFunc state:

The path argument contains the argument to Walk as a prefix; that is, if 
> Walk is called with "dir", which is a directory containing the file "a", 
> the walk function will be called with argument "dir/a".
>

but  if the root parameter of Walk is ".", walk function is called with 
"a", not "./a".

example:
https://play.golang.org/p/PvRDSKo3KGz

Is this intentional or incorrect documentation ?

Regards,
Djadala


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] golang tcp transport just like nc

2018-03-08 Thread Jamil Djadala
On Wed, 7 Mar 2018 19:16:33 -0800 (PST)
sucong...@gmail.com wrote:

> 
> 
> linux nc command port to golang 
> 
> 
> in nc , we can do this
> 
> echo 'my id is 1' > /tmp/1
> echo 'my id is 3' > /tmp/3
> rm -rf /tmp/2 /tmp/4
> 
> 
> 
> server
> 
> nc -l 19090 < /tmp/1 > /tmp/2
> 
> ( if you are in linux not mac this may be  ` nc -l -p 19090 `  )
> 
> client
> 
> 
> nc 127.0.0.1 19090 < /tmp/3 > /tmp/4
> 
> 
> when finish ,both server and client will be closed
> 
> client send /tmp/3 is saved by server to /tmp/2
> 
> server send /tmp/1 is saved by server to /tmp/4
> 
> then use golang do the same thing , but when finished , both server
> and client can not closed automaticly
> 
> 
> 
> echo 'my id is 1' > /tmp/1
> echo 'my id is 3' > /tmp/3
> rm -rf /tmp/2 /tmp/4
> 
> 
> 
> 
> 
> ./nc serer < /tmp/1 > /tmp/2
> 
> 
> 
> ./nc  < /tmp/3 > /tmp/4
> 
> 
> 
> please help me how to solve this and works like nc 
> 
> 
> example code 
> 
> https://gist.github.com/suconghou/a1bfab9a30b3408400b6382d73051227
> 
> 
> 

See
https://play.golang.org/p/6ljoK4EB9iY

You must use CloseRead/CloseWrite

Jamil Djadala


-- 
Jamil Djadala

-- 
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] printing a struct fields that implements an error interface

2018-02-18 Thread Jamil Djadala
On Sat, 17 Feb 2018 16:05:42 -0800 (PST)
Joseph Lorenzini  wrote:

> Hi all:
> 
> Per documentation:
> 
> "If an operand implements the error interface, the Error method will
> be invoked to convert the object to a string, which will then be
> formatted as required by the verb (if any)"
> 
> And this is so even if the struct implements the stringer interface.
> So if I print the struct, I get the error value. Is there anyway to
> force fmt.Print to output the struct fields, even when it implements
> the error interface? 
> 
> Thanks,
> Joe 
> 

Just use fmt.Print(v.String()) instead of fmt.Print(v)

-- 
Jamil Djadala

-- 
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: Implementation of sync.Once

2018-02-16 Thread djadala


On Friday, February 16, 2018 at 3:27:04 PM UTC+2, dc0d wrote:
>
> Why sync.Once uses a sync.Mutex in addition to atomic functions?
>
> What are the drawbacks/shortcomings/deficiencies of this implementation? 
>
> type Once struct {
>  done uint32
> }
>
>
> func (o *Once) Do(f func()) {
>  if !atomic.CompareAndSwapUint32(&o.done, 0, 1) {
>  return
>  }
>  f()
> }
>
>

You implementation returns immediately, if f() is still running, while in 
original implementation all concurrent calls to Do() returns when f() 
return.

Djadala

 

-- 
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] goto from inner select

2017-11-06 Thread djadala


On Monday, November 6, 2017 at 8:03:28 PM UTC+2, Ian Lance Taylor wrote:
>
> On Mon, Nov 6, 2017 at 8:55 AM,  > wrote: 
> > 
> > Can someone explain, is this program  is really incorrect: 
> > https://play.golang.org/p/0fp9Nt_99L 
> > 
> > trying to run it results in error: 
> > tmp/sandbox536393528/main.go:16:9: goto C jumps into block starting at 
> > tmp/sandbox536393528/main.go:10:2 
> > but goto jumps in outside block. 
>
> Every case in a switch is an implicit block, so, yes, this program is 
> invalid and the compiler is telling you why. 
>

Thanks for clear explanation
 

>
> > I trying to make priority select by nesting selects, and want to find 
> way to 
> > write logic only in one place. 
>
> Use a function? 


Yes, i consider using functions, just wonder why goto does not work,

Thanks again.

Jamil Djadala



 

-- 
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] goto from inner select

2017-11-06 Thread djadala
Hi all,
Can someone explain, is this program  is really incorrect:
https://play.golang.org/p/0fp9Nt_99L

trying to run it results in error:
tmp/sandbox536393528/main.go:16:9: goto C jumps into block starting at 
tmp/sandbox536393528/main.go:10:2
but goto jumps in outside block.

I trying to make priority select by nesting selects, and want to find way 
to write logic only in one place.

Regards,
Jamil Djadala

-- 
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 could a new user konw which packge should be used?

2017-11-06 Thread djadala


On Monday, November 6, 2017 at 12:23:37 PM UTC+2, Karan Chaudhary wrote:
>
> Another one: http://go-search.org
>

Go Search 
756881  golang packages in 171083 projects 
indexed, last updated 265 days ago.

265 days ago. ???
No, 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: How to pass a value to multiple readers of a shared channel

2017-10-15 Thread djadala
And here is some working code:
https://play.golang.org/p/1Qt-LqKiph

Djadala

On Sunday, October 15, 2017 at 11:36:36 PM UTC+3, st ov wrote:
>
> A value sent through a channel can be read by only one reader, so once its 
> read its no longer available to other readers is that right?
>
> In what ways can I pass/communicate/distribute a value through a channel 
> and have it shared across an unknown number of readers?
>

-- 
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 to pass a value to multiple readers of a shared channel

2017-10-15 Thread djadala
This post might help:
https://rogpeppe.wordpress.com/2009/12/01/concurrent-idioms-1-broadcasting-values-in-go-with-linked-channels/

Djadala

On Sunday, October 15, 2017 at 11:36:36 PM UTC+3, st ov wrote:
>
> A value sent through a channel can be read by only one reader, so once its 
> read its no longer available to other readers is that right?
>
> In what ways can I pass/communicate/distribute a value through a channel 
> and have it shared across an unknown number of readers?
>

-- 
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: Retrieve Unknown Rows & Columns From a MySQL Table (Golang)

2017-09-14 Thread djadala
Again not tested:

package main

import (
"database/sql"
"fmt"
"log"

_ "github.com/go-sql-driver/mysql"
)

func main() {
//Connect to database and check for errors  
db, err := sql.Open("mysql",
"script:script1!@tcp(10.14.0.173:3306)/dbaTesting")
if err != nil {
log.Println(err)
}

rows,err := db.Query("SELECT * FROM animals")
if err != nil {
log.Fatal(err)
}
defer rows.Close()

cols, err := rows.Columns() // Remember to check err afterwards
if err != nil {
log.Fatal(err)
}

vals := make([]interface{}, len(cols))


for rows.Next() {
for i := range cols {
vals[i] = &vals[i]
}
err = rows.Scan(vals...)
// Now you can check each element of vals for nil-ness,
if err != nil {
log.Fatal(err)
}
for i := range cols {
fmt.Println(vals[i]) 
}
}
}


On Friday, September 15, 2017 at 5:10:43 AM UTC+3, Alexandre K wrote:
>
> Thank you so much for your response!
>
> The code you added probably works, but I'm getting held up by something 
> else.
>
> I'm running into a set of errors when I execute this on the command 
> line...It seems the "rows" value I'm creating doesn't have the 
> functionality that the guide says it would
>
> # command-line-arguments
> ./2multi.go:22: rows.Columns undefined (type error has no field or method 
> Columns)
> ./2multi.go:30: rows.Next undefined (type error has no field or method 
> Next)
> ./2multi.go:34: rows.Scan undefined (type error has no field or method 
> Scan)
> Here's an updated version of my code
>
> package main
>
> import (
>"database/sql"
>"fmt"
>"log"
>
> _ "github.com/go-sql-driver/mysql"
> )
>
> func main() {
> //Connect to database and check for errors  
>db, err := sql.Open("mysql",
>"script:script1!@tcp(10.14.0.173:3306)/dbaTesting")
>if err != nil {
>log.Println(err)
>}
>
> var str string
>rows := db.QueryRow("SELECT * FROM animals").Scan(&str)
>
> cols, err := rows.Columns() // Remember to check err afterwards
>if err != nil {
>log.Fatal(err)
>}
>
> vals := make([]interface{}, len(cols))
>
>
> for rows.Next() {
>for i := range cols {
>vals[i] = &vals[i]
>}
>err = rows.Scan(vals...)
>// Now you can check each element of vals for nil-ness,
>if err != nil {
>log.Fatal(err)
>}
>for i := range cols {
>fmt.Println(vals[i]) 
> }
>}
> }
>
>
> Shouldn't the value I create in "rows" be able to pass arguments to the 
> "db" class I'm referencing when I'm creating "rows?"
>

-- 
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: Retrieve Unknown Rows & Columns From a MySQL Table (Golang)

2017-09-14 Thread djadala
Hi,
something like (not tested): 

package main

import (
"database/sql"
"fmt"
"log"

_ "github.com/go-sql-driver/mysql"
)

func main() {
//Connect to database and check for errors  
db, err := sql.Open("mysql",
"script:scriptPassword@tcp($HOSTNAME:3306)/Testing")
if err != nil {
log.Println(err)
}

var str string
rows, err = db.Query("SELECT * FROM animals").Scan(&str)
if err != nil && err != sql.ErrNoRows {
log.Fatal(err)
}

cols, err := rows.Columns() // Remember to check err afterwards
if err != nil {
log.Fatal(err)
}

vals := make([]interface{}, len(cols))

for rows.Next() {

for i := range cols {
vals[i] = &vals[i]

}

err = rows.Scan(vals...)
// Now you can check each element of vals for nil-ness,
if err != nil {
log.Fatal(err)
}

for i := range cols {

fmt.Println(vals[i]) 

}
}


Jamil Djadala


On Friday, September 15, 2017 at 2:59:59 AM UTC+3, Alexandre K wrote:
>
> Hello Everyone,
>
> I'm new to Golang and I am trying to figure out how to retrieve multiple 
> unknown columns and rows from a table.
>
> I have an example table called ANIMALS 
> <https://gist.github.com/akalaj/015aa79b5854b728af0baf884f50b827>.
>
> I am trying to follow the example at the bottom of this GUIDE 
> <http://go-database-sql.org/varcols.html>.
>
> Here is the code that I've sewn together:
>
> package main
>
> import (
> "database/sql"
> "fmt"
> "log"
>
> _ "github.com/go-sql-driver/mysql"
> )
>
> func main() {
> //Connect to database and check for errors  
> db, err := sql.Open("mysql",
> "script:scriptPassword@tcp($HOSTNAME:3306)/Testing")
> if err != nil {
> log.Println(err)
> }
>
> var str string
> rows, err = db.Query("SELECT * FROM animals").Scan(&str)
> if err != nil && err != sql.ErrNoRows {
> log.Fatal(err)
> }
>
> cols, err := rows.Columns() // Remember to check err afterwards
> if err != nil {
> log.Fatal(err)
> }
>
> vals := make([]interface{}, len(cols))
> for i, _ := range cols {
> vals[i] = new(sql.RawBytes)
> }
>
> for rows.Next() {
> err = rows.Scan(vals...)
> // Now you can check each element of vals for nil-ness,
> if err != nil {
> log.Fatal(err)
> }
> // Here is where I get lost
> // How should I access Vals and print the values it finds???
> }
>
>
>
> I am trying to get Golang to print the values to the linux terminal using 
> something like the code below.
>
> fmt.Println(mysqlValues)
>
> How do I retrieve the MySQL values stored in the interface in m 
> <https://gist.github.com/akalaj/28684690c42da8e9aa0cea5bd7340b1c>y code 
> provided above
>

-- 
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: Copying slice over itself

2017-09-07 Thread djadala
Hi,
Just check if backing array are same before copying:
https://play.golang.org/p/MSqs-jRkSO

On Thursday, September 7, 2017 at 8:54:16 AM UTC+3, Deepak Jois wrote:
>
> Hi 
>
> Pls look at this code: https://play.golang.org/p/QfQOo1iyp4 
>
> I am copying a slice over itself. How does it work internally? Does 
> the copy operation optimise for this, and not perform any copying in 
> this case? 
>
> I have to deal with a situation where I get a slice reference back 
> from a function, and it is possible that it points to the same slice 
> that I am trying to copy it into. It would be nice if the copy 
> operation in that case is a no-op, but I don’t want to assume that is 
> the case. 
>
> Deepak 
>

-- 
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: Reading bytes into uint32

2017-08-23 Thread djadala
Agree about hidden assumption, and may be alignment issues. 
Last try: 
https://play.golang.org/p/6e-i0AFZri

Jamil Djadala

On Thursday, August 24, 2017 at 1:40:52 AM UTC+3, Rob 'Commander' Pike 
wrote:
>
> Apologies, typo. This is it: https://play.golang.org/p/9XWoCiUH2D 
>
> On Thu, Aug 24, 2017 at 8:39 AM, Rob Pike > 
> wrote: 
> > I believe there is no safe (that is, unsafe-free) way to discover the 
> > native byte order. In a sense, this is because depending on the native 
> > byte order is intrinsically unsafe. It is by definition not portable. 
> > It is a terrible design decision. 
> > 
> > By the way, that program may work but it's not sound. It has a hidden 
> > assumption about how bytes are laid out in arrays and the 
> > correspondence with words. (Some machines, like the PDP-11, actually 
> > confused some matters like this). This is a better way to discover the 
> > byte order, at which point you can use portable methods from 
> > encoding/binary: https://play.golang.org/p/7svQ66wl7I 
> > 
> > -rob 
> > 
> > On Thu, Aug 24, 2017 at 8:24 AM,  > 
> wrote: 
> >> It use unsafe, but works even in playground: 
> >> https://play.golang.org/p/S1rw157M9C 
> >> 
> >> 
> >> On Wednesday, August 23, 2017 at 3:49:39 PM UTC+3, Christian von 
> Kietzell 
> >> wrote: 
> >>> 
> >>> Hi, 
> >>> 
> >>> I've stumbled across a problem I don't know how to solve. 
> >>> 
> >>> I'm trying to read (from stdin) four bytes into a uint32 value. Those 
> >>> bytes are provided in _native_ byte order by an external program.[*1] 
> >>> 
> >>> Since I've found nothing in the standard library to determine the 
> >>> machine's native byte order I can't decide whether to use 
> >>> binary.BigEndian.Uint32 or binary.LittleEndian.Uint32. 
> >>> 
> >>> Is there a way without involving package unsafe? Am I missing 
> something 
> >>> obvious? 
> >>> 
> >>> [*1] The data comes from a web browser extension using the native 
> >>> messaging API, which specifies that messages sent to external programs 
> >>> are prefixed with the 32-bit length of the message in native byte 
> order. 
> >>> 
> >>> 
> >>> Thanks, 
> >>> Chris 
> >>> 
> >>> -- 
> >>> Nothing to see here. Move along. 
> >> 
> >> -- 
> >> 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: Reading bytes into uint32

2017-08-23 Thread djadala
It use unsafe, but works even in playground:
https://play.golang.org/p/S1rw157M9C


On Wednesday, August 23, 2017 at 3:49:39 PM UTC+3, Christian von Kietzell 
wrote:
>
> Hi, 
>
> I've stumbled across a problem I don't know how to solve. 
>
> I'm trying to read (from stdin) four bytes into a uint32 value. Those 
> bytes are provided in _native_ byte order by an external program.[*1] 
>
> Since I've found nothing in the standard library to determine the 
> machine's native byte order I can't decide whether to use 
> binary.BigEndian.Uint32 or binary.LittleEndian.Uint32. 
>
> Is there a way without involving package unsafe? Am I missing something 
> obvious? 
>
> [*1] The data comes from a web browser extension using the native 
> messaging API, which specifies that messages sent to external programs 
> are prefixed with the 32-bit length of the message in native byte order. 
>
>
> Thanks, 
> Chris 
>
> -- 
> Nothing to see here. Move along. 
>

-- 
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: Best way to truncate a ridiculously long string in GO

2017-08-21 Thread djadala
https://play.golang.org/p/YXXlJlsNGa
Hi,
i'm not sure if compiler is smart enough to optimize v1, but likely v2 ends 
in separate memory.   

On Tuesday, August 22, 2017 at 3:04:42 AM UTC+3, Travis Keep wrote:
>
> Suppose you have code like this
>
>
> // verylongstring may be several thousand bytes long
> verylongstring := GetSomeVeryLongString()
>
> prefix := verylongstring[:3]
>
>prefixStore.StorePrefixForDurationOfApplication(prefix)
>
>
>
> If I understand correctly, verylongstring cannot be garbage collected 
> because prefix points to the first 3 characters of it and is stored forever.
>
> What I want is to hold onto the first 3 characters while allowing the rest 
> of verylongstring to be GCed? In JAVA, you can do
>
> prefix := new String(verylongstring.substring(0,3))
>
> which allows verylongstring to be GCed even if the application holds onto 
> prefix.  This is because the above JAVA code has prefix reference a copy of 
> the first 3 characters of verylongstring instead of having prefix reference 
> verylongstring itself.
>
> What is the best way to do this in go?
>
>
>
>
>
>

-- 
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: defer func() { _ = resp.Body.Close() }()

2017-08-17 Thread djadala
Useful additional info:
https://mijailovic.net/2017/05/09/error-handling-patterns-in-go/
https://groups.google.com/forum/#!topic/golang-nuts/-eo7navkp10

On Wednesday, August 16, 2017 at 3:05:39 PM UTC+3, Gert wrote:
>
> To pass errcheck I need to do something like
>
> defer func() { _ = resp.Body.Close() }()
>
> instead of 
>
> defer resp.Body.Close()
>
> Is this something the errcheck tool can figure out to mark as valid 
> instead or does the errcheck tool need help from the compiler so the second 
> case is also ok?
>
>

-- 
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 based JSON Escape/Unescape

2017-08-13 Thread djadala
may be it is by default ?
https://play.golang.org/p/e1mTTLt6zH

On Monday, August 14, 2017 at 6:35:41 AM UTC+3, Tong Sun wrote:
>
> Has anyone done Go based JSON Escape/Unescape yet? 
>
> I want to pass any arbitrary content as a JSON string:
>
>   {
>   "content": "my escaped strings {\n \"employees\": {\n   
>   \"employee\": [\n {\n \"id\": 
> \"1\",..."
>   }
>
> In order to pass a JSON string inside another JSON string in such a 
>> scenario, you need to escape it (e.g. manually via JSON Escape/Unescape 
>> ).
>
>
>  
> Is there a Go package ready-made for it somewhere? 
> Else, what are to be escaped so that I can embed any arbitrary content as 
> a JSON string?
>
> Thx
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] liteide x32.2 released

2017-08-04 Thread djadala
apt-get install apt-file
apt-file update
apt-file search libpng12.so
libpng12-0: /lib/x86_64-linux-gnu/libpng12.so.0
libpng12-0: /lib/x86_64-linux-gnu/libpng12.so.0.50.0
libpng12-0: /usr/lib/x86_64-linux-gnu/libpng12.so.0
libpng12-dev: /usr/lib/x86_64-linux-gnu/libpng12.so





On Friday, August 4, 2017 at 7:22:41 PM UTC+3, Oleg Puchinin wrote:
>
> liteidex32.2.linux64-qt4.tar.bz2 
> 
> $ bin/liteide say
> ./liteide: error while loading shared libraries: libpng12.so.0: cannot 
> open shared object file: No such file or directory
>
> Debian 9.1
> Oleg.
>
>
> 2017-07-19 7:25 GMT+06:00 visualfc >:
>
>> Hi all.
>> LiteIDE x32.2 released! Fix editor watcher invalid bug (if external 
>> editor many change). Debug add breakpoint load and save. Fix debug tests 
>> action. etc.
>>
>> ### Links
>> * LiteIDE New Home 
>> 
>> * LiteIDE Source code
>> 
>> * Gotools Source code
>> 
>> * Release downloads
>> 
>>
>> ### 2017.7.18 Ver X32.2
>> * LiteApp
>> * fix editor file watcher is invalid for many change
>> * GolangEdit
>> * fix TODO/BUG/FIXME comment syntax 
>> * DlvDebugger
>> * fix dlv headless process workdir
>> * LiteDebug
>> * fix debug tests action
>> * fix load and save breakpoint for editor
>> --
>> Sent from YoMail for Gmail 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread djadala
again i'm wrong :(

On Friday, August 4, 2017 at 10:30:14 AM UTC+3, Sebastien Binet wrote:
>
>
>
> On Fri, Aug 4, 2017 at 9:24 AM, > wrote:
>
>> Ok, 
>> i'm not right,pow in C is :
>> float powf(float x, float y);
>>long double powl(long double 
>>
>> use float32 pow for proper comparison or use powl for C double wersion.
>>
>
> C'pow is with doubles (like Go's math.Pow):
>  https://linux.die.net/man/3/pow
>
> ```
> Synopsis
>
> #include 
>
> double pow(double x, double y);
> ```
>
> -s
>
>
>> This is demonstartion how when you use go long time, you lose ability to 
>> read other languages :)
>>
>>
>> On Friday, August 4, 2017 at 10:15:06 AM UTC+3, dja...@gmail.com wrote:
>>>
>>> You are comparing apples to oranges( integer vs float64 pow),
>>> use integer pow and compare again:
>>>
>>>
>>> func Pow(a, b int) int {
>>>  p := 1
>>>  for b > 0 {
>>>  if b&1 != 0 {
>>>  p *= a
>>>  }
>>>  b >>= 1
>>>  a *= a
>>>  }
>>>  return p
>>> }
>>>
>>>
>>> On Friday, August 4, 2017 at 9:20:41 AM UTC+3, Dorival Pedroso wrote:

 I've noticed that this C code:

 #include "math.h"
 int main() {
 double x = 2.5;
 int Nmax = 1000;
 for (int N=0; N>>> for (int i=0; i<20; i++) {
 pow(x, i);
 }
 }
 }

 can run up to 50x faster than this Go code:

 package main

 import "math"

 func main() {
 x := 2.5
 Nmax := 1000
 for N := 0; N < Nmax; N++ {
 for i := 0; i < 20; i++ {
 math.Pow(x, float64(i))
 }
 }
 }

 The C code was compiled with: gcc -O2 ccode.c -o ccode -lm
 then run with time ./ccode

 The Go code was compiled with: go build gcode.go
 then run with  time ./gcode

 I've used the time command on Linux (Ubuntu) to get some estimate.

 So the question is: how can we make the Go code faster?

>>> -- 
>> 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: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread djadala
Ok, 
i'm not right,pow in C is :
float powf(float x, float y);
   long double powl(long double 

use float32 pow for proper comparison or use powl for C double wersion.

This is demonstartion how when you use go long time, you lose ability to 
read other languages :)


On Friday, August 4, 2017 at 10:15:06 AM UTC+3, dja...@gmail.com wrote:
>
> You are comparing apples to oranges( integer vs float64 pow),
> use integer pow and compare again:
>
>
> func Pow(a, b int) int {
>  p := 1
>  for b > 0 {
>  if b&1 != 0 {
>  p *= a
>  }
>  b >>= 1
>  a *= a
>  }
>  return p
> }
>
>
> On Friday, August 4, 2017 at 9:20:41 AM UTC+3, Dorival Pedroso wrote:
>>
>> I've noticed that this C code:
>>
>> #include "math.h"
>> int main() {
>> double x = 2.5;
>> int Nmax = 1000;
>> for (int N=0; N> for (int i=0; i<20; i++) {
>> pow(x, i);
>> }
>> }
>> }
>>
>> can run up to 50x faster than this Go code:
>>
>> package main
>>
>> import "math"
>>
>> func main() {
>> x := 2.5
>> Nmax := 1000
>> for N := 0; N < Nmax; N++ {
>> for i := 0; i < 20; i++ {
>> math.Pow(x, float64(i))
>> }
>> }
>> }
>>
>> The C code was compiled with: gcc -O2 ccode.c -o ccode -lm
>> then run with time ./ccode
>>
>> The Go code was compiled with: go build gcode.go
>> then run with  time ./gcode
>>
>> I've used the time command on Linux (Ubuntu) to get some estimate.
>>
>> So the question is: how can we make the Go code faster?
>>
>

-- 
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 to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread djadala
You are comparing apples to oranges( integer vs float64 pow),
use integer pow and compare again:


func Pow(a, b int) int {
 p := 1
 for b > 0 {
 if b&1 != 0 {
 p *= a
 }
 b >>= 1
 a *= a
 }
 return p
}


On Friday, August 4, 2017 at 9:20:41 AM UTC+3, Dorival Pedroso wrote:
>
> I've noticed that this C code:
>
> #include "math.h"
> int main() {
> double x = 2.5;
> int Nmax = 1000;
> for (int N=0; N for (int i=0; i<20; i++) {
> pow(x, i);
> }
> }
> }
>
> can run up to 50x faster than this Go code:
>
> package main
>
> import "math"
>
> func main() {
> x := 2.5
> Nmax := 1000
> for N := 0; N < Nmax; N++ {
> for i := 0; i < 20; i++ {
> math.Pow(x, float64(i))
> }
> }
> }
>
> The C code was compiled with: gcc -O2 ccode.c -o ccode -lm
> then run with time ./ccode
>
> The Go code was compiled with: go build gcode.go
> then run with  time ./gcode
>
> I've used the time command on Linux (Ubuntu) to get some estimate.
>
> So the question is: how can we make the Go code faster?
>

-- 
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] errors package

2017-07-30 Thread djadala
also check errors package:
https://godoc.org/github.com/pkg/errors

On Sunday, July 30, 2017 at 12:56:25 PM UTC+3, Oleg Puchinin wrote:
>
> Cool ! Thank you !
>
> Oleg.
>
> 2017-07-30 15:39 GMT+06:00 >:
>
>>
>> https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully
>>
>>
>> On Sunday, July 30, 2017 at 11:40:59 AM UTC+3, Oleg Puchinin wrote:
>>>
>>> Hi !
>>> IMHO package "errors" bad. How in the program to check which error 
>>> actually occurred?
>>> Well it is impossible on a string.
>>>
>>> Thank you !
>>> Oleg.
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] errors package

2017-07-30 Thread djadala
https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully

On Sunday, July 30, 2017 at 11:40:59 AM UTC+3, Oleg Puchinin wrote:
>
> Hi !
> IMHO package "errors" bad. How in the program to check which error 
> actually occurred?
> Well it is impossible on a string.
>
> Thank you !
> Oleg.
>

-- 
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] x/exp/shiny: is there a way to get screen DPI ?

2017-07-11 Thread djadala
Hi All,
Question is in subject,
May be i miss something obvious, but cant find how to get DPI

golang.org/x/exp/shiny/screen  doesn't mention anyting about dpi or 
resolution.

thanks in advance,
Djadala


-- 
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: [ANN] gos2: S2 geometry library in Go

2017-05-05 Thread djadala
Hi,
this package is moved to
https://github.com/golang/geo
just in case you don't noticed.
Djadala

On Saturday, May 6, 2017 at 4:03:25 AM UTC+3, Matthew Hoggan wrote:
>
> I am trying to find a group associated with 
> https://code.google.com/archive/p/s2-geometry-library/. This is the only 
> post that comes up when searching groups.
>
> My question on the library is, Do the bounding polygons associated with a 
> cell id include the boundaries or sides of the polygon? If so what sides 
> (top, left), (bottom, left)... etc?
>
> Thanks,
> Matthew Hoggan
>
> On Wednesday, March 13, 2013 at 8:37:35 PM UTC-6, David Symonds wrote:
>>
>> I'm pleased to announce the initial open source release of the Go port 
>> of the S2 geometry library: 
>>
>> https://code.google.com/p/gos2/ 
>> http://godoc.org/code.google.com/p/gos2/s2 
>>
>> (or "go get code.google.com/p/gos2/s2".) 
>>
>> /* 
>> Package s2 implements types and functions for working with geometry in 
>> S² (spherical geometry). 
>>
>> Its related packages, parallel to this one, are s1 (operates on S¹), 
>> r1 (operates on ℝ¹) and r3 (operates on ℝ³). 
>>
>> This package provides types and functions for the S2 cell hierarchy 
>> and coordinate systems. The S2 cell hierarchy is a hierarchical 
>> decomposition of the surface of a unit sphere (S²) into “cells”; it is 
>> highly efficient, scales from continental size to under 1 cm² and 
>> preserves spatial locality (nearby cells have close IDs). 
>>
>> A presentation that gives an overview of S2 is 
>>
>> https://docs.google.com/presentation/d/1Hl4KapfAENAOf4gv-pSngKwvS_jwNVHRPZTTDzXXn6Q/view.
>>  
>>
>> */ 
>>
>>
>> Note that it is not as complete as the C++ version it is based on, but 
>> it works well for what it does support, and is sufficient for geo 
>> indexing and the like. 
>>
>

-- 
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 let go and c code work Alternately in the same thread

2017-04-28 Thread djadala


On Friday, April 28, 2017 at 9:18:03 AM UTC+3, hui zhang wrote:
>
> How let go and c code work Alternately in the same thread with 
> goroutine(corouting mechanism)
> Check the code below.  c and go code in one thread they just do work 1 by 
> 1.
> Expected Result 
>
>> Do CWork
>> Do GoWork
>> Do CWork
>> Do GoWork
>> Do CWork
>> .
>
>
> //c code
>> void CWork() {
>> while(1) {
>>--Print Do CWork
>>--Coroutine Stop
>> --switch to GoWork()
>> }
>> }
>> int main() {
>> CWork();
>> }
>> //go code 
>> func GoWork() {
>> for {
>> --Print Do GoWork
>>--Coroutine Stop
>> --switch back to CWork()
>> }
>> }
>
>
>  
>


Hi, simplest solution:

//c code
> void CWork() {
> --Print Do CWork
> }
> int main() {
> for {
> C.CWork()
> GoWork() 
> }
> }
>
> //go code 
> func GoWork() {
> --Print Do GoWork
> }



 Djadala

-- 
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: Parsing base64 data with headers

2017-04-06 Thread djadala
https://golang.org/pkg/mime/multipart/  ?

On Thursday, April 6, 2017 at 2:00:21 PM UTC+3, Ain wrote:
>
> Hi
>
> I get string which contains:
>
> MIME-Version: 1.0
> content-type: text/xml
> content-transfer-encoding: base64
>
>
> PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPD94bWwtc3R5bGVzaGVldCB0
> ...
>
>
> ie there are some headers and then base64 encoded data. I suspect there 
> might be some functions in the std lib which should be able to parse this 
> and give me easy access to the headers and data but I just can't find it... 
> it isn't mime/multipart, right? Perhaps something in the http client 
> package?
>
> TIA
> ain
>

-- 
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: Overwritten pointer value on channel

2017-03-28 Thread djadala
ok, 1st guess is wrong.
do you run your code with race enabled ?

On Tuesday, March 28, 2017 at 4:08:17 PM UTC+3, Danilo Cianfrone wrote:
>
> Doesn't work, and doesn't make sense, even.
> I assume the problem is in the channel, but can't figure out which and why.
>
> Il giorno martedì 28 marzo 2017 14:47:40 UTC+2, dja...@gmail.com ha 
> scritto:
>>
>> >> go func(j tengin.Job) { m.OnJob(j); m.Done() }(job)
>> func(j tengin.Job) { go func(){ m.OnJob(j); m.Done()}() }(job)
>>
>> Djadala
>> On Tuesday, March 28, 2017 at 3:27:34 PM UTC+3, Danilo Cianfrone wrote:
>>>
>>> I'm experiencing a weird bug.
>>> I have a microservice that uses FBP architecture, with a structure 
>>> *graph* as main graph and *multiplexer* as first component.
>>>
>>> The code is the following:
>>>
>>> type graph struct {
>>> loggable
>>> fetchable
>>>
>>> multiplexer
>>> fetcher
>>> nodeEvaluator
>>> joiner
>>> treeEvaluator
>>>
>>> closed   atomic.Value
>>> listener atomic.Value
>>> }
>>>
>>> func (g *graph) Submit(job tengin.Job) error {
>>> if closed := g.closed.Load().(bool); closed {
>>> return ErrClosed
>>> }
>>>
>>> if err := job.Validate(); err != nil {
>>> return err
>>> }
>>>
>>> g.Logger.Debug("added new job to the input channel", job.ZapField())
>>>
>>> g.multiplexer.Add(1)
>>> g.multiplexer.Job <- job
>>> return nil
>>> }
>>>
>>> type multiplexer struct {
>>> sync.WaitGroup
>>> loggable
>>> multiplexerCallbacks
>>>
>>> Jobchan tengin.Job
>>> FetcherOut chan tengin.Job
>>> NodeOutchan tengin.Job
>>> }
>>>
>>> func (m *multiplexer) Handler() {
>>> go func() {
>>> for job := range m.Job {
>>> m.Logger.Debug("JOB ARRIVED", job.ZapField())
>>> go func(j tengin.Job) { m.OnJob(j); m.Done() }(job)
>>> }
>>> }()
>>> }
>>>
>>> type Job struct {
>>> Event ResourceEvent `json:"event"`
>>> Stuff *stuff.Stuff  `json:"stuff"`
>>> }
>>>
>>> Every Job is submitted in the main graph, and the *graph.Submit()* function 
>>> writes the incoming Job into the multiplexer Job channel.
>>> The *multiplexer.Handler() *listens for incoming jobs from the Job 
>>> channel, and executes the *multiplexer.OnJob() *function *(which is 
>>> basically state-less).*
>>>
>>> Let's say I'm feeding two Jobs to the graph, *Job1 *and *Job2*, where 
>>> *Job1.Stuff.ID 
>>> <http://Job1.Stuff.ID> = x *and *Job2.Stuff.ID <http://Job2.Stuff.ID> = 
>>> y*
>>> The *multiplexer.Handler() *receives 2 Jobs, but they're *2 instances 
>>> of Job2!*
>>>
>>> In fact, the Logger on *Submit()* prints Job1 and Job2 as one would 
>>> expect, but the Logger on *Handler() *prints *2 times Job2!*
>>> Maybe I'm missing something, but *go vet* doesn't highlight any 
>>> problems.
>>>
>>>

-- 
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: Overwritten pointer value on channel

2017-03-28 Thread djadala
>> go func(j tengin.Job) { m.OnJob(j); m.Done() }(job)
func(j tengin.Job) { go func(){ m.OnJob(j); m.Done()}() }(job)

Djadala
On Tuesday, March 28, 2017 at 3:27:34 PM UTC+3, Danilo Cianfrone wrote:
>
> I'm experiencing a weird bug.
> I have a microservice that uses FBP architecture, with a structure *graph* 
> as main graph and *multiplexer* as first component.
>
> The code is the following:
>
> type graph struct {
> loggable
> fetchable
>
> multiplexer
> fetcher
> nodeEvaluator
> joiner
> treeEvaluator
>
> closed   atomic.Value
> listener atomic.Value
> }
>
> func (g *graph) Submit(job tengin.Job) error {
> if closed := g.closed.Load().(bool); closed {
> return ErrClosed
> }
>
> if err := job.Validate(); err != nil {
> return err
> }
>
> g.Logger.Debug("added new job to the input channel", job.ZapField())
>
> g.multiplexer.Add(1)
> g.multiplexer.Job <- job
> return nil
> }
>
> type multiplexer struct {
> sync.WaitGroup
> loggable
> multiplexerCallbacks
>
> Jobchan tengin.Job
> FetcherOut chan tengin.Job
> NodeOutchan tengin.Job
> }
>
> func (m *multiplexer) Handler() {
> go func() {
> for job := range m.Job {
> m.Logger.Debug("JOB ARRIVED", job.ZapField())
> go func(j tengin.Job) { m.OnJob(j); m.Done() }(job)
> }
> }()
> }
>
> type Job struct {
> Event ResourceEvent `json:"event"`
> Stuff *stuff.Stuff  `json:"stuff"`
> }
>
> Every Job is submitted in the main graph, and the *graph.Submit()* function 
> writes the incoming Job into the multiplexer Job channel.
> The *multiplexer.Handler() *listens for incoming jobs from the Job 
> channel, and executes the *multiplexer.OnJob() *function *(which is 
> basically state-less).*
>
> Let's say I'm feeding two Jobs to the graph, *Job1 *and *Job2*, where 
> *Job1.Stuff.ID 
> <http://Job1.Stuff.ID> = x *and *Job2.Stuff.ID <http://Job2.Stuff.ID> = y*
> The *multiplexer.Handler() *receives 2 Jobs, but they're *2 instances of 
> Job2!*
>
> In fact, the Logger on *Submit()* prints Job1 and Job2 as one would 
> expect, but the Logger on *Handler() *prints *2 times Job2!*
> Maybe I'm missing something, but *go vet* doesn't highlight any problems.
>
>

-- 
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: Does sync.Cond call Lock() twice on the underlying Locker?

2017-03-13 Thread djadala


On Tuesday, March 14, 2017 at 12:10:31 AM UTC+2, Albert Tedja wrote:
>
> I am writing a custom Locker which does a check if Lock() is being called 
> more than once and throws a panic if it does.
> I tested it to see if I can use it with sync.Cond, and for the most part, 
> it was running as intended, except once in a while
> the panic check triggered.
>
> Here's the dumbed down version of what I am trying to do:
>
> https://play.golang.org/p/2tWqY221RM
>
> I cannot get it to reproduce on the Go Playground, but copy paste it to 
> your local computer and see if you get it to panic.
> Here's what I got:
>
> panic: Cannot lock twice
> goroutine 5 [running]:
> main.(*CustomLocker).Lock(0xc42000e2e0)
> /.../go/src/github.com/test/custom_locker.go:18 +0xc9
> main.main.func1(0xc4200142c0, 0xc42000e2f0, 0xc42000e2d0)
> /.../go/src/github.com/test/custom_locker.go:42 +0x37
> created by main.main
> /.../go/src/github.com/test/custom_locker.go:50 +0x159
> exit status 2
>
> I thought sync.Cond.Wait() should Unlock(), sleeps itself, then when 
> awaken by Broadcast() try to Lock() again?
>

Hi,

First, your custom Locker implements Locker interface, but does not lock as 
it call Unlock at function return.
Second, Locker main job is to call Lock() multiple times (from different 
goroutines)

Djadala

-- 
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: Understanding garbage collection in Go with infinite lists

2017-03-03 Thread djadala


On Friday, March 3, 2017 at 9:05:50 AM UTC+2, Yota Toyama wrote:
>
> Nathan,
>
> As I posted above right after you posted, you are right.
> "Memory leak" was gone when I inserted sleep at the loop end.
> Thank you for your advice!
>
> Yota
>
> On Friday, March 3, 2017 at 10:39:02 AM UTC+9, Nathan Fisher wrote:
>>
>> Hi Yota,
>>
>> I don't disagree there's value in understanding how Go handles the 
>> scenario. What I'm not certain of is the potential tradeoffs when 
>> optimising for an uncommon edge case.
>>
>> The loop you've created is very tight and would be unusual to find in a 
>> typical application. The allocator is moving faster than GC could ever hope 
>> to keep up. Given it's an endless loop without any work I think there would 
>> be a tradeoff of performance to guard against something that will only 
>> exist in micro-benchmarks and/or invalid code.
>>
>> I would expect that if you introduce some "work" the memory leak would go 
>> away. 
>>
>> Kind regards,
>> Nathan
>>
>> On Fri, 3 Mar 2017 at 01:10 Yota Toyama  wrote:
>>
>>> Volker,
>>>
>>> I don't know if the term "memory leak" is misuse.
>>> But, the 1st version's memory usage is constant but the 2nd version's 
>>> one grows over time as if nothing is garbage-collected.
>>>
>>>
>>> Yota
>>>
>>>
>>> On Friday, March 3, 2017 at 2:38:08 AM UTC+9, Volker Dobler wrote:
>>>>
>>>> Am Donnerstag, 2. März 2017 17:15:05 UTC+1 schrieb Yota Toyama:
>>>>>
>>>>> Hi, all.
>>>>>
>>>>> I'm trying to understand argument liveness in Go 1.8.
>>>>> As preparation for it, I wrote 2 programs which iterate over infinite 
>>>>> lists.
>>>>> At first, I thought both can be run forever without any memory leak.
>>>>> However, the result was that one could and the other couldn't.
>>>>>
>>>>> Their main difference is the way to iterate lists.
>>>>>
>>>>> l := *NewList(42, nil)
>>>>>
>>>>> for {
>>>>>   l = *l.Rest() // Cause no memory leak :)
>>>>> }
>>>>>
>>>>> vs
>>>>>
>>>>> l := NewList(42, nil)
>>>>>
>>>>> for {
>>>>>   l = l.Rest() // Cause memory leak!!!
>>>>> }
>>>>>
>>>>> The repository is here 
>>>>> <https://github.com/raviqqe/argument-liveness.go>.
>>>>> I wanna understand why the latter causes memory leak and what is going 
>>>>> on in my programs at low level. 
>>>>> Any ideas?
>>>>>
>>>>
>>>>
>>>> What makes you say that one version causes a memory leak?
>>>>
>>>> The first version produces much less garbage (well, basically none):
>>>> l is a ListValue and the freshly created "list rest" is assigned to it,
>>>> basically just overwriting the memory location of l with the same
>>>> value.
>>>>
>>>> The second version produces an endless linked list where only the
>>>> last list element is reachable from your code as this is the only value
>>>> you have a pointer to.
>>>>
>>>> So the second produces tremendous amounts of  garbage but this
>>>> garbage is collectable. Running it shows no problem when tracing GC
>>>> at least not with Go 1.8.
>>>>
>>>> So the main difference is: The first code does not produce an "endless
>>>> list" it just operates on one List value while the second code really
>>>> constructs an ever increasing linked list if List values where only the
>>>> tail is reachable/uncollectable.
>>>>
>>>> How did you determine the second version "leaks"?
>>>>
>>>> V
>>>>
>>> -- 
>>> 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.
>>>
>> -- 
>> - from my thumbs to your eyes
>>
>

instead of time.Sleep(), use runtime. Gosched().

Djadala
 

-- 
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: Trying to understand := and named return values

2017-02-22 Thread djadala


On Wednesday, February 22, 2017 at 3:39:58 PM UTC+2, Marvin Renich wrote:
>
> On Tue, Feb 21, 2017 at 1:46 PM,  > 
> wrote: 
> > Seems like named returns + if/for/switch initializers = a shadowing 
> > nightmare. I wish the Go compiler emitted a loud warning on shadowing, 
> as 
> > this is a dangerously subtle problem out there. 
>
> * Ian Lance Taylor [170221 16:13]: 
> > Yes, named returns may have been a mistake.  Only use them in very 
> > very short functions. 
>
> * John Souvestre > [170221 21:46]: 
> > I feel the opposite.  I view named returns as documentation of a 
> > function's parameters.  I'm constantly amazed by the (correct) 
> > emphasis placed on using appropriate names for calling parameters, but 
> > not for the return parameters.  The goal is that I shouldn't have to 
> > read a function's code to use the function, right? 
>
> I agree with the John and the others that named return variables are a 
> good feature. 
>
> The confusion is not because of the named returns, but because the := 
> notation used with multiple variables on the left combines declaration 
> and simple assignment without allowing, much less requiring, the 
> programmer to explicitly identify which variables are being declared and 
> which are simply being assigned a new value.  This is relevant when := 
> is used at the block scope as well as in if/for/switch initializers. 
>
> ...Marvin 
>
>


does it sounds good to disable (in specs) named return vars shadowing ?
Djadala
 

-- 
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: Why get an element from []interface{} `arr[0] == nil` is not true?

2017-02-15 Thread djadala

On Wednesday, February 15, 2017 at 11:25:16 AM UTC+2, dja...@gmail.com 
wrote:
>
>
>
> On Wednesday, February 15, 2017 at 10:40:35 AM UTC+2, Felix Sun wrote:
>>
>> https://play.golang.org/p/qYA8Ddnnye
>>
>> ```
>>
>> package main
>>
>> import (
>> "fmt"
>> )
>>
>> type Obj struct {
>> One *Obj
>> }
>>
>> func main() {
>> var o = &Obj{}
>>
>> var arr = []interface{}{o.One}
>>
>> fmt.Println(arr[0])
>> fmt.Println("why this is not true?", arr[0] == nil)
>> }
>>
>>
>> ```
>>
>>
>> Why `arr[0] == nil` is not true?
>>
>> Hi, there are misleading answers, so:
>
> First Println prints value of arr[0].One, winch is nil.
> Second Println check if f arr[0] is nil (arr[0] is address of 'o')
>
> Ops, my bad, this is not true,
> I must read source more carefully.
>
>

-- 
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: Why get an element from []interface{} `arr[0] == nil` is not true?

2017-02-15 Thread djadala


On Wednesday, February 15, 2017 at 10:40:35 AM UTC+2, Felix Sun wrote:
>
> https://play.golang.org/p/qYA8Ddnnye
>
> ```
>
> package main
>
> import (
> "fmt"
> )
>
> type Obj struct {
> One *Obj
> }
>
> func main() {
> var o = &Obj{}
>
> var arr = []interface{}{o.One}
>
> fmt.Println(arr[0])
> fmt.Println("why this is not true?", arr[0] == nil)
> }
>
>
> ```
>
>
> Why `arr[0] == nil` is not true?
>
> Hi, there are misleading answers, so:

First Println prints value of arr[0].One, winch is nil.
Second Println check if f arr[0] is nil (arr[0] is address of 'o')

Regards,
Djadala

-- 
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: fmt: Why Golang doesn't have fmt.Printlnf?

2017-02-07 Thread djadala


On Wednesday, February 8, 2017 at 3:58:55 AM UTC+2, 高橋誠二 wrote:
>
> fmt package have no *lnf method, but in other langs,
> sometimes it implements Printlnf.
> Is there any reason?
>

fmt.Printlnf(f,...) = fmt.Printf(f+"\n", ...)
Djadala 

-- 
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: Priority cases in select?

2017-01-26 Thread djadala


On Wednesday, January 25, 2017 at 3:14:27 PM UTC+2, T L wrote:
>
> sometimes, I do want one case on a select block get selected even if there 
> are multiple unblocked cases.
> For example, I don't want the dataCh case is selected if the stopCh and 
> the timer channel are unblocked:
>
> select {
> case <- stopCh:
> return
> case value := <-dataCh:
> }
>
> select {
> case <- time.After(time.Second):
> return
> case dataCh <- value:
> }
>
> Is there a solution to satisfy my need currently?
>


Hi,
multiple priority with only 2 nested selects: 
https://play.golang.org/p/ViI54yGyIm

Djadala

-- 
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] Reset Slice with Make Every Time?

2017-01-10 Thread djadala


On Tuesday, January 10, 2017 at 9:52:06 AM UTC+2, Chetan Gowda wrote:

Old data remains as it is in the existing allocation. It will be 
> overwritten as you fill up the slice again. 


This happens in case of group = group[:0],
OP asks what happens   in case of group = make( []Area, 0, MAX ),
In that case  old data will be garbage collected when GC runs.

Djadala  

-- 
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 go cast multi return value type

2017-01-05 Thread djadala


On Friday, January 6, 2017 at 4:01:32 AM UTC+2, hui zhang wrote:
>
>
> check code below
> func foo() (int32,int32) {
> .
> }
> var a,b int16
> a, b = (int16, int16)foo()
>
> I want to cast multi return value ,  but it seems impossible in go,  how 
> can I do that
> I just want to make my code short , and not wish to create useless temp 
> variable
>
>
>

Hi,
you can use function to convert types:
https://play.golang.org/p/2mBwvXhUI9
 
Djadala

-- 
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: Check if previous value in template range is different

2017-01-04 Thread djadala


On Wednesday, January 4, 2017 at 7:09:48 PM UTC+2, Sathish VJ wrote:
>
> Is there a way to check if the previous value in the template range is 
> different from the current one?
>
> type Data struct {
> Value int32
> }
>
> var htmlTemplate = `{{range $i, $el := .}}
> {{$i}}:{{.Value}}: (is it diff from previous value, i.e. data[i-1])
> {{end}}`
>
> Intended use: to change the color of certain cells in a table if it is 
> different from that in previous row.
>
> code: https://play.golang.org/p/v-O_M4Rq4N
>


Hi,
add dummy element in slice at beginning and pass to template data[1:] and 
data:
https://play.golang.org/p/OnQPOJPsIp

I don't know is there a better way.
Djadala 
 

-- 
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: There has no Mutex.Trylock() implemention or similar method ?

2016-10-23 Thread djadala

Hi,

Trylock is simple as: https://play.golang.org/p/rpy3Kg1KWW

Regards,
Djadala

-- 
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: slice: copy to zero length slice

2016-10-02 Thread djadala
Hi, you want to use append, not copy:
https://play.golang.org/p/1TXCsC4-GJ
 

On Sunday, October 2, 2016 at 5:18:42 PM UTC+3, 高橋誠二 wrote:
>
> As official doc explains, copy to zero length slice results to be empty.
>
> package main
>
> import "fmt"
>
> func main() {
> src := []int{1, 2, 3}
> dst := []int{}
> fmt.Println(len(dst))
> copy(dst, src)
> fmt.Println(src)
> fmt.Println(dst)
> // [1 2 3]
> // []
>
> src2 := []int{1, 2, 3}
> dst2 := make([]int, len(src))
> copy(dst2, src2)
> fmt.Println(src2)
> fmt.Println(dst2)
> // [1 2 3]
> // [1 2 3]
> }
>
>
>
> But it seems unusual, is it should be like following?
>
> package main
>
> import "fmt"
>
> func main() {
> src := []int{1, 2, 3}
> dst := []int{}
> fmt.Println(len(dst))
> copy(dst, src)
> fmt.Println(src)
> fmt.Println(dst)
> // [1 2 3]
> // [1 2 3]
> }
>
>
>

-- 
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] Licenses

2016-09-30 Thread djadala


On Friday, September 30, 2016 at 5:18:28 PM UTC+3, Ian Lance Taylor wrote:
>
> On Thu, Sep 29, 2016 at 1:12 AM,  > wrote: 
> > Hi, 
> > May be OT, but: 
> > 
> > Can i  translate some GPLv2 licensed C code to GO, and publish it under 
> BSD 
> > new license ? 
> > Code comments are from original C code. 
>
> Despite some other replies here, I think you probably can, though you 
> can't copy the comments.  Note that I am not a lawyer.  And, that 
> said, don't do it, and don't do a clean room reimplementation either. 
> Respect the wishes of the original author, or explicitly ask 
> permission.  The free software community runs on respect for coders. 
> Don't breach that respect. 
>
>
> > Also, Can I in my BSD licensed GO project, link to GPLv2 library ? 
>
> Despite some other replies here, the answer to the question is 
> definitely yes, as long as you respect the requirements that the two 
> licenses impose on the fully linked program.  People link BSD and 
> GPLv2 code together all the time. 
>
> Ian 
>





Thanks all for answers, 
Ian, can you please explain (briefly) what are requirements that the two 
licenses impose on the program ?
Again thanks.

Djadala

-- 
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] Licenses

2016-09-29 Thread djadala
Hi,
May be OT, but:

Can i  translate some GPLv2 licensed C code to GO, and publish it under BSD 
new license ?
Code comments are from original C code.

Also, Can I in my BSD licensed GO project, link to GPLv2 library ?

Regards,
Djadala


-- 
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: Bug in go? Package net

2016-09-25 Thread djadala
don't ignore errors

On Monday, September 26, 2016 at 5:53:01 AM UTC+3, Jon Strauss wrote:
>
> This error:
>
> panic: runtime error: invalid memory address or nil pointer dereference
>
> [signal 0xb code=0x1 addr=0x20 pc=0x401487]
>
>
> goroutine 1 [running]:
>
> panic(0x50bfa0, 0xc82000a0c0)
>
> /usr/lib/go-1.6/src/runtime/panic.go:481 +0x3e6
>
> main.main()
>
> /root/Whois3/rest-whois-threaded/main.go:65 +0x67
>
> Is produced by this code: I commented line 65. Is there an error in the go?
>
> package main
>
>
> import (
>
> "os"
>
> "net"
>
> "syscall"
>
> "time"
>
> )
>
>
> func reader(incoming net.Conn, outgoing net.Conn,ready chan bool) {
>
>
> var buffer []byte
>
> <- ready
>
> buffer = make([]byte,2)
>
> for {  
>
> read, _ := incoming.Read(buffer)  
>
> outgoing.Write(buffer)
>
> if read == 0 {
>
> break
>
> }
>
> }
>
> return
>
> }
>
>
> func writer(outgoing net.Conn, incoming net.Conn, ready chan bool) {
>
>
> var buffer []byte
>
> <- ready
>
> buffer = make([]byte,2)
>
> for {
>
> read, _ := outgoing.Read(buffer)
>
> incoming.Write(buffer)
>
> if read == 0 {
>
> break
>
> }
>
> }
>
> return
>
> }
>
>
> func worker(connection net.Conn) {
>
> var ready chan bool
>
> var app net.Conn
>
> var process *os.Process
>
> var attr *syscall.ProcAttr
>
> var stuff []string
>
>
> attr.Dir = "/my/dir"
>
>
> pid,_ := syscall.ForkExec("/my/exec", stuff, attr)
>
> process.Pid = pid
>
> app, _= net.Dial("tcp", "127.0.0.1:5000")
>
> go reader(connection,app,ready)
>
> go writer(connection,app,ready)
>
>
> ready <- true
>
> time.Sleep(7 * time.Second)
>
> process.Kill()
>
> return
>
> }
>
>
> func main() {
>
> ln, _ := net.Listen("tcp", ":80")
>
>
> for {
>
> conn, _ := ln.Accept() // Line 65
>
> go worker(conn)
>
> }
>
>
> }
>

-- 
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: gorutine, channels

2016-09-02 Thread djadala
working examle:
https://play.golang.org/p/KLZdle7R47

On Friday, September 2, 2016 at 8:07:32 PM UTC+3, Ринат Галиев wrote:
>
> Я не могу заставить работать попеременно 2 gorutines:
> не использовать новый imports
> использовать каналы
> получить результаты: 1 2 3 4 5 6
> согte after "// Красноломкий "
>
> Основной пакет
>
>  // красноломкий
>
> импорт "Время"
>
>  
>
> FUNC главный () {
>
> идти FUNC () {
>
> для _, значение: = диапазон [] INT {1, 3, 5} {
>
> // красноломкий
>
> Println (значение)
>
> // красноломкий
>
> }
>
> }()
>
>  
>
> идти FUNC () {
>
> для _, значение: = диапазон [] INT {2, 4, 6} {
>
> // красноломкий
>
> Println (значение)
>
> // красноломкий
>
> }
>
> }()
>
>  
>
>
>  
>
> time.Sleep (time.Second)
>
> }
>

-- 
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: gorutine, channels

2016-09-02 Thread djadala


On Friday, September 2, 2016 at 8:07:32 PM UTC+3, Ринат Галиев wrote:
>
> Я не могу заставить работать попеременно 2 gorutines:
> не использовать новый imports
> использовать каналы
> получить результаты: 1 2 3 4 5 6
> согte after "// Красноломкий "
>
> Основной пакет
>
>  // красноломкий
>
> импорт "Время"
>
>  
>
> FUNC главный () {
>
> идти FUNC () {
>
> для _, значение: = диапазон [] INT {1, 3, 5} {
>
> // красноломкий
>
> Println (значение)
>
> // красноломкий
>
> }
>
> }()
>
>  
>
> идти FUNC () {
>
> для _, значение: = диапазон [] INT {2, 4, 6} {
>
> // красноломкий
>
> Println (значение)
>
> // красноломкий
>
> }
>
> }()
>
>  
>
>
>  
>
> time.Sleep (time.Second)
>
> }
>




wow, google translate of program source, i guess.

there are no guarantees that 2 goroutines  are executed one after one.  if 
you want some order of execution, you must synchronize explicitly these 
goroutines.


-- 
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: flag: Stack overflow when return stringer with fmt.Sprint

2016-09-01 Thread djadala
s/fmt.String/fmt.Sprintf/

On Thursday, September 1, 2016 at 12:25:24 PM UTC+3, dja...@gmail.com wrote:
>
> Hi,
> Do you know what infinite recursion is ?
> fmt.String use your String method
>
> see https://play.golang.org/p/jeOilZW7JU
>
>
> On Thursday, September 1, 2016 at 11:59:12 AM UTC+3, Muhammad Shulhan 
> wrote:
>>
>> Dear all,
>>
>> I will describe the problem step by step, please bear with me.
>>
>> Lets take a look at first example ,
>>
>> package main
>>>
>>> import (
>>>  "fmt"
>>> )
>>>
>>> type Slices []string
>>>
>>> func (sl *Slices) String() string {
>>>  // OK
>>>  return fmt.Sprint(sl)
>>> }
>>>
>>> func main() {
>>>  var slices Slices
>>>
>>>  fmt.Print("slices:", slices)
>>> }
>>>
>>
>>
>> Run: https://play.golang.org/p/Cjb0xCVaCC
>> Output:
>>
>> slices:[]
>>>
>>
>> Let change String() return to fmt.Sprint(*sl).
>>
>> Run: https://play.golang.org/p/St6TyltA56
>> Output:
>>
>> slices:[]
>>>
>>
>> Using the above prototype lets build a flag that parse Slices. Here is the 
>> code that return without stack overflow,
>>
>> package main
>>>
>>> import (
>>> "flag"
>>> "fmt"
>>> )
>>>
>>> type Slices []string
>>>
>>> func (sl *Slices) String() string {
>>> return fmt.Sprint(*sl)
>>> }
>>>
>>> func (sl *Slices) Set(vv string) error {
>>> // STUB for clarity
>>> return nil
>>> }
>>>
>>> func main() {
>>> var sl Slices
>>> flag.Var(&sl, "slices", "Test parsing slice flag.")
>>> flag.Parse()
>>>
>>> fmt.Printf("slices: %s\n", sl)
>>> }
>>
>>
>> Run: https://play.golang.org/p/Sol4C8hRk7
>> Output:
>>
>> slices: []
>>>
>>
>> Last one, lets change the String return to "fmt.Sprint(sl)".
>>
>> Run: https://play.golang.org/p/550Krvim77
>> Output:
>>
>> runtime: goroutine stack exceeds 25000-byte limit 
>>>
>> fatal error: stack overflow
>>>
>>  
>> Question: is this a bug? If it is I would report one.
>>
>> PS:
>>
>> Previous discussion that I found mentioning the same problem:
>>
>> * 
>> https://groups.google.com/forum/#!searchin/golang-nuts/fmt.Sprint|sort:relevance/golang-nuts/jJ72z0Ssahc/FDwArwNCiw4J
>>
>

-- 
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: flag: Stack overflow when return stringer with fmt.Sprint

2016-09-01 Thread djadala
Hi,
Do you know what infinite recursion is ?
fmt.String use your String method

see https://play.golang.org/p/jeOilZW7JU


On Thursday, September 1, 2016 at 11:59:12 AM UTC+3, Muhammad Shulhan wrote:
>
> Dear all,
>
> I will describe the problem step by step, please bear with me.
>
> Lets take a look at first example ,
>
> package main
>>
>> import (
>>  "fmt"
>> )
>>
>> type Slices []string
>>
>> func (sl *Slices) String() string {
>>  // OK
>>  return fmt.Sprint(sl)
>> }
>>
>> func main() {
>>  var slices Slices
>>
>>  fmt.Print("slices:", slices)
>> }
>>
>
>
> Run: https://play.golang.org/p/Cjb0xCVaCC
> Output:
>
> slices:[]
>>
>
> Let change String() return to fmt.Sprint(*sl).
>
> Run: https://play.golang.org/p/St6TyltA56
> Output:
>
> slices:[]
>>
>
> Using the above prototype lets build a flag that parse Slices. Here is the 
> code that return without stack overflow,
>
> package main
>>
>> import (
>> "flag"
>> "fmt"
>> )
>>
>> type Slices []string
>>
>> func (sl *Slices) String() string {
>> return fmt.Sprint(*sl)
>> }
>>
>> func (sl *Slices) Set(vv string) error {
>> // STUB for clarity
>> return nil
>> }
>>
>> func main() {
>> var sl Slices
>> flag.Var(&sl, "slices", "Test parsing slice flag.")
>> flag.Parse()
>>
>> fmt.Printf("slices: %s\n", sl)
>> }
>
>
> Run: https://play.golang.org/p/Sol4C8hRk7
> Output:
>
> slices: []
>>
>
> Last one, lets change the String return to "fmt.Sprint(sl)".
>
> Run: https://play.golang.org/p/550Krvim77
> Output:
>
> runtime: goroutine stack exceeds 25000-byte limit 
>>
> fatal error: stack overflow
>>
>  
> Question: is this a bug? If it is I would report one.
>
> PS:
>
> Previous discussion that I found mentioning the same problem:
>
> * 
> https://groups.google.com/forum/#!searchin/golang-nuts/fmt.Sprint|sort:relevance/golang-nuts/jJ72z0Ssahc/FDwArwNCiw4J
>

-- 
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: dynamic frequency ticker

2016-08-30 Thread djadala
https://play.golang.org/p/FMs01ACKJv  ?

Djadala

On Tuesday, August 30, 2016 at 8:46:23 PM UTC+3, seb@gmail.com wrote:
>
> In my application I select on a ticker channel, but sometimes need to have 
> the waiting time vary a bit. For not so frequent changes I could make a new 
> ticker everytime, but I have the feeling this is not the best solution for 
> higher frequencies and many rate changes. Best would be if I could tell my 
> existing ticker "from next tick on please use an interval of x". In fact 
> what I want is that the frequency changes over time.
>
> Any tips how to achieve that?
>

-- 
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: context race

2016-08-13 Thread djadala


On Saturday, August 13, 2016 at 4:56:45 PM UTC+3, upad...@gmail.com wrote:
>
> Now given receiving on a closed channel never returns, above is not safe. 
> I can check inside my second case if ctx.Err() is non nil, but its not a 
> very clean solution. 
>
>
receiving on *nil* channel never returns, receiving  on *closed* channel 
always return zero value.

Djadala

-- 
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: SetKeepAlive TCP server

2016-07-26 Thread djadala
you must also set keepalive period:
 SetKeepAlivePeriod( time.Minute)

On Wednesday, July 27, 2016 at 7:19:24 AM UTC+3, EdgarAlejandro Vintimilla 
wrote:
>
> How can I let a conn alive, I have this code, the TCP server work but  it 
> does not keep alive
>
>
> func main() {
> // Listen for incoming connections.
> l, err := net.Listen(CONN_TYPE, CONN_HOST+":"+CONN_PORT)
> if err != nil {
> fmt.Println("Error listening:", err.Error())
> os.Exit(1)
> }
> // Close the listener when the application closes.
> defer l.Close()
> fmt.Println("Listening on " + CONN_HOST + ":" + CONN_PORT)
> for {
> // Listen for an incoming connection.
> 
> conn, err := l.Accept()
> if err != nil {
> fmt.Println("Error accepting: ", err.Error())
> os.Exit(1)
> }
>
> // Handle connections in a new goroutine.
> go handleRequest(conn)
> }
> }
>
> // Handles incoming requests.
> func handleRequest(conn net.Conn) {
>   conn.(*net.TCPConn).SetKeepAlive(true)
>   buf := make([]byte, 1024)
>
>   // Read the incoming connection into the buffer.
>   reqLen, err := conn.Read(buf)
>   buf = buf[:reqLen]
>
>   if err != nil {
> fmt.Println("Error reading:", err.Error())
>   }
>
>   var packageData string = ""
>   for i := 0; i < len(buf)-1; i++ {
> packageData += fmt.Sprintf("%02x", buf[i])
>   }
>   //...
>   // Close the connection when you're done with it.
>   conn.Close()
> 
> }
>
>
>
>
>
>
>
> On Tuesday, July 26, 2016 at 12:21:51 PM UTC-5, Matt Harden wrote:
>>
>> This is because your conn variable is probably of the type net.Conn (an 
>> interface) rather than *net.TCPConn, so the compiler doesn't know that the 
>> SetKeepAlive method is available. If you use a type assertion as djadala 
>> suggested: conn.(*net.TCPConn).SetKeepAlive then you are telling the 
>> compiler that the value in the conn variable is actually a TCP connection 
>> and so the SetKeepAlive method becomes available. This will panic if the 
>> conn variable does not actually contain a *net.TCPConn.
>>
>> On Tue, Jul 26, 2016 at 12:09 AM  wrote:
>>
>>> tryconn.(*TCPConn <https://golang.org/pkg/net/#TCPConn>
>>> ).SetKeepAlive
>>>
>>> On Tuesday, July 26, 2016 at 10:04:41 AM UTC+3, EdgarAlejandro 
>>> Vintimilla wrote:
>>>>
>>>>
>>>>
>>>>
>>>> when I use the conn.SetKeepAlive i get this error: reference to 
>>>> undefined field or method ‘SetKeepAlive’
>>>>
>>>> https://golang.org/pkg/net/#TCPConn.SetKeepAlive
>>>>
>>>> why? 
>>>>
>>>> but If I use conn.SetReadDeadline it works ok
>>>>
>>>> https://golang.org/pkg/net/#IPConn.SetReadDeadline
>>>>
>>> -- 
>>> 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: SetKeepAlive TCP server

2016-07-26 Thread djadala
tryconn.(*TCPConn ).SetKeepAlive

On Tuesday, July 26, 2016 at 10:04:41 AM UTC+3, EdgarAlejandro Vintimilla 
wrote:
>
>
>
>
> when I use the conn.SetKeepAlive i get this error: reference to undefined 
> field or method ‘SetKeepAlive’
>
> https://golang.org/pkg/net/#TCPConn.SetKeepAlive
>
> why? 
>
> but If I use conn.SetReadDeadline it works ok
>
> https://golang.org/pkg/net/#IPConn.SetReadDeadline
>

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