Re: [go-nuts] cgo and time.After

2018-05-20 Thread Chris Burkert
Dear Jakob and all,

indeed I was blind. This works like a charm:
amount := 42
remaining := amount
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for remaining > 0 {
select {
case <-ticker.C:
fmt.Printf("Progress: %d left from %d\n", remaining, amount)
case <-donChan:
remaining--
case res := <-resChan:
fmt.Println(res)
}
}

thanks all!
Chris

On Saturday, May 19, 2018 at 9:16:19 PM UTC+2, Jakob Borg wrote:
>
> On 19 May 2018, at 16:25, Chris Burkert > 
> wrote: 
> > 
> > case <-time.After(5 * time.Second): 
> > fmt.Printf("Progress: %d left from %d\n", remaining, amount) 
>
> It's not super clear from your post if you're aware of this already, but 
> this case will only fire after the select has been blocked for five 
> seconds. If there is any activity on the other cases one of those will 
> proceed, you'll get another loop iteration, and another five second timeout 
> before status output. 
>
> Typically you'd use a five second ticker instead to get a channel event 
> every five seconds and use that to print status output. 
>
> //jb

-- 
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] What powers search on golang.org?

2018-05-20 Thread meirfischer
golang.org let’s you search all stdlib go source code.

For example, see https://golang.org/search?q=hello

Where is the code that serves these search queries? If the code is not public, 
does it use a publicly available or at least publicly documented search engine?

-- 
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: What powers search on golang.org?

2018-05-20 Thread alex . rou . sg
https://github.com/golang/blog/blob/a317451f36b22672c8a079489aa5425b9fa3a9da/content/context/google/google.go

Google search

On Monday, 21 May 2018 04:08:18 UTC+8, meir fischer wrote:
>
> golang.org let’s you search all stdlib go source code. 
>
> For example, see https://golang.org/search?q=hello 
>
> Where is the code that serves these search queries? If the code is not 
> public, does it use a publicly available or at least publicly documented 
> search engine?

-- 
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: What powers search on golang.org?

2018-05-20 Thread alex . rou . sg
Tho there is also the offline one used by godoc

https://github.com/golang/tools/blob/4e70a1b26a7875f00ca1916637a876b5ffaeec59/godoc/search.go

On Monday, 21 May 2018 05:27:53 UTC+8, alex@gmail.com wrote:
>
>
> https://github.com/golang/blog/blob/a317451f36b22672c8a079489aa5425b9fa3a9da/content/context/google/google.go
>
> Google search
>
> On Monday, 21 May 2018 04:08:18 UTC+8, meir fischer wrote:
>>
>> golang.org let’s you search all stdlib go source code. 
>>
>> For example, see https://golang.org/search?q=hello 
>>
>> Where is the code that serves these search queries? If the code is not 
>> public, does it use a publicly available or at least publicly documented 
>> search engine?
>
>

-- 
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] db interface design

2018-05-20 Thread yang sheng
Hi

I am trying to practice golang and have some questions regarding to 
interface design.

Say I want to create a simple app to store the book and its author info. I 
am planning to create interfaces so that I can use different db driver 
(mysql/mongo/redis...) as long as if they implemented DB interface:
https://play.golang.org/p/DOw83_OqBOe

I have a couple questions:

1. there are a lot of similar functions, for example NewBook and NewAuthor. 
The difference is type of argument passed into the function. Is it a good 
idea to combine those 2 functions with a generic New(interface{}) (string, 
error) function and  reflect the actual type inside? 

2. Sometimes we query based on one or more conditions (where clause),  for 
example find books based on author/release data/ price.  Should I create a 
generic function like:

func FindBooks(map[string]interface{}) ([]Book, error)

that passed in a map of condition kv and do the typer assertion of each 
condition key values?


Thanks for any advice


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


[go-nuts] How can I get the last followed URL use http.Client on 302 Redirections?

2018-05-20 Thread Darren Hoo
if this is how  the redirections go:

A (original url) => B => C => D

I want to know the url of request D

the URL of A is never changed, and get the Location header from request is 
impossible.

-- 
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 can I get the last followed URL use http.Client on 302 Redirections?

2018-05-20 Thread Darren Hoo
Found a hacky solution,  https://play.golang.org/p/jLlKR3yjWSw
Any better ideas?


var client = &http.Client{
CheckRedirect: setFollowURL,
}

func setFollowURL(req *http.Request, via []*http.Request) error {
via[0].URL = req.URL
if len(via) >= 10 {
return errors.New("stopped after 10 redirects")
}
return nil
}


On Monday, May 21, 2018 at 12:25:37 PM UTC+8, Darren Hoo wrote:
>
> if this is how  the redirections go:
>
> A (original url) => B => C => D
>
> I want to know the url of request D
>
> the URL of A is never changed, and get the Location header from request is 
> impossible.
>

-- 
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] I am confused.

2018-05-20 Thread John
  Hello I am just a random person in this small planet of the creation that 
happens to think that artificial intelligence will take over the world of 
jobs in the future. With that point of I started to learn Java Script on 
Khan Academy but didn't quite make that much progress. So I think that now 
it is time for me to do some serious coding with my OWN launcher or 
compiler. And after a while I chosen go and got me here. But before I join 
this group I tried to download the compiler but it didn't quite work. When 
I finished downloading the 65 MSI installer it only gave me the option to 
delete the itself or itself and maybe the actual go compiler or repair 
itself, which when I clicked it it ran something and nothing visually 
changed. The source I was unable to open for some reason, the computer says 
it is to big and needs something program to open it. I tried the Internet 
Explorer but it didn't do anything. But when i clicked the store it shows 
me that if I have a Microsoft account it can download an program that can 
open the source which I don't have. By the way I am on a Windows computer. 
So please Gophers help me become a Gopher too.

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