[go-nuts] Re: sharing "go runtime VM" for many go application

2016-11-28 Thread Dave Cheney
Go is not a virtual machine language, it's compiled to native machine code, 
like a C program. Each Go program does have a runtime package which 
provides the garbage collector to manage the programs heap, and Go programs 
do follow a pattern of over allocating with the expectation that the 
operating system will lazily fulfil that allocation when the Go program 
actually does come to use that memory.

It's a moot point at the moment because there is no way to share a Go 
program's runtime between multiple programs, but I don't think this would 
achieve the saving you expect compared to JITed virtual machine runtimes 
like nodejs.


On Tuesday, 29 November 2016 18:30:09 UTC+11, Thaniyarasu Kannusamy wrote:
>
> thanks Dave,
>
> i am thinking about server less architecture with golang.
> i feel that "sharing languange runtime/VM" will be next technology than 
> the container/kubernetes era.
> already aws offering lambda service for serverless architecture.
>
> i know that nodejs is running in sandbox mode with event based parallel 
> execution. where node VM is shared for each sandbox.
> so i think that node sandbox can be useful to isolate each application 
> scope where we can achieve 'sharing runtime' effectively. 
>
> i am not an expert in core nodejs, so my question to you is 
> Is sharing "Nodejs VM" for multiple node application possible ???
>
> sorry for my late reply 
>
> Thanks
> Thani
>
> On Tuesday, 29 November 2016 11:30:28 UTC+5:30, Dave Cheney wrote:
>>
>> No, this is not currently possible. 
>>
>> If it was possible in the future, what would this let you do that you 
>> cannot do today?
>>
>

-- 
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: sharing "go runtime VM" for many go application

2016-11-28 Thread Thaniyarasu Kannusamy
thanks Dave,

i am thinking about server less architecture with golang.
i feel that "sharing languange runtime/VM" will be next technology than the 
container/kubernetes era.
already aws offering lambda service for serverless architecture.

i know that nodejs is running in sandbox mode with event based parallel 
execution. where node VM is shared for each sandbox.
so i think that node sandbox can be useful to isolate each application 
scope where we can achieve 'sharing runtime' effectively. 

i am not an expert in core nodejs, so my question to you is 
Is sharing "Nodejs VM" for multiple node application possible ???

sorry for my late reply 

Thanks
Thani

On Tuesday, 29 November 2016 11:30:28 UTC+5:30, Dave Cheney wrote:
>
> No, this is not currently possible. 
>
> If it was possible in the future, what would this let you do that you 
> cannot do today?
>

-- 
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: need library suggestions on writing a record program

2016-11-28 Thread biatche



The above is what the present DOS program looks like. Within each section 
are simply input/text fields. This certain old man who wants this done 
doesn't want a web interface. Before I begin learning, I've been wondering 
how I should setup input fields. should termbox be responsible for it? 
or termui as you suggested (this  seems more for monitoring...) or even 
gocui?

If anyone is kind enough to show some example code of a page with input 
fields maybe 1-2 input fields it'd greatly help.


On Tuesday, November 29, 2016 at 1:45:25 PM UTC+8, Jason Playne wrote:
>
> If you really must use a terminal ui - maybe try 
> https://github.com/gizak/termui it seems quite nice. if you can make 
> people SSH into your app (using some golang ssh server magic) that might be 
> a way to go as well.
>
> Otherwise go for a web based solution (as layout would be much easier)
>
> On 29 November 2016 at 03:19, Rick  > wrote:
>
>> I've written a small program for work in gocui and am quite happy with 
>> the results.
>>
>>
>> On Monday, 28 November 2016 08:12:35 UTC-8, bia...@gmail.com wrote:
>>>
>>> i'd like to rewrite an old dos medical patient record program in go for 
>>> a friend. its not a complex program by any means
>>>
>>> i'd probably use go-sqlite3 for storage but its the terminal part where 
>>> I'm confused. should i use gocui or termbox directly?
>>>
>>> the program will only have menus to be controlled using arrow-keys, 
>>> hotkeys, fields for keying in data
>>>
>>> if there are any other libs i should know of that may be useful in this 
>>> task please share.
>>>
>>> keep in mind, i have no knowledge of go.. but this should be the first 
>>> first proper programming language i'd learn. (im currently reasonable in 
>>> bash scripting)
>>>
>>>
>>> -- 
>> 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] sharing "go runtime VM" for many go application

2016-11-28 Thread Dave Cheney
No, this is not currently possible. 

If it was possible in the future, what would this let you do that you cannot do 
today?

-- 
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] sharing "go runtime VM" for many go application

2016-11-28 Thread Thaniyarasu Kannusamy
we all knows that sharing "Linux Kernel" is possible in container world.
i also want to know further that, 
is sharing "Go Runtime VM" is possible in anyway ?
so we can able to share a common "Go Runtime VM" for many go application.
if that is possible then we can able to run 'Go Runtime VM' effectively in 
serverless architecture.

i know that 'Go Runtime VM' must be start from a "func main()"

Thanks
Thani

-- 
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: need library suggestions on writing a record program

2016-11-28 Thread Jason Playne
If you really must use a terminal ui - maybe try
https://github.com/gizak/termui it seems quite nice. if you can make people
SSH into your app (using some golang ssh server magic) that might be a way
to go as well.

Otherwise go for a web based solution (as layout would be much easier)

On 29 November 2016 at 03:19, Rick 
wrote:

> I've written a small program for work in gocui and am quite happy with the
> results.
>
>
> On Monday, 28 November 2016 08:12:35 UTC-8, bia...@gmail.com wrote:
>>
>> i'd like to rewrite an old dos medical patient record program in go for a
>> friend. its not a complex program by any means
>>
>> i'd probably use go-sqlite3 for storage but its the terminal part where
>> I'm confused. should i use gocui or termbox directly?
>>
>> the program will only have menus to be controlled using arrow-keys,
>> hotkeys, fields for keying in data
>>
>> if there are any other libs i should know of that may be useful in this
>> task please share.
>>
>> keep in mind, i have no knowledge of go.. but this should be the first
>> first proper programming language i'd learn. (im currently reasonable in
>> bash scripting)
>>
>>
>> --
> 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.


Re: [go-nuts] bug report?: go font box drawing is wrong

2016-11-28 Thread Nigel Tao
On Mon, Nov 28, 2016 at 5:28 PM,   wrote:
> Sorry if this is the wrong place.

This place is as good as any other. Thanks for the bug report. I'll
pass it on to Bigelow & Holmes.

-- 
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] Sendgrid on App Engine urlfetch client instead of defaulthttp client

2016-11-28 Thread vanmulders1992
I'm running my API backend in Go on App Engine

When a user creates an account, he gets sent an activation email.

The normal tutorial for this doesn't work since App engine refuses the 
default http client and I have the urlfetch one

I've been trying to figure this out for hours but can't seem to get it right

My code right now 

requestHeaders := make(map[string]string)
requestHeaders["Authorization"] = "Bearer api_key"
requestHeaders["User-Agent"] = "sendgrid/3.1.0o"
requestHeaders["Accept"] = "application/json"

request := Request{
Method : "POST",
BaseURL : "https://api.sendgrid/com/v3/mail/send;,
Headers : requestHeaders,

}
request.Body = []byte(` {
"personalizations": [
   {
   "to": [
   {
   "email": "`+user_email+`"
   }
   ],
   "substitutions" : {
"-username-" : "`+username+`",
"-code-" : "`+user_code+`",
"-email-" : "`+user_email+`"
   }
   }
   ],
   "from": {
   "email": "noreply@"
   },
   "template_id" : "f69ce275-2421-4fca-beb0-247482ea3af0"
}`)

customClient := urlfetch.Client(appengine.NewContext(r))
response,err := customClient.Do(request)

Which gives me "Cannot use request (type Request) as type *http.Request in 
argument to customClient.Do

Where do I add in the bit that makes the call use the urlfetch instead of 
the default http client?

Many 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: multiple html templates

2016-11-28 Thread Jon Calhoun
What you are doing seems pretty normal. You could technically parse each 
HTML file into it's own template and then just use

  
baseTemplate.Execute(...)

and 

dataTemplate.Execute(...) 

in your code instead, but I really doubt what you are doing has a 
noticeable performance hit (if it even has one).


On Sunday, November 27, 2016 at 3:03:16 PM UTC-5, keit...@gmail.com wrote:
>
> Hello,
>
> I am building a site which will have the following pages, "/" (home), 
> "/about", and "/data" which will show some data using DataTables 
> . 
>
> "/", "/about" will be simple so I am using templates/base.html but for 
> /data I would still like to use tempaltes/data.html because I need to load 
> DataTables code. To do this I am creating a seperate handler and I am not 
> sure if this is the right way to do it.
>
> So, is a seperate handler needed? and how inefficient is it?
>
>
>
>
> var templates = template.Must(template.ParseFiles("templates/base.html", 
> "templates/data.html")) 
>
> func handler(w http.ResponseWriter, r *http.Request) { 
>   
> log.Printf(r.URL.Path[1:]) 
> myVars := 
> Variables{"Main", "My Heading #1"} 
> err := 
> templates.ExecuteTemplate(w, "base.html", myVars)   
> 
>   if err != nil { 
>   
> http.Error(w, err.Error(), http.StatusInternalServerError) 
>   
> return 
> }
> }
>
>  
> func staticHandler(w http.ResponseWriter, r *http.Request) {   
> 
> 
> http.ServeFile(w, r, r.URL.Path[1:])   
> 
> 
> } 
> 
>  
>   
> 
>  
> func dataHandler(w http.ResponseWriter, r *http.Request) { 
> 
> 
> myVars := Variables{"About", "About page"} 
> 
> 
> err := templates.ExecuteTemplate(w, "data.html", myVars)   
> 
> 
> if err != nil {   
> 
>  
> http.Error(w, err.Error(), http.StatusInternalServerError) 
> 
> 
> return 
> 
> 
> } 
> 
>  
> } 
> 
>  
>  
> func main() { 
> 
>  
> fmt.Printf("ok\n") 
> 
> 
> 

[go-nuts] Heap fragmentation due to protobuffs serialization/de-serialization

2016-11-28 Thread Dave Cheney
It looks ok to me, the svg.released number is growing which suggests that 
fragmentation is not an 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] Re: net/http and errors.

2016-11-28 Thread Dave Cheney
Indeed. Does your program differentiate between a URL not resolving, the 
webserver at the other end being down or refusing to connect, or it returnining 
a non temporary fatal error, 4xx? 

-- 
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: net/http and errors.

2016-11-28 Thread James Bardin
If you want to assert your way down to the original error, the order of the 
structures returned from http.Get is:

if err, ok := err.(*url.Error); ok {
if err, ok := err.Err.(*net.OpError); ok {
if err, ok := err.Err.(*net.DNSError); ok {
fmt.Println("DNS ERROR:", err)
}
}
}

Again though, the action (http.Get) failed regardless of the reason, so you 
would usually the errors all in the same manner. You can't necessarily 
count on a DNS error being permanent either, just look at what happened a 
few weeks ago, when a huge number of major sites couldn't be resolved. 





On Monday, November 28, 2016 at 12:01:18 PM UTC-5, mb.dha...@gmail.com 
wrote:
>
> I'm downloading a large number of urls and the result is expected to have 
> failure reasons, DNS lookup failed being one.
>
> calling lookup manually would solve my issue, I suppose. Just wanted to 
> make sure that I'm not missing any obvious solutions.
>
> 1. lookup DNS and if it succeeds, 
> 2. try http.Get - which calles Lookup again (also maybe DNS server went 
> down now - improbable but not impossible?)
>
>
> On Monday, November 28, 2016 at 1:05:25 PM UTC+1, Dave Cheney wrote:
>>
>> What specifically do you want to handle about DNS errors ?
>>
>> If you have a set of possible dns names and you don't know if some of 
>> them are valid, you could use net.LookupHost to check which ones are valid 
>> before calling http.Get.
>>
>> On Monday, 28 November 2016 22:44:37 UTC+11, mb.dha...@gmail.com wrote:
>>>
>>> But AFIU, err.Temporary() could be true for other kind of errors that 
>>> might happen, isn't that a problem if I only want to handle DNS errors?
>>>
>>>
>>> On Friday, November 25, 2016 at 6:35:59 PM UTC+1, Victor Vrantchan wrote:

 In Go, you can check if a type satisfies a particular behavior by 
 declaring an interface, and then checking if the type satisfies that 
 interface. 
 In your case, you can check if the error is `Temporrary()` or not. 

 See this snippet as an example: https://I don't 
 thinplay.golang.org/p/Ffyg61iDpB 

 I recommend 
 https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully
  
 and.or the GopherCon talk https://www.youtube.com/watch?v=lsBF58Q-DnY 
 by Dave Cheney for a more in-depth presentation of this idea. 

 On Friday, November 25, 2016 at 12:00:06 PM UTC-5, mb.dha...@gmail.com 
 wrote:
>
> This is a question about the net/http API, Googling was not very 
> helpful.
>
> _, err := http.Get("https://random_non_existing_domain.com;)
>
>
> Following code will obviously fail, but how can I check if it failed 
> because of DNS error not because a billion other things that might have 
> gone wrong?
>
> I tried this, (mostly as a shot in the dark)
>
> if e, ok := err.(net.Error); ok {
> fmt.Println("dial error", e.Temporary())
> }
> if e, ok := err.(*net.AddrError); ok {
> fmt.Println("addr rror", e.Temporary())
> }
> if e, ok := err.(*net.DNSError); ok {
> fmt.Println(e)
>
> and it seems to print 
>
>dial error false
>
> Is there any easy way to do what I'm trying to achieve?
>
> -
> dbalan
> @notmycommit
>
>
>

-- 
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: need library suggestions on writing a record program

2016-11-28 Thread Rick
I've written a small program for work in gocui and am quite happy with the 
results.

On Monday, 28 November 2016 08:12:35 UTC-8, bia...@gmail.com wrote:
>
> i'd like to rewrite an old dos medical patient record program in go for a 
> friend. its not a complex program by any means
>
> i'd probably use go-sqlite3 for storage but its the terminal part where 
> I'm confused. should i use gocui or termbox directly?
>
> the program will only have menus to be controlled using arrow-keys, 
> hotkeys, fields for keying in data
>
> if there are any other libs i should know of that may be useful in this 
> task please share.
>
> keep in mind, i have no knowledge of go.. but this should be the first 
> first proper programming language i'd learn. (im currently reasonable in 
> bash scripting)
>
>
>

-- 
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] Can anyone explain this section of the unicode/utf8 test suite?

2016-11-28 Thread Jan Mercl
On Mon, Nov 28, 2016 at 7:18 PM Pietro Gagliardi 
wrote:

> What is this supposed to be doing? I tried going through the git history
to find any context and the only thing I can figure is that there are lots
of leftovers from super early Go (in fact, this whole test suite is full of
them...). In particular, shouldn't the first line there not be different
from just the test on b?

IIRC, I think the runtime pads, or used to pad, strings with a zero byte
for easy compatibility with C strings and CGO interop. The runtime
conversion to []byte seems to preserve, or used to preserve that trailing
zero byte. The test checks that DecodeRune is not tripped by the zero byte
trailer, ditto DecodeRuneInString.
-- 

-j

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


Re: [go-nuts] need library suggestions on writing a record program

2016-11-28 Thread Justin Israel
Does a replacement have to be a terminal app or is that just to match the
legacy look and feel? I haven't written apps in a terminal UI before, but I
have spent many years writing Qt applications, so I would probably reach
for Qt via https://github.com/therecipe/qt

If you haven't written any Go yet, it will be two challenges at once, since
you also have to wrap your head around an event loop and connecting signals
and slots together (function callbacks). I would assume terminal UI libs
will work the same way.

Justin

On Tue, Nov 29, 2016, 5:12 AM  wrote:

> i'd like to rewrite an old dos medical patient record program in go for a
> friend. its not a complex program by any means
>
> i'd probably use go-sqlite3 for storage but its the terminal part where
> I'm confused. should i use gocui or termbox directly?
>
> the program will only have menus to be controlled using arrow-keys,
> hotkeys, fields for keying in data
>
> if there are any other libs i should know of that may be useful in this
> task please share.
>
> keep in mind, i have no knowledge of go.. but this should be the first
> first proper programming language i'd learn. (im currently reasonable in
> bash scripting)
>
>
> --
> 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] Can anyone explain this section of the unicode/utf8 test suite?

2016-11-28 Thread Pietro Gagliardi
Not sure if this belongs here or golang-dev, but...

I'm copying the unicode/utf8 and unicode/utf16 tests for my own C library that 
also deals with UTF-8 and UTF-16 (because why not), and there's one thing I'm 
confused about in the former:

https://github.com/golang/go/blob/d2951740303587fc0c5d14cb5461e39b099e6695/src/unicode/utf8/utf8_test.go#L143-L152
// there's an extra byte that bytes left behind - make sure trailing byte works
r, size = DecodeRune(b[0:cap(b)])
if r != m.r || size != len(b) {
t.Errorf("DecodeRune(%q) = %#04x, %d want %#04x, %d", b, r, size, m.r, 
len(b))
}
s = m.str + "\x00"
r, size = DecodeRuneInString(s)
if r != m.r || size != len(b) {
t.Errorf("DecodeRuneInString(%q) = %#04x, %d want %#04x, %d", s, r, size, 
m.r, len(b))
}

What is this supposed to be doing? I tried going through the git history to 
find any context and the only thing I can figure is that there are lots of 
leftovers from super early Go (in fact, this whole test suite is full of 
them...). In particular, shouldn't the first line there not be different from 
just the test on b?

Or is there something more subtle?

Thanks.

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


Re: [go-nuts] Heap fragmentation due to protobuffs serialization/de-serialization

2016-11-28 Thread Ian Lance Taylor
On Mon, Nov 28, 2016 at 8:00 AM, Devanand Reddy
 wrote:
>
> We are using protocol buffers extensively in our application. We have a
> suspect that over the time, due to excessive  marshaling/un-marshaling these
> two operations are causing heap fragmentation. One factor I am looking at,
> to come to this conclusion is HeapIdle. In my tests, though HeapInUse is
> coming back to my expectation, HeapIdle is staying there forever. On another
> note, our protobuff operations consume any where between 700-900mb, given
> the size of the data we are trying to serialize.
> I am attaching a few graphs here.
>
> Please advise whether this is a sign for concern.

Heap fragmentation is not normally a concern with the current Go
runtime.  The heap is implemented to that large pages are divided up
into blocks that are all the same size.  This means that the usual
definition of fragmentation--a small block prevents coalescing of
large blocks--can not occur.

Your graphs seem to show your memory use is in a steady state, which
is a good thing.  When there are operations that temporarily use a lot
of memory, it's normal for HeapIdle to be high--the memory is there
ready and waiting for temporary memory use spikes.

Ian

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


Re: [go-nuts] Problem with code!

2016-11-28 Thread Seth Bunce
You may be missing a "continue" in your "if cont == 0" block.

Seth

On Nov 28, 2016 7:33 AM, "Sergio Hunter"  wrote:

> Hi everybody. I need help. When outputting data to a csv file, the dates
> is duplicated, but should merge and be counted. How to write correctly?
> Thanks.
>
>
>
> package main
>
> import (
>"database/sql"
>"log"
>_"github.com/go-sql-driver/mysql"
>"compress/zlib"
>"bytes"
>"encoding/json"
>"io/ioutil"
>"sort"
>"encoding/csv"
>"os"
>"strconv"
>"fmt"
> )
>
> var (
>data []byte
>dates []string
> )
>
> type UserStatsData struct {
>Dates map[string]Info `json:"d"`
> }
>
> type Info struct {
>D string `json:"-"`
>G int `json:"g"`
>R json.Number `json:"r"`
> }
>
> func main()
>
>db, err := sql.Open("mysql", 
> "name:password@tcp(127.0.0.1:port)/database")
>if err != nil {
>   panic(err.Error())
>}
>defer db.Close()
>
>rows, err := db.Query(`SELECT data FROM user_stats ORDER BY created_at 
> LIMIT 5`)
>if err != nil {
>   log.Fatal(err)
>}
>defer rows.Close()
>
>file, err := os.Create("result.csv")
>if err != nil {
>   fmt.Println(err)
>}
>defer file.Close()
>
>cont := 0
>writer := csv.NewWriter(file)
>userStatsData := UserStatsData{}
>for rows.Next() {
>   err := rows.Scan()
>   if err != nil {
>  log.Fatal(err)
>   }
>
>   if err := json.Unmarshal(data, ); err != nil {
>  r, err := zlib.NewReader(bytes.NewReader(data))
>  if err != nil {
> log.Panicf("\nCannot read archive %v", err)
>  }
>  r.Close()
>  data, _ = ioutil.ReadAll(r)
>   }
>   //fmt.Printf("%s\n", data)
>   if err := json.Unmarshal(data, ); err != nil{
>  panic(err)
>   }
>
>   for userStats := range userStatsData.Dates {
>  dates = append(dates, userStats)
>   }
>   sort.Strings(dates)
>
>   var info []Info
>   for _, date := range dates {
>  k := userStatsData.Dates[date]
>  k.D = date
>  info = append(info, k)
>   }
>
>   for _, i := range info {
>  if cont == 0 {
> var record []string
> record = append(record, "Date")
> record = append(record, "Gold")
> record = append(record, "Revenue")
> writer.Write(record)
> cont++
>
>  }
>  var record []string
>  record = append(record, i.D)
>  record = append(record, strconv.Itoa(i.G))
>  record = append(record, i.R.String())
>  writer.Write(record)
>  cont++
>
>   }
>
>   writer.Flush()
>   err = writer.Error()
>   if err != nil {
>  panic(err)
>   }
>
>}
>
> }
>
>
>
> --
> 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: net/http and errors.

2016-11-28 Thread mb . dhananjay
I'm downloading a large number of urls and the result is expected to have 
failure reasons, DNS lookup failed being one.

calling lookup manually would solve my issue, I suppose. Just wanted to 
make sure that I'm not missing any obvious solutions.

1. lookup DNS and if it succeeds, 
2. try http.Get - which calles Lookup again (also maybe DNS server went 
down now - improbable but not impossible?)


On Monday, November 28, 2016 at 1:05:25 PM UTC+1, Dave Cheney wrote:
>
> What specifically do you want to handle about DNS errors ?
>
> If you have a set of possible dns names and you don't know if some of them 
> are valid, you could use net.LookupHost to check which ones are valid 
> before calling http.Get.
>
> On Monday, 28 November 2016 22:44:37 UTC+11, mb.dha...@gmail.com wrote:
>>
>> But AFIU, err.Temporary() could be true for other kind of errors that 
>> might happen, isn't that a problem if I only want to handle DNS errors?
>>
>>
>> On Friday, November 25, 2016 at 6:35:59 PM UTC+1, Victor Vrantchan wrote:
>>>
>>> In Go, you can check if a type satisfies a particular behavior by 
>>> declaring an interface, and then checking if the type satisfies that 
>>> interface. 
>>> In your case, you can check if the error is `Temporrary()` or not. 
>>>
>>> See this snippet as an example: https://I don't 
>>> thinplay.golang.org/p/Ffyg61iDpB 
>>>
>>> I recommend 
>>> https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully
>>>  
>>> and.or the GopherCon talk https://www.youtube.com/watch?v=lsBF58Q-DnY 
>>> by Dave Cheney for a more in-depth presentation of this idea. 
>>>
>>> On Friday, November 25, 2016 at 12:00:06 PM UTC-5, mb.dha...@gmail.com 
>>> wrote:

 This is a question about the net/http API, Googling was not very 
 helpful.

 _, err := http.Get("https://random_non_existing_domain.com;)


 Following code will obviously fail, but how can I check if it failed 
 because of DNS error not because a billion other things that might have 
 gone wrong?

 I tried this, (mostly as a shot in the dark)

 if e, ok := err.(net.Error); ok {
 fmt.Println("dial error", e.Temporary())
 }
 if e, ok := err.(*net.AddrError); ok {
 fmt.Println("addr rror", e.Temporary())
 }
 if e, ok := err.(*net.DNSError); ok {
 fmt.Println(e)

 and it seems to print 

dial error false

 Is there any easy way to do what I'm trying to achieve?

 -
 dbalan
 @notmycommit




-- 
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] Problem with code!

2016-11-28 Thread Shawn Milochik
Just a Go map -- like you're already using elsewhere in the code. It's the
same as a hash in Perl or a dict in Python -- you can't have duplicate keys.

So if you create a map that has the date as the key and anything as the
value (an empty struct is idiomatic, but you can also use a boolean), then
you will end up with a unique list of dates as map keys.

Example:

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

-- 
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] Problem with code!

2016-11-28 Thread Sergio Hunter
I can't understand about "map", Could you explain me please?

понедельник, 28 ноября 2016 г., 18:35:54 UTC+2 пользователь Shawn Milochik 
написал:
>
> The dates are just being appended without being checked for duplication:
>
> for userStats := range userStatsData.Dates {
> dates = append(dates, userStats)
> }
>
> You could use a map for this. 
>
> Also, check your errors: data, _ = ioutil.ReadAll(r)
>
> If the first "if" block for the unmarshal works, then userStatsData is 
> populated, but it's not used.
>
>
>

-- 
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] Problem with code!

2016-11-28 Thread Shawn Milochik
 The dates are just being appended without being checked for duplication:

for userStats := range userStatsData.Dates {
dates = append(dates, userStats)
}

You could use a map for this.

Also, check your errors: data, _ = ioutil.ReadAll(r)

If the first "if" block for the unmarshal works, then userStatsData is
populated, but it's not used.

-- 
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: Bloom filter

2016-11-28 Thread Ian Davis
On Sat, Jan 25, 2014, at 07:17 AM, greg.z...@gmail.com wrote:

> Hello, I seem to be unable to Unmarshal a bitset over size 32..



What have you tried and what errors did you encounter?



If you share some code then your question will be easier to answer.


-- 
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] need library suggestions on writing a record program

2016-11-28 Thread biatche
i'd like to rewrite an old dos medical patient record program in go for a 
friend. its not a complex program by any means

i'd probably use go-sqlite3 for storage but its the terminal part where I'm 
confused. should i use gocui or termbox directly?

the program will only have menus to be controlled using arrow-keys, 
hotkeys, fields for keying in data

if there are any other libs i should know of that may be useful in this 
task please share.

keep in mind, i have no knowledge of go.. but this should be the first 
first proper programming language i'd learn. (im currently reasonable in 
bash scripting)


-- 
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: Bloom filter

2016-11-28 Thread xrfang
Hi Will,

Could you please explain the memory characteristics of your implementation? 
i.e. given boom.New(m, k), how much memory will the filter consume? Is the 
memory consumption related to number of items in the filter? If 
appropriate, function such as 

func EstimateParameterByMemory(mem int) (m, k int)
func (f *BloomFilter) MemoryConsumption() int

will be very useful in my case.

Thank you very much!

xrfang

在 2011年5月21日星期六 UTC+8下午10:24:05,Will Fitzgerald写道:
>
> I've written an implementation of Bloom filters, using the BitSet package. 
> You can find it at
>
> https://github.com/willf/bloom
>
> As usual, comments welcome. 
>
> Will
>

-- 
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] Deleting the /r/golang subreddit

2016-11-28 Thread Craig
I took the same interpretation ("rankist", not sexist). Still an ad hominem.
On Mon, Nov 28, 2016 at 9:32 AM Andy Balholm  wrote:

> I took the usage of “men” in that comment to be gender-neutral. I read it
> as “Are you rankist?", not as “Are you sexist or rankist?”
>
> (I don’t know if rankist is a word, but I mean someone who discriminates
> on the basis of rank.)
>
> Andy
>
> On Nov 27, 2016, at 6:43 PM, vac...@gmail.com wrote:
>
>
> I would just like to point out what a genuinely vile response this is.
> Your vague and menacing implication is that Florian is somehow a sexist
> because he disagrees with you is beneath you, Dave, and you should
> apologise.
>
>
> On Friday, November 25, 2016 at 6:26:40 PM UTC+13, Dave Cheney wrote:
>
> On Fri, Nov 25, 2016 at 4:24 PM, Florian Weimer 
> wrote:
> > * Brad Fitzpatrick:
> >
> >> In light of the CEO of Reddit admitting to editing user comments (see
> >> dozen news stories today), I propose we delete the /r/golang subreddit.
> >>
> >> That is so beyond unethical and immature,
> >
> > Was it immature because they didn't make any money out of it, at least
> > not directly?  Modifying user-generated content without informed
> > consent is standard business practice.  You must be aware of that.
> > (Many people who read this will see totally misleading ads next to
> > this post, for instance, and I obviously never agreed to that.)
> >
> > It was a bad prank for sure.  But it was just a prank.
>
> Do you normalise the behaviour of all men, or only those at the C level?
>
> >
> > --
> > 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/XoOhzUClDPs/unsubscribe.
> > To unsubscribe from this group and all its topics, 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.
>
> --
> 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/XoOhzUClDPs/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] Problem with code!

2016-11-28 Thread Sergio Hunter
Hi everybody. I need help. When outputting data to a csv file, the dates is 
duplicated, but should merge and be counted. How to write correctly? Thanks.



package main

import (
   "database/sql"
   "log"
   _"github.com/go-sql-driver/mysql"
   "compress/zlib"
   "bytes"
   "encoding/json"
   "io/ioutil"
   "sort"
   "encoding/csv"
   "os"
   "strconv"
   "fmt"
)

var (
   data []byte
   dates []string
)

type UserStatsData struct {
   Dates map[string]Info `json:"d"`
}

type Info struct {
   D string `json:"-"`
   G int `json:"g"`
   R json.Number `json:"r"`
}

func main() 

   db, err := sql.Open("mysql", 
"name:password@tcp(127.0.0.1:port)/database")
   if err != nil {
  panic(err.Error())
   }
   defer db.Close()

   rows, err := db.Query(`SELECT data FROM user_stats ORDER BY created_at 
LIMIT 5`)
   if err != nil {
  log.Fatal(err)
   }
   defer rows.Close()

   file, err := os.Create("result.csv")
   if err != nil {
  fmt.Println(err)
   }
   defer file.Close()

   cont := 0
   writer := csv.NewWriter(file)
   userStatsData := UserStatsData{}
   for rows.Next() {
  err := rows.Scan()
  if err != nil {
 log.Fatal(err)
  }

  if err := json.Unmarshal(data, ); err != nil {
 r, err := zlib.NewReader(bytes.NewReader(data))
 if err != nil {
log.Panicf("\nCannot read archive %v", err)
 }
 r.Close()
 data, _ = ioutil.ReadAll(r)
  }
  //fmt.Printf("%s\n", data)
  if err := json.Unmarshal(data, ); err != nil{
 panic(err)
  }

  for userStats := range userStatsData.Dates {
 dates = append(dates, userStats)
  }
  sort.Strings(dates)

  var info []Info
  for _, date := range dates {
 k := userStatsData.Dates[date]
 k.D = date
 info = append(info, k)
  }

  for _, i := range info {
 if cont == 0 {
var record []string
record = append(record, "Date")
record = append(record, "Gold")
record = append(record, "Revenue")
writer.Write(record)
cont++

 }
 var record []string
 record = append(record, i.D)
 record = append(record, strconv.Itoa(i.G))
 record = append(record, i.R.String())
 writer.Write(record)
 cont++

  }

  writer.Flush()
  err = writer.Error()
  if err != nil {
 panic(err)
  }

   }

}



-- 
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] Deleting the /r/golang subreddit

2016-11-28 Thread Andy Balholm
I took the usage of “men” in that comment to be gender-neutral. I read it as 
“Are you rankist?", not as “Are you sexist or rankist?”

(I don’t know if rankist is a word, but I mean someone who discriminates on the 
basis of rank.)

Andy

> On Nov 27, 2016, at 6:43 PM, vac...@gmail.com wrote:
> 
> 
> I would just like to point out what a genuinely vile response this is. Your 
> vague and menacing implication is that Florian is somehow a sexist because he 
> disagrees with you is beneath you, Dave, and you should apologise. 
> 
> 
> On Friday, November 25, 2016 at 6:26:40 PM UTC+13, Dave Cheney wrote:
> On Fri, Nov 25, 2016 at 4:24 PM, Florian Weimer  > wrote: 
> > * Brad Fitzpatrick: 
> > 
> >> In light of the CEO of Reddit admitting to editing user comments (see 
> >> dozen news stories today), I propose we delete the /r/golang subreddit. 
> >> 
> >> That is so beyond unethical and immature, 
> > 
> > Was it immature because they didn't make any money out of it, at least 
> > not directly?  Modifying user-generated content without informed 
> > consent is standard business practice.  You must be aware of that. 
> > (Many people who read this will see totally misleading ads next to 
> > this post, for instance, and I obviously never agreed to that.) 
> > 
> > It was a bad prank for sure.  But it was just a prank. 
> 
> Do you normalise the behaviour of all men, or only those at the C level? 
> 
> > 
> > -- 
> > 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/XoOhzUClDPs/unsubscribe 
> > . 
> > To unsubscribe from this group and all its topics, 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 
> .

-- 
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: Deleting the /r/golang subreddit

2016-11-28 Thread Art Mellor
I think some readers are missing the OP's attempt to invoke the wise words 
of Obi Wan Kenobi:
https://www.youtube.com/watch?v=0znNiN0lYAQ

On Thursday, November 24, 2016 at 8:57:22 PM UTC-6, Nathaniel Nutter wrote:
>
> Are all 25,171 subscribers scum and villainy?  As a someone that reads 
> /r/golang I've somehow managed not to come to the same conclusion.
>
> On Thursday, November 24, 2016 at 5:56:47 PM UTC-6, Brian Ketelsen wrote:
>>
>> Kill it.
>> It's a wretched hive of scum and villainy.  The Go subreddit was the only 
>> thing similar to human and it is downright painful most of the time.
>>
>> On 11/24/2016 6:54:25 PM, Brad Fitzpatrick  wrote:
>> [+bketelson, dgryski]
>>
>>
>> On Thu, Nov 24, 2016 at 3:53 PM, Brad Fitzpatrick  
>> wrote:
>>
>>> In light of the CEO of Reddit admitting to editing user comments (see 
>>> dozen news stories today), I propose we delete the /r/golang subreddit.
>>>
>>> That is so beyond unethical and immature, I no longer want anything to 
>>> do with that site. I will be deleting my account on Reddit after backing up 
>>> my content, and I will no longer be a moderator of /r/golang.
>>>
>>> If other moderators of /r/golang feel strongly that it should remain, I 
>>> suppose you're welcome to keep it going.
>>>
>>> But if the other moderators want to abandon it and focus our 
>>> conversation elsewhere (or build a replacement), I'm happy to just delete 
>>> /r/golang.
>>>
>>> Opinions?
>>>
>>>
>>

-- 
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-11-28 Thread adonovan via golang-nuts
On Monday, 28 November 2016 09:04:55 UTC-5, atd...@gmail.com wrote:
>
>
> I  concur.
>
> On Monday, November 28, 2016 at 4:35:13 AM UTC+1, Michael Jones wrote:
>>
>> Details of this would make a great Go Blog post…
>>
>  

There is certainly a dearth of documentation on how to make the key design 
decisions when building tools to analyze Go source, but the topic seems 
rather esoteric for the Go Blog.

-- 
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-11-28 Thread atd...@gmail.com

I  concur.

On Monday, November 28, 2016 at 4:35:13 AM UTC+1, Michael Jones wrote:
>
> Details of this would make a great Go Blog post…
>
>  
>
> *From: *adonovan via golang-nuts 
> *Reply-To: *
> *Date: *Sunday, November 27, 2016 at 6:07 PM
> *To: *golang-nuts 
> *Cc: *
> *Subject: *Re: [go-nuts] CFG for a Go program
>
>  
>
> If you're building tools for source code analysis, you may find the 
> golang.org/x/go/ssa representation easier to work with than the internals 
> of the compiler.  Build and run this command to see an example:
>
>  
>
>   $ go get golang.org/x/tools/cmd/ssadump
>
>   $ ssadump -build=F fmt
>
>  
>
> Alternatively, the cmd/vet tool in the standard library has an internal 
> subpackage that constructs the control-flow graph of a function.  In this 
> representation, each block contains a sequence of Go statements and 
> expressions, not low-level SSA instructions.
>
>  
>
> Which of these forms of control-flow graph is most appropriate depends on 
> the (unmentioned) problem you're trying to solve.
>
> -- 
> 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: Extracting link to earlier panic

2016-11-28 Thread Matt Joiner
^

On Friday, 25 November 2016 14:02:29 UTC+11, Matt Joiner wrote:
>
> I can't see anyway to extract earlier panics per runtime's _panic.link. 
> This makes it difficult to print stack traces in the way that the default 
> handler does if a panic is not recovered.
>
> I want to recover a panic, print its stack trace, and all earlier panic 
> values in the way shown here:
>
> panic: zip: not a valid zip file [recovered]
>
> panic: some context [recovered]
>
> panic: more context
>
>
> goroutine 1 [running]:
>
> 
>

-- 
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: Hide struct fields from frontend code (JSON REST API)

2016-11-28 Thread Mirco Zeiss
Sorry, but it won't work. I'm using the same marshal method when 
communicating with my DB as when communicating to my frontend. How can I 
tell it to sometimes leave out the private fields and sometimes not?

On Monday, November 28, 2016 at 6:43:26 AM UTC+1, Mirco Zeiss wrote:
>
> That might work. Thank you! Will try and report back.
>

-- 
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: net/http and errors.

2016-11-28 Thread Dave Cheney
What specifically do you want to handle about DNS errors ?

If you have a set of possible dns names and you don't know if some of them 
are valid, you could use net.LookupHost to check which ones are valid 
before calling http.Get.

On Monday, 28 November 2016 22:44:37 UTC+11, mb.dha...@gmail.com wrote:
>
> But AFIU, err.Temporary() could be true for other kind of errors that 
> might happen, isn't that a problem if I only want to handle DNS errors?
>
>
> On Friday, November 25, 2016 at 6:35:59 PM UTC+1, Victor Vrantchan wrote:
>>
>> In Go, you can check if a type satisfies a particular behavior by 
>> declaring an interface, and then checking if the type satisfies that 
>> interface. 
>> In your case, you can check if the error is `Temporrary()` or not. 
>>
>> See this snippet as an example: https://I don't 
>> thinplay.golang.org/p/Ffyg61iDpB 
>>
>> I recommend 
>> https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully
>>  
>> and.or the GopherCon talk https://www.youtube.com/watch?v=lsBF58Q-DnY by 
>> Dave Cheney for a more in-depth presentation of this idea. 
>>
>> On Friday, November 25, 2016 at 12:00:06 PM UTC-5, mb.dha...@gmail.com 
>> wrote:
>>>
>>> This is a question about the net/http API, Googling was not very helpful.
>>>
>>> _, err := http.Get("https://random_non_existing_domain.com;)
>>>
>>>
>>> Following code will obviously fail, but how can I check if it failed 
>>> because of DNS error not because a billion other things that might have 
>>> gone wrong?
>>>
>>> I tried this, (mostly as a shot in the dark)
>>>
>>> if e, ok := err.(net.Error); ok {
>>> fmt.Println("dial error", e.Temporary())
>>> }
>>> if e, ok := err.(*net.AddrError); ok {
>>> fmt.Println("addr rror", e.Temporary())
>>> }
>>> if e, ok := err.(*net.DNSError); ok {
>>> fmt.Println(e)
>>>
>>> and it seems to print 
>>>
>>>dial error false
>>>
>>> Is there any easy way to do what I'm trying to achieve?
>>>
>>> -
>>> dbalan
>>> @notmycommit
>>>
>>>
>>>

-- 
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 I do bulk insert with "INSERT INTO xxx(..) VALUE(?,?,?),(?,?,?),(?,?,?) ON DUPLICATE KEY UPDATE xxx=?,xxx=?;"

2016-11-28 Thread mworks092
Ok, I got the answer.
First I prepared the VALUES(?,?) by putting the (?,?,?) together. Second, 
using vals of type []interface{} I can append every member of the 
DataAccessObject to vals like: vals = append(vals, np.Port). Finally all 
things have been done with normal stmt, err := db.Prepare(), and _, err := 
stmt.Exec(vals...)



在 2016年11月28日星期一 UTC+8下午5:33:22,mwor...@gmail.com写道:
>
> Hi everyone!
>
> I met a problem in my project where I want to do INSERT ON DUPLICATE 
> KEY UPDATE with around 3,000 records once. It seems like golang didn't 
> support bulk insert . I was confused if it will lead MySQL inject risk if I 
> just do put the sql pieces together, it will looks like: 
> stmt, err := db.Prepare("INSERT INTO users(id, name) 
> VALUES(?,?),...,(?,?)ON DUPLICATE KEY UPDATE id=?, name=?")
>
> _, err = stmt.Query(/*how to write here ?*/)
>
> thanks for your attentions.
>
>

-- 
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: net/http and errors.

2016-11-28 Thread mb . dhananjay
But AFIU, err.Temporary() could be true for other kind of errors that might 
happen, isn't that a problem if I only want to handle DNS errors?


On Friday, November 25, 2016 at 6:35:59 PM UTC+1, Victor Vrantchan wrote:
>
> In Go, you can check if a type satisfies a particular behavior by 
> declaring an interface, and then checking if the type satisfies that 
> interface. 
> In your case, you can check if the error is `Temporrary()` or not. 
>
> See this snippet as an example: https://I don't 
> thinplay.golang.org/p/Ffyg61iDpB 
>
> I recommend 
> https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully
>  
> and.or the GopherCon talk https://www.youtube.com/watch?v=lsBF58Q-DnY by 
> Dave Cheney for a more in-depth presentation of this idea. 
>
> On Friday, November 25, 2016 at 12:00:06 PM UTC-5, mb.dha...@gmail.com 
> wrote:
>>
>> This is a question about the net/http API, Googling was not very helpful.
>>
>> _, err := http.Get("https://random_non_existing_domain.com;)
>>
>>
>> Following code will obviously fail, but how can I check if it failed 
>> because of DNS error not because a billion other things that might have 
>> gone wrong?
>>
>> I tried this, (mostly as a shot in the dark)
>>
>> if e, ok := err.(net.Error); ok {
>> fmt.Println("dial error", e.Temporary())
>> }
>> if e, ok := err.(*net.AddrError); ok {
>> fmt.Println("addr rror", e.Temporary())
>> }
>> if e, ok := err.(*net.DNSError); ok {
>> fmt.Println(e)
>>
>> and it seems to print 
>>
>>dial error false
>>
>> Is there any easy way to do what I'm trying to achieve?
>>
>> -
>> dbalan
>> @notmycommit
>>
>>
>>

-- 
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] Type statement in blocks vs global

2016-11-28 Thread Jan Mercl
On Mon, Nov 28, 2016 at 12:21 PM  wrote:

> Since a type can only be declared once in a scope, the order in which
they are declared shouldn't matter ?

It matters depending on which scope it is. From
https://golang.org/ref/spec#Declarations_and_scope


...
2. The scope of an identifier denoting a constant, type, variable,
or function (but not method) declared at top level (outside any function)
is the package block.
...
5. The scope of a type identifier declared inside a function begins
at the identifier in the TypeSpec and ends at the end of the innermost
containing block.


IOW, one cannot have forward local type references inside a function.
-- 

-j

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


Re: [go-nuts] Type statement in blocks vs global

2016-11-28 Thread paraiso . marc
I'm not sure what you mean. 

types that reference each others in a type declaration are allowed when 
declared globally , but not in a block ( ? ) 

i.e. :

declaring Foo and Bar outside main would work , declaring them inside main 
doesn't . I wanted to declare them inside an example function in order for 
them to show up in the docs since the latter only prints the body of 
example functions (func ExampleFoo ...) . So I was asking why it worked 
that way. Since a type can only be declared once in a scope, the order in 
which they are declared shouldn't matter ? so they could reference each 
others like in my code snippet. thanks. 

Le lundi 28 novembre 2016 11:54:39 UTC+1, Jan Mercl a écrit :
>
> On Mon, Nov 28, 2016 at 11:46 AM  
> wrote:
>
> > Is there an alternative aside from declaring types globally ? 
>
> Unfortunately, the problem to solve is not defined, only the solution 
> tried and failed is, so I don't know if this can help: 
> https://play.golang.org/p/9btAagXDpM
>
> -- 
>
> -j
>

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


Re: [go-nuts] Type statement in blocks vs global

2016-11-28 Thread Jan Mercl
On Mon, Nov 28, 2016 at 11:46 AM  wrote:

> Is there an alternative aside from declaring types globally ?

Unfortunately, the problem to solve is not defined, only the solution tried
and failed is, so I don't know if this can help:
https://play.golang.org/p/9btAagXDpM

-- 

-j

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


[go-nuts] How could I do bulk insert with "INSERT INTO xxx(..) VALUE(?,?,?),(?,?,?),(?,?,?) ON DUPLICATE KEY UPDATE xxx=?,xxx=?;"

2016-11-28 Thread mworks092
Hi everyone!

I met a problem in my project where I want to do INSERT ON DUPLICATE 
KEY UPDATE with around 3,000 records once. It seems like golang didn't 
support bulk insert . I was confused if it will lead MySQL inject risk if I 
just do put the sql pieces together, it will looks like: 
stmt, err := db.Prepare("INSERT INTO users(id, name) 
VALUES(?,?),...,(?,?)ON DUPLICATE KEY UPDATE id=?, name=?")

_, err = stmt.Query(/*how to write here ?*/)

thanks for your attentions.

-- 
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] Checking whether html/css toggle switch has been set to on/off position in go

2016-11-28 Thread Konstantin Khomoutov
On Mon, 28 Nov 2016 11:50:26 +0300
Konstantin Khomoutov  wrote:

[...]
> > I do have my go handler configured, as well as my ws function in
> > javascript configured to be triggered on the click of a button.
> > Forgot to mention this. right now on the click of a button I can
> > execute a terminal command in go, and output the results in realtime
> > on my webpage. But what I want to do is configure a toggle switch on
> > my webpage so that if the switch is in an on position, then when I
> > click the button, I can execute a terminal command in my go code,
> > and if the switch is off, after I click the button my go code will
> > execute a different terminal command. Here is the toggle switch I
> > have implemented: http://www.bootstraptoggle.com/
> > 
> > But now I'm stuck on how to read whether this switch is in its
> > off/on position in my go code. Any suggestions would help.
> 
> In general, you can't do this (well, almost [*]).

Forgot to address this point.

Well, with modern browsers and websockets it should be possible to use
the so-called "server sent events" which allows the server to actively
solitict an action from the client.

But the fact this feature exists does not means it should be used in
your case.  Your case, in my opinion, is much simpler and I suggest you
to not overengeneer your solution.

[...]

-- 
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] Checking whether html/css toggle switch has been set to on/off position in go

2016-11-28 Thread Konstantin Khomoutov
On Mon, 28 Nov 2016 03:37:32 -0500
Chris S  wrote:

> Thanks for the response Konstantin,
> 
> I do have my go handler configured, as well as my ws function in
> javascript configured to be triggered on the click of a button.
> Forgot to mention this. right now on the click of a button I can
> execute a terminal command in go, and output the results in realtime
> on my webpage. But what I want to do is configure a toggle switch on
> my webpage so that if the switch is in an on position, then when I
> click the button, I can execute a terminal command in my go code, and
> if the switch is off, after I click the button my go code will
> execute a different terminal command. Here is the toggle switch I
> have implemented: http://www.bootstraptoggle.com/
> 
> But now I'm stuck on how to read whether this switch is in its off/on
> position in my go code. Any suggestions would help.

In general, you can't do this (well, almost [*]).

But you shouldn't -- just reverse the problem: when the user activates
the button to execute the command they have input, read the state of
that toggle and send it along with the command to the server.

The server will then parse out that piece of information from the
webpage's request and switch its course of action accordingly.

In other words, that's no magic -- just try thinking constructively:

1. When the user activates a button on your web page, the server has to
   interpret this event *depending* on the state of a toggle control.

2. OK, this means you have to tell the server what's the state of that
   toggle control along with the "user activated that button" event.

-- 
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] Checking whether html/css toggle switch has been set to on/off position in go

2016-11-28 Thread Konstantin Khomoutov
On Sun, 27 Nov 2016 22:33:33 -0800 (PST)
Chris S  wrote:

[...]
> I currently have my html file set up with a button and this toggle
> switch. I also configured my webserver in go to be listening on
> localhost:8080. And I have a websocket handler configured, so that I
> can easily pass data through to my webpage on the click of the button.
> 
> What I want to do create a toggle switch on my webpage that the user
> can switch on and off, and then have them click a button. After that
> button is clicked I want to analyse the users selection using an if
> condition in my golang code based on whether this toggle switch is
> on/off, but I cannot figure out how to access this value in go. Any
> suggestions would be helpful. Also, it'd be ideal to have a toggle
> switch implemented, but if anyone has any simpler ideas for this use
> case then I'd be open to them.

You're (probably) supposed to use some JavaScript on your page so that
when the user activates your toggle, you perform a request through that
web socket.  A handler installed to listen on that websocket in your Go
server should parse the request sent from the browser and act
accordingly.

The best course of action is to break this task into subtasks and have
them solved one-by-one:

* Make sure activating your toggle calls whatever JS code you intend.

  For this, use plain console.log("whatever") and see whether it works
  in your browser's developer window.  Note that contemporary browsers
  even allow you to execute your JS handlers step-by-step and set
  breakpoints.

* Make sure your JS handler performs the request through the web socket.

  Again, this can be checked in the browser's developer window.
  It allows you to inspect the request's properties.

* Make sure your Go handler works.

  Match that what you install on the Go side with what you've inspected
  using the browser's developer tools.

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