[go-nuts] http.Client interface

2016-12-11 Thread omarshariffdontlikeit
Just a quick question - I've noticed that the http package doesn't have an 
interface for Client. How would I swap out a http.Client that is required 
by a third-party library with a another that supports, say retries with 
exponential back-off? It appears that it is not possible? Would the http 
package benefit from an interface for the http.Client?

Cheers!
Ben 

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


[go-nuts] Re: thread.join equivalent in Go

2016-12-11 Thread Stannis Kozlov
I've been looking for a solution for .join like method in Go. Finally 
solution came with "sync":
https://golang.org/pkg/sync/#WaitGroup

-- 
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: Network error handle

2016-12-11 Thread Stannis Kozlov
I've modified the function accordingly:

func sock() {
  conn, err := net.Dial("tcp", "192.168.0.1:9991")
  if err != nil {
fmt.Printf("\nDial has an error for you %v", err)
  }

  fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n")
  status, err := bufio.NewReader(conn).ReadString('\n')
  fmt.Printf("%v",status)
}

Nevertheless same issue appearing:
Dial has an error for you: dial tcp 192.168.0.1:9991: getsockopt: 
connection refusedpanic: runtime error: invalid memory address or nil 
pointer dereference 
[signal 0xb code=0x1 addr=0x20 pc=0x4612dc]
 

"Connection refused" is simple socket state, how can it call a panic?

Here is my go version:
$ go version  
go version go1.6.3 linux/amd64Enter code here...


-- 
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: Network error handle

2016-12-11 Thread Dave Cheney
Your printf does not include a newline character, so the panic message is 
from your usage of conn in the line

fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n")

Because an error occured during the dail, you cannot use or assume conn has 
any sensible value.

On Sunday, 11 December 2016 21:43:02 UTC+11, Stannis Kozlov wrote:
>
> I've modified the function accordingly:
>
> func sock() {
>   conn, err := net.Dial("tcp", "192.168.0.1:9991")
>   if err != nil {
> fmt.Printf("\nDial has an error for you %v", err)
>   }
>
>   fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n")
>   status, err := bufio.NewReader(conn).ReadString('\n')
>   fmt.Printf("%v",status)
> }
>
> Nevertheless same issue appearing:
> Dial has an error for you: dial tcp 192.168.0.1:9991: getsockopt: 
> connection refusedpanic: runtime error: invalid memory address or nil 
> pointer dereference 
> [signal 0xb code=0x1 addr=0x20 pc=0x4612dc]
>  
>
> "Connection refused" is simple socket state, how can it call a panic?
>
> Here is my go version:
> $ go version  
> go version go1.6.3 linux/amd64Enter code here...
>
>
>

-- 
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: Network error handle

2016-12-11 Thread Stannis Kozlov
Thanks, folks!
It's clear now:

func sock() {
  conn, err := net.Dial("tcp", "192.168.0.1:80")
  if err != nil {
fmt.Printf("\nDial has an error for you: %v\n", err)
return
  }
  fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n")
  status, err := bufio.NewReader(conn).ReadString('\n')
  fmt.Printf("%v",status)
  conn.Close()
}

I'm Go newcomer and stunned with threading compared to Python

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


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

2016-12-11 Thread Daniel Theophanes
How would you put them in query when args are the last ...warm?

On Sat, Dec 10, 2016, 22:44 Tamás Gulácsi  wrote:

> I'd also like to change the API for passing options as Andrè suggested: by
> optional funcs. But everywhere - they're not to be in a Context!
>
> To put them in Context feels a hack.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/20NtIGTgBeg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


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

2016-12-11 Thread Gulácsi Tamás
Good question.
QueryContext(ctx context.Context, query QueryWithOpts, args ...interface{})
(sql.Rows, error)
?

Where
type QueryWithOpts struct {
fmt.Stringer
opts []qryOpt
}

and

func Query(qry string, options ...qryOpt) QueryWithOpts

á'lá sql.NamedArg.


But this feels just as hacky, as putting those options into the context...

Daniel Theophanes  ezt írta (időpont: 2016. dec. 11.,
V, 14:48):

> How would you put them in query when args are the last ...warm?
>
> On Sat, Dec 10, 2016, 22:44 Tamás Gulácsi  wrote:
>
> I'd also like to change the API for passing options as Andrè suggested: by
> optional funcs. But everywhere - they're not to be in a Context!
>
> To put them in Context feels a hack.
>
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/20NtIGTgBeg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>

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


[go-nuts] Fun way to learn about Go (and others langages)

2016-12-11 Thread Jérôme LAFORGE
Hello all,
My workmate pointed me a funny web site for working/learning about Go (and 
others language) with lot of fun.
https://www.codingame.com

By the way, you can find here the result of one of my first challenges:
https://www.codingame.com/replay/solo/167065503
(you have to drive the man with the gun, who is charge of protect the 
humans from zombies)

Jérôme

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


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

2016-12-11 Thread Daniel Theophanes
I don't think ops in context is how I would clean room design this, but it
is the better of many other options.

The tx begin is easier, but still difficult when I need to ensure drivers
can set custom attributes. The problem with something like you suggested is
it deviates too far from the original API.

If you have a concrete proposal, file an issue cc me in the next day or
two. At the least tx begin needs a way for drivers to set custom
attributes.

On Sun, Dec 11, 2016, 06:48 Gulácsi Tamás  wrote:

> Good question.
> QueryContext(ctx context.Context, query QueryWithOpts, args
> ...interface{}) (sql.Rows, error)
> ?
>
> Where
> type QueryWithOpts struct {
> fmt.Stringer
> opts []qryOpt
> }
>
> and
>
> func Query(qry string, options ...qryOpt) QueryWithOpts
>
> á'lá sql.NamedArg.
>
>
> But this feels just as hacky, as putting those options into the context...
>
> Daniel Theophanes  ezt írta (időpont: 2016. dec.
> 11., V, 14:48):
>
> How would you put them in query when args are the last ...warm?
>
> On Sat, Dec 10, 2016, 22:44 Tamás Gulácsi  wrote:
>
> I'd also like to change the API for passing options as Andrè suggested: by
> optional funcs. But everywhere - they're not to be in a Context!
>
> To put them in Context feels a hack.
>
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/20NtIGTgBeg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>

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


Re: [go-nuts] CFG for a Go program

2016-12-11 Thread akshanshchahal
Hi

If you can help with this problem, whenever you are free. I am not sure how 
to get any starting node of type BasicBlock (ssa#BasicBlock 
), so that I can 
traverse the Graph using Preds/Succs relation.
I am able to get ssa/program (ssa#Program 
) for a given .go file 
by using packages ssautil, parser, token and functions ParseFile(), 
CreateProgram() etc.
I took some help from here example_test.go 

But how to get any node of type BasicBlock from that ssa.Program I have ?

Thanks
Akshansh

On Wednesday, November 30, 2016 at 7:55:25 PM UTC+5:30, adon...@google.com 
wrote:
>
> On Wednesday, 30 November 2016 05:13:15 UTC-5, akshans...@gmail.com wrote:
>>
>> Thanks a lot for your valuable suggestions. I think the one using SSA 
>> form will be helpful for my project. 
>>
>
> Lest there be any confusion: there are two unrelated SSA forms for Go 
> code, the one used internally by the gc compiler and the one defined by the 
> golang.org/x/tools/go/ssa package.
>

-- 
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] CFG for a Go program

2016-12-11 Thread 'Alan Donovan' via golang-nuts
On 11 December 2016 at 12:21,  wrote:

> I am not sure how to get any starting node of type BasicBlock (
> ssa#BasicBlock ), so
> that I can traverse the Graph using Preds/Succs relation.
>

An ssa.Program is a essentially collection of packages.  Use one of its
methods (Package or ImportedPackage) to get the ssa.Package you want.
Then, use the (*Package).Func method to get the function you want.  If you
want a method, you can use (*Program).LookupMethod, giving it the receiver
type and the method name.

Once you have an *ssa.Function f, its control flow graph is rooted at
r.Blocks[0], which is the entry block.  To enumerate blocks in arbitrary
order, range over the Blocks slice.  For graph order, traverse depth-first
over the Succs slice; Preds is its inverse.  To visit nodes in dominator
tree preorder, use the Dominees method.

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


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

2016-12-11 Thread Tamás Gulácsi
2016. december 11., vasárnap 16:20:51 UTC+1 időpontban Daniel Theophanes a 
következőt írta:
>
> I don't think ops in context is how I would clean room design this, but it 
> is the better of many other options.
>
> The tx begin is easier, but still difficult when I need to ensure drivers 
> can set custom attributes. The problem with something like you suggested is 
> it deviates too far from the original API.
>
> If you have a concrete proposal, file an issue cc me in the next day or 
> two. At the least tx begin needs a way for drivers to set custom 
> attributes. 
>
>>

https://github.com/golang/go/issues/18284

Should I send a CL? We could discuss it in the issue. 

-- 
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] Any solution for Multicast IGMPv3 support in windows for Golang?

2016-12-11 Thread jamoranca
Hello:

It seems that IGMPv3 is only supported in linux in the 
golang.org/x/net/ipv4.
Windows is not supported. See the following comment in 
golang.org/x/net/ipv4/multicast_test.go 

if err := p.JoinSourceSpecificGroup(ifi, &grp, tt.src); err != nil {

switch runtime.GOOS {

case "freebsd", "linux":

default: // platforms that don't support IGMPv2/3 fail here

t.Logf("not supported on %s", runtime.GOOS)

continue

}

t.Fatal(err)


Do you know of any library that allows IGMPv2/3 support for Golang in Windows?


Thank you


Javier

-- 
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] Any golang support of Multicast from specific source in Windows?

2016-12-11 Thread Javier Moran
Hi,

I have been trying to build a golang program on Windows that joins to a 
Multicast group from a particular source address, so far unsucessfully. 
Looking at golang.org/x/ipv4/multicast_test.go, it looks like 
JoinSourceSpecificGroup is not supported in Windows.




if err := p.JoinSourceSpecificGroup(ifi, &grp, tt.src); err != 
nil { 

switch runtime.GOOS {

case "freebsd", "linux":

default: // platforms that don't support IGMPv2/3 fail here

t.Logf("not supported on %s", runtime.GOOS)

continue

}

t.Fatal(err)



(The comment is a bit misleading as I have seen in wireshark that JoinGroup 
generates a IGMPv3 message).

Do you know of any library or method in Golang to enable multicast group 
joining for particular address on Windows?

Thank you

Javier

-- 
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] http.Client interface

2016-12-11 Thread Kevin Conway
>  How would I swap out a http.Client that is required by a third-party
library with a another that supports, say retries with exponential back-off?
I'd suggest looking at http.Transport and http.RoundTripper [
https://golang.org/pkg/net/http/#RoundTripper]. The docs explicitly forbid
using RoundTripper to implement higher level protocol features like
retry-with-backoff based on HTTP response codes, but those are your only
hooks into making this a feature of the client rather than moving the retry
logic somewhere else.


On Sun, Dec 11, 2016 at 4:07 AM  wrote:

> Just a quick question - I've noticed that the http package doesn't have an
> interface for Client. How would I swap out a http.Client that is required
> by a third-party library with a another that supports, say retries with
> exponential back-off? It appears that it is not possible? Would the http
> package benefit from an interface for the http.Client?
>
> Cheers!
> Ben
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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: Any golang support of Multicast from specific source in Windows?

2016-12-11 Thread mikioh . mikioh
looks like windows vista or above supports the required api.
windows port stuff in net and x/net/{ipv4,ipv6} packages still lack tons of 
control knobs.
feel free to send a patch for review if you'd like. thanks.

cf: https://github.com/golang/go/wiki#contributing-to-the-go-project

On Monday, December 12, 2016 at 3:49:34 AM UTC+9, Javier Moran wrote:
>
> Hi,
>
> I have been trying to build a golang program on Windows that joins to a 
> Multicast group from a particular source address, so far unsucessfully. 
> Looking at golang.org/x/ipv4/multicast_test.go, it looks like 
> JoinSourceSpecificGroup is not supported in Windows.
>
>
>
>
> if err := p.JoinSourceSpecificGroup(ifi, &grp, tt.src); err != 
> nil { 
>
> switch runtime.GOOS {
>
> case "freebsd", "linux":
>
> default: // platforms that don't support IGMPv2/3 fail here
>
> t.Logf("not supported on %s", runtime.GOOS)
>
> continue
>
> }
>
> t.Fatal(err)
>
>
>
> (The comment is a bit misleading as I have seen in wireshark that 
> JoinGroup generates a IGMPv3 message).
>
> Do you know of any library or method in Golang to enable multicast group 
> joining for particular address on Windows?
>
> Thank you
>
> Javier
>

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