Re: [go-nuts] golang maps; using slice as a key

2018-05-23 Thread Karan Chaudhary
The slice which is created to be appended to b, points to &i, which (i) gets updated in next (last) loop iteration. Hence in last iteration, first element in `b` will start pointing to the new array [4,5,6]. This could have been mitigated had `i` been allocated to new location on every it

[go-nuts] Re: add Printfln to log and fmt

2018-05-23 Thread Karan Chaudhary
I don't know if its a good idea to have this in stdlib, but you can definitely write your own to solve the problem :) package main import ( "fmt" ) func Printfln(format string, a ...interface{}) { fmt.Printf(format + "\n", a...) } func main() { Printfln("%s is awesome!", "Go") fmt.Println("yu

Re: [go-nuts] golang maps; using slice as a key

2018-05-23 Thread Karan Chaudhary
And a little better way to create `numMem` https://play.golang.org/p/fAWgSpi2CKR On Wednesday, 23 May 2018 12:55:49 UTC+5:30, Karan Chaudhary wrote: > > One other simpler (and not so elegant) solution is to use separate set for > each element. > > https://play.golang.o

Re: [go-nuts] golang maps; using slice as a key

2018-05-23 Thread Karan Chaudhary
One other simpler (and not so elegant) solution is to use separate set for each element. https://play.golang.org/p/9ZSRfAyOX4- @Bakul's solution sounds good but haven't tried to understand it clearly. On Wednesday, 23 May 2018 11:46:15 UTC+5:30, Sankar wrote: > > Use an array instead of a sl

[go-nuts] Re: Processing test json data

2018-05-22 Thread Karan Chaudhary
Will this help? https://github.com/aaronbriel/jsonjunit I haven't tried it but piping the json output to jsonjunit can help. On Saturday, 19 May 2018 19:55:24 UTC+5:30, Vedu Joshi wrote: > > I see that in go1.10, we can have json formatted "go test" output (by > using -json flag) > I googled aro

[go-nuts] Re: [ANN] A golang source code query language

2018-03-24 Thread Karan Chaudhary
Interesting idea, Forud. So I was reading net/http package, it has ResponseWriter which is an interface as opposed to http.Request (which is a concrete type). Then I wanted to know what all types implement http.REsponseWriter, which reminded of your post here. Is it possible to know this usi

[go-nuts] Re: Enormously large core filed is generated for simple Go program.

2018-03-20 Thread Karan Chaudhary
Kindly discard this. I was looking at a different file. -- 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 option

[go-nuts] Enormously large core filed is generated for simple Go program.

2018-03-20 Thread Karan Chaudhary
Hi, For a simple program: package main import ( "fmt" "os" "time" ) func main() { fmt.Println("hello!", os.Getpid()) time.Sleep(10 * time.Second) } I generate the core file using "gcore ". Size of the core file is 1.1G. Is that normal? Isn't it eno

[go-nuts] Re: profiling webserver with pprof and router middleware

2017-12-04 Thread Karan Chaudhary
p allocations generated by incoming >> requests, so I can optimize my handler functions >> >> I will write a more basic webserver example to see if I can produce the >> result I am expecting >> >> Am Donnerstag, 30. November 2017 14:39:56 UTC+1 schrieb Karan Chaudhary

[go-nuts] Re: net/http Server Shutdown does not free up the port upon return

2017-11-30 Thread Karan Chaudhary
I think, this is what is happening. I don't think this is a bug. When server shuts down, it asks the kernel to release the resources it was holding. One of the resources is port. Though the program closed the port (by the shutdown()), but kernel still keeps it in TIME_WAIT state. Now if w

[go-nuts] Re: How to check if db connection active after database server restarts ?

2017-11-30 Thread Karan Chaudhary
If at any point it is to be checked that connection is active or not, `Ping` can be used as stated by Shawn. And any operation on dirty conn should fail, as the session is corrupt. Though, it seems, auto-reconnection is already done by database/sql. https://github.com/golang/go/issues/5718 O

[go-nuts] Re: profiling webserver with pprof and router middleware

2017-11-30 Thread Karan Chaudhary
Attaching png: <https://lh3.googleusercontent.com/-3pu5f0Zvebw/WiAKKFjnVnI/KG4/hnPspzQzf7ASbvqtTU64rEMPSsZ3G1bzgCLcBGAs/s1600/profile003.png> On Thursday, 30 November 2017 19:09:04 UTC+5:30, Karan Chaudhary wrote: > > Are you just trying to see how heap allocation can b

[go-nuts] Re: profiling webserver with pprof and router middleware

2017-11-30 Thread Karan Chaudhary
. November 2017 13:37:43 UTC+1 schrieb basti skalendudler: >> >> The go tool pprof command is interactive, so I thought it is enough type >> 'png' to get the image after the benchmark is run >> >> I tested to start go tool pprof now as well during and

[go-nuts] Re: profiling webserver with pprof and router middleware

2017-11-26 Thread Karan Chaudhary
>From the top of my head, shouldn't the benchmark be done when traffic is being sent to the server and not before it is sent? On Sunday, 26 November 2017 00:11:40 UTC+5:30, basti skalendudler wrote: > > Hey guiys, I posted a StackOF question two days ago, but so far nobody was > able to help me

[go-nuts] Re: who does go compiler link executable to glibc without an apparent reason?

2017-11-07 Thread Karan Chaudhary
With a quick look, it seems "net" is not the only pkg which depends on cgo, though by default it uses pure Go DNS resolver only. I tested on small program: package main import ( "fmt" "net/http" ) func main() { fmt.Println("Hello, playground") http.ListenAndSe

[go-nuts] Re: Data persistence in go routine in defer

2017-11-07 Thread Karan Chaudhary
Yes it will work as "x" is within scope. https://play.golang.org/p/dhBahtIVGb On Tuesday, 7 November 2017 14:42:47 UTC+5:30, Abhijit Desai wrote: > > I want to log MyStruct value in "defer + go routine" so that logging > will not affect total execution time of the the request which works

Re: [go-nuts] network programming about go

2017-11-06 Thread Karan Chaudhary
Is the port 5000 on 192.168.153.239 open? If it is open, is your server running on that port? https://stackoverflow.com/questions/2972600/no-connection-could-be-made-because-the-target-machine-actively-refused-it On Monday, 6 November 2017 19:30:22 UTC+5:30, 28911...@gmail.com wrote: > > I try

[go-nuts] Re: how could a new user konw which packge should be used?

2017-11-06 Thread Karan Chaudhary
Oh, didn't check that! On Monday, 6 November 2017 17:49:52 UTC+5:30, dja...@gmail.com wrote: > > > > On Monday, November 6, 2017 at 12:23:37 PM UTC+2, Karan Chaudhary wrote: >> >> Another one: http://go-search.org >> > > Go Search > 756881 <http://

Re: [go-nuts] accept4: too many open files;

2017-11-06 Thread Karan Chaudhary
CMIIW, I doubt if it is explicitly needed to close the request's body in handler, as it seems, close of request's body is handled by stdlib upon completion of handler. Handler, in net/http, is called here: https://github.com/golang/go/blob/master/src/net/http/server.go#L1804 Finish Request

[go-nuts] Re: how could a new user konw which packge should be used?

2017-11-06 Thread Karan Chaudhary
Another one: http://go-search.org On Friday, 3 November 2017 21:21:48 UTC+5:30, 517 March wrote: > > as a new Go programmer, > how could I know which package should be use? > > is there any search tool could be used? > > or does it just depend on your experience? > -- You received this message

Re: [go-nuts] Bizarre Error Message (Go 1.9.2)

2017-11-06 Thread Karan Chaudhary
> > `go run` takes multiple files as arguments. > Interesting. Didn't know this was possible. Until now i used to fallback to using go build if code was distributed over multiple files. (When i'm testing some case which includes few files) -- You received this message because you are subs

Re: [go-nuts] Re: concurrency programing about go

2017-11-06 Thread Karan Chaudhary
Just a note that waitGroup should be passed as reference to functions/methods rather than as value. I have made mistakes where the program hung as Done was called on copy of waitgroup rather than on the original wg to which tasks were added. Here it is not a problem as waitgroup used within an

[go-nuts] Re: input and output about go

2017-11-06 Thread Karan Chaudhary
You need to break the scanning by passing EOF to the program. Use ctrl-d if you're on Unix based system. go doc bufio.Scan func (s *Scanner) Scan() bool Scan advances the Scanner to the next token, which will then be available through the Bytes or Text method. It returns false when the

Re: [go-nuts] Defer with anon func and func literal

2017-09-28 Thread Karan Chaudhary
I see. I'm trying to find rationale for this: why is "defer foo(x)" treated differently than "defer func() { foo(x) }" by the language designers? On Thursday, 28 September 2017 17:57:45 UTC+5:30, Jan Mercl wrote: > > On Thu, Sep 28, 2017 at 2:18 PM Karan Chaudhar

[go-nuts] Defer with anon func and func literal

2017-09-28 Thread Karan Chaudhary
Hi, I have a doubt regarding use of enclosing function's variables inside functions used as "deferred". If function literal is used as "deferred" func (say foo), and it uses enclosing function's variable (say x) as one of its arguments, the value of x is "frozen" and func foo is called with t

[go-nuts] nosplit stack overflow while installing

2017-03-02 Thread Karan Chaudhary
Hi, I'm getting this error when install the project: runtime.cgocall: nosplit stack overflow 584 assumed on entry to runtime.cgocall (nosplit) 528 after runtime.cgocall (nosplit) uses 56 520 on entry to runtime.entersyscall (nosplit) 480 after runti