Re: [go-nuts] Extension for type assertion of interface array

2018-04-19 Thread ankit . gupta
Though the above is not allowed, you can restructure your code to wrap your 
struct as array in another struct and have area() paas a index to the 
underlying struct. Something like this (landSpaceArr wraps landSpace 
struct) - 

type landSpace struct{
side int
}

type landSpaceArr struct {
lS []landSpace
}

func (s *landSpaceArr) area(i int) int {
return s.lS[i].side * s.lS[i].side
}

type Shapes interface {
area(int) int
}

func main() {

v := make([]landSpace, 1)
v[0].side =50
a := &landSpaceArr{lS: v}

processShapes(a, 0)
}

func processShapes(shapes Shapes, i int) {

println(shapes.area(i))
}

~

On Thursday, April 19, 2018 at 10:29:12 AM UTC+5:30, Sakthi Natesan wrote:
>
> Usescases that I came across doesn't involve []interface{}. 
>
> My usecases will be similar to this sample code 
> 
>
> type landSpace struct {
> //consider that landSpace implements all functions from both Shape and 
> property interfaces
> ...
> }
> type Shape interface {
> ...
> }
>
>
> type property interface {
>
> ...
> }
>
>
> var a []*landSpace
>
> func processShapes(shapes []Shape) {
> //
> }
>
> func evaluateProperties(properties []Property) {
> //
> }
>
>
>
> If I want to pass the variable 'a' to both the functions, then I have to 
> write two functions to clone and typeAssert to respective interfaces.
>
>
> On Wednesday, 18 April 2018 19:53:33 UTC+5:30, Jan Mercl wrote:
>>
>> On Wed, Apr 18, 2018 at 4:13 PM  wrote:
>>
>> When possible, avoid using '[]interface{}' and use just 'interface{}' 
>> instead: https://play.golang.org/p/oPtPoGChkMZ.
>>
>>
>> -- 
>>
>> -j
>>
>
-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
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: parallel array processing question

2018-04-20 Thread Ankit Gupta
There could have been a data race in your code with the usage of allMax 
variable which is updated and checked by multiple goroutines. But you are 
saved by the use of mutex. All shared variables, in general, are subject to 
data races when there is a write involved. The local variables you create 
and params passed by value to goroutines are not subject to data race. Your 
usage of mutex is correct, but you can have it block only these lines --

mutex.Lock()

*if* sliceMax > allMax {

allMax = sliceMax

}

mutex.Unlock()


Now, whenever you have doubt, just remove mutex and run your code with 
-race directive. Go runtime will provide details if any racy code is 
detected.

Also, your slice range will omit last element, so do this - 

endIndex = len(numbers)


instead of 


endIndex = len(numbers) - 1



On Thursday, April 19, 2018 at 5:05:20 PM UTC+5:30, l vic wrote:
>
> I have a program that calculates max value in integer array by breaking 
> the array into number of slices and calculating max in every slice inside 
> of go-routine.
> Do I still need to lock/unlock each slice with mutex inside of go-routine? 
> The code seems to be working but are any apparent problems with it?
>
> package main
>
>
> import (
>
> "fmt"
>
> "os"
>
> "strconv"
>
> "sync"
>
> )
>
>
> //returns maximum number found in provided slice
>
> func maxInSlice(numbers []uint) (uint, error) {
>
> if numbers == nil {
>
> return 0, fmt.Errorf("nil  numbers")
>
> }
>
>
> var max uint = 0
>
> for _, n := range numbers {
>
> for _, m := range numbers {
>
> if n > m {
>
> max = n
>
> }
>
> }
>
> }
>
>
> return max, nil
>
> }
>
>
> // finds  maximum  number  in  numbers  array  by   breaking  work  into  N  
> pieces
>
> // (where  N  is provided  as a command  line  argument)  and processing  the
>
> // pieces  in  parallel  goroutines func  main()
>
> func main() {
>
> parallelism, _ := strconv.Atoi(os.Args[1])
>
> fmt.Printf("ok,  i'll  use %d  goroutines\n", parallelism)
>
>
> numbers := []uint{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
>
> wg := sync.WaitGroup{}
>
> mutex := sync.Mutex{}
>
> var allMax uint = 0
>
> perGoRoutine := len(numbers) / parallelism
>
> fmt.Printf("perGoRoutine=%d\n", perGoRoutine)
>
>
> for i := 0; i < parallelism; i++ {
>
> wg.Add(1)
>
> go func(i int) {
>
> defer wg.Done()
>
> fmt.Printf("==>index i = %d perGoRoutine in go func=%d\n", i, 
> perGoRoutine)
>
> startIndex := perGoRoutine * i
>
> endIndex := startIndex + perGoRoutine - 1
>
> //include last element
>
> if i == parallelism-1 {
>
> endIndex = len(numbers) - 1
>
>
> }
>
>
> fmt.Printf("startIndex=%d endIndex=%d\n", startIndex, endIndex)
>
> sliceMax, err := maxInSlice(numbers[startIndex:endIndex])
>
> mutex.Lock()
>
> if err != nil {
>
> fmt.Printf("error  finding  max  for  slice  %d  to  %d, 
> skipping  this  slice:  %s\n", err)
>
> return
>
> }
>
>
> fmt.Printf("goroutine  %d  (slice  %d  to  %d)  found  max  
> %d\n", i, startIndex, endIndex, sliceMax)
>
> if sliceMax > allMax {
>
> allMax = sliceMax
>
> }
>
> mutex.Unlock()
>
>
> }(i)
>
>
> }
>
> wg.Wait()
>
>
> fmt.Printf("maximum:  %d\n", allMax)
>
>
> }
>
>
>
>
>
-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
*::DISCLAIMER::




The contents of this e-mail and any attach

[go-nuts] Re: Accessing Slices Made From Same Array Concurrently

2018-04-21 Thread Ankit Gupta
@Kaveh

Slices are values but they refer to the same back array location. You have 
created localized v which is appended inside goroutine which refer to a 
location containing its own byte array of len=10. So, you are not really 
referencing the same memory location as other v slice in the goroutine. You 
will be affected if you remove k,v:=k,v or append more than 10 bytes to v 
inside goroutine which will take up space on next slice's bytes. 

On Saturday, April 21, 2018 at 2:30:53 PM UTC+5:30, Kaveh Shahbazian wrote:
>
> @ Louki Sumirniy
> Slices are values AFAIK. There is no passby pointer.
>
> And the point is, race detector does not flag anything: 
> https://play.golang.org/p/NC8mBwS1-0P
>

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


[go-nuts] Question regarding runtime.ReadMemStats

2018-04-22 Thread Ankit Gupta
I ran a goroutine 3 times, at the end of each, I run runtime.GC() and print 
mem stats. Just before exiting program, I do it once more. This is what I 
get in each runs - 

HeapSys = 720896 Alloc = 48408 TotalAlloc = 62464 StackSys = 327680 Sys = 
2461696 GCSys = 63488 NumGC = 1 PauseTotalNs = 1680857
HeapSys = 720896 Alloc = 48408 TotalAlloc = 63496 StackSys = 327680 Sys = 
2461696 GCSys = 63488 NumGC = 2 PauseTotalNs = 1905615
HeapSys = 753664 Alloc = 48408 TotalAlloc = 64528 StackSys = 294912 Sys = 
2461696 GCSys = 63488 NumGC = 3 PauseTotalNs = 2123106
HeapSys = 786432 Alloc = 48280 TotalAlloc = 65560 StackSys = 262144 Sys = 
2461696 GCSys = 63488 NumGC = 4 PauseTotalNs = 2341283

While I understand most of the allocations in my program, I don't get why 
*HeapSys* is more than 15 times of *Alloc*. If this is reserved virtual 
space from OS, why does it have to be this big? Any reasons.

-- 
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] bufio usage hurting performance

2018-05-04 Thread Ankit Gupta
I recently wrote a reverse proxy in Go 
- https://github.com/gptankit/serviceq which does load balancing and queues 
failed requests (to dipatch later). 
When I compared perf with nginx, I noticed 15-20 ms higher response times. 
So, I timed each function, and got to know that the code spends most time 
in 3 places - 

Read from tcp conn
Save in a buffer
Write to tcp conn

'Save' is necessary addition as I need to re-run the requests. For 'Read' 
and 'Write', I use bufio - 

Read:
reader := bufio.NewReader(*httpConn.tcpConn)
req, err := http.ReadRequest(reader)

Write:
writer := bufio.NewWriter(*httpConn.tcpConn)

Why does Go impose me to read from bufio.Reader and not directly from 
io.Reader? I understand the implication for bigger data but for few bytes, 
managing a buffer seems like an overhead.

I am using Go 1.6.

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
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: beginner question about chanels

2018-05-04 Thread Ankit Gupta
ch := make(chan bool) means you want to have an unbufferred channel. Send 
and Receive are block operations. In other words, send will block unless 
there is a receive operation, which is the case in your code. All calls to 
increment are blocked at ch <- true.

When you change it to ch := make(chan bool, 1), you create a bufferred 
chanel, send does not block and program moves on to empty the channel at 
<-ch.

Imp thing to note here is that when you exceed the send operations by 
channel capacity, it starts acting like an unbufferred channel.

On Friday, May 4, 2018 at 6:51:49 PM UTC+5:30, k1at...@gmail.com wrote:
>
> Hi
>
> i dont' understn what is the difference between :
>
> ch := make(chan bool,1)   vs. ch := make(chan bool)
>
> this sample works well :
>
> package main
>
> import (
> "fmt"
> "sync"
> )
>
> var x = 0
>
> func increment(wg *sync.WaitGroup, ch chan bool) {
> ch <- true
> x = x + 1
> <-ch
> wg.Done()
> }
> func main() {
> var w sync.WaitGroup
> ch := make(chan bool,1)   <--it is OK , but if i 
> change to  ch := make(chan bool) - it doesn't work
> for i := 0; i < 1000; i++ {
> w.Add(1)
> go increment(&w, ch)
> }
> w.Wait()
> fmt.Println("final value of x", x)
> }
>
> Thank you in advance
>

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
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] bufio usage hurting performance

2018-05-04 Thread Ankit Gupta
I am talking in terms of parsing http request by using

http.ReadRequest method which only accept bufio.Reader 
(https://golang.org/pkg/net/http/#ReadRequest)

On Friday, May 4, 2018 at 8:04:22 PM UTC+5:30, Ian Lance Taylor wrote:
>
> On Fri, May 4, 2018 at 5:20 AM, Ankit Gupta  > wrote: 
> > 
> > I recently wrote a reverse proxy in Go - 
> > https://github.com/gptankit/serviceq which does load balancing and 
> queues 
> > failed requests (to dipatch later). 
> > When I compared perf with nginx, I noticed 15-20 ms higher response 
> times. 
> > So, I timed each function, and got to know that the code spends most 
> time in 
> > 3 places - 
> > 
> > Read from tcp conn 
> > Save in a buffer 
> > Write to tcp conn 
> > 
> > 'Save' is necessary addition as I need to re-run the requests. For 
> 'Read' 
> > and 'Write', I use bufio - 
> > 
> > Read: 
> > reader := bufio.NewReader(*httpConn.tcpConn) 
> > req, err := http.ReadRequest(reader) 
> > 
> > Write: 
> > writer := bufio.NewWriter(*httpConn.tcpConn) 
> > 
> > Why does Go impose me to read from bufio.Reader and not directly from 
> > io.Reader? I understand the implication for bigger data but for few 
> bytes, 
> > managing a buffer seems like an overhead. 
>
> I'm sorry, I don't understand the question.  Go does not in general 
> require you to use a bufio.Reader.  Where is that requirement coming 
> from? 
>
>
> > I am using Go 1.6. 
>
> That is pretty old now. 
>
> Ian 
>

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
<http://redbus.in/>com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
<http://redbus.in/>com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

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


[go-nuts] Re: go 1 on Ubuntu 18.04

2018-05-07 Thread Ankit Gupta

Updating Go is simply a matter of removing old Go installation directory 
and replace it with new one. For your particular use case - 

Remove the go folder under /usr/lib (the /usr/bin/go just holds the 
binary). 
Install the new go version to /usr/local as mentioned on golang 
installation manual and have GOROOT set up
Update PATH variable to point to "/usr/local/go/bin" by adding below to 
/etc/environment variable

:/usr/local/go/bin

So the final PATH looks something like this - 

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/go/bin"

Execute 'source /etc/environment'

You are set

On Sunday, May 6, 2018 at 8:27:07 AM UTC+5:30, Robert Solomon wrote:
>
> I have a question regarding file locations for go on Ubuntu.  I just 
> installed Ubuntu 18.04 and installed go 1.10.1 thru the package 
> manager.  That puts the go system in /usr/bin. 
>
> The instructions on the golang site when installing an updated version 
> of go, like version 1.10.2, says to install in /usr/local so the to 
> system ends up in /usr/local/go/bin. 
>
> If I wanted to install an updated go, like v 1.11 when it comes out, how 
> do I handle the fact that apt put the current go files in /usr/bin? 
>
> Thx 
>
> --rob 
>
>
>
-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
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: go 1 on Ubuntu 18.04

2018-05-07 Thread Ankit Gupta
Different school of thoughts I guess. I would personally prefer my software 
installs to go under one of either /usr or /opt (certainly when I have root 
permission). Feels safer and idiomatic that way.

On Tuesday, May 8, 2018 at 1:07:16 AM UTC+5:30, Shawn Milochik wrote:
>
> On Mon, May 7, 2018 at 3:32 PM, Ankit Gupta  > wrote:
>
>>
>> Updating Go is simply a matter of removing old Go installation directory 
>> and replace it with new one. For your particular use case - 
>>
>>
> A better solution (in my opinion) is to decompress the new Go tarball to a 
> new location (preferably in your $HOME directory) and update the GOROOT in 
> your .bashrc (or whatever your shell RC) is.
>
> This allows you to switch back easily if something goes wrong, or keep 
> multiple versions available at any time so you can try compiling against 
> different variables just by changing an environment variable. In addition, 
> in the unlikely event that there are multiple accounts using Go on that 
> computer, you changing it won't effect any other users.  
>

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
<http://redbus.in/>com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
<http://redbus.in/>com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
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] Load balancing with error feedback capabilities

2018-05-18 Thread Ankit Gupta
Hello gophers,

I recently built a small HTTP load balancer with capabilities built around 
error feedback - https://github.com/gptankit/serviceq
Provides two primary functionalities - deferred request queue and 
probabilitically reducing errored nodes selection.

I am using channel as a in-memory data structure for storing deferred 
requests. Would love some feedback on this approach and on the project in 
general.



-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
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: Load balancing with error feedback capabilities

2018-05-18 Thread Ankit Gupta
Hi Matt,

First of all, thanks so much for the review.

I will revisit the package structure and take care of err handling in a 
more idiomatic way. Few points - 

- The mutex is embedded in model.ServiceQProperties. Here is the definition 
in model.balancer_properties.go - 

type ServiceQProperties struct {
...
REMutex sync.Mutex
}

This is used in two places - error logging to service map in 
service_error.go and reading in select_service.go.

- I validated 3 things (all tests were done on a cluster of aws t2 medium 
linux machines) -  

a) Program should reduce probability of selection of errored nodes - this 
was done by continously bringing 1 to n-1 services down/up and noting the 
trend of requests sent to each node after every state change. As an 
example, for a 3 node cluster with 1 node down for 2 mins, the probability 
of selection of that node reduced (from 33%) by around 1-2% on each 
subsequent hit.

b) For performance testing, I used apache bench for issuing large number of 
concurrent requests/issuing requests within a time frame and benchmarking 
against nginx. There was a 10% difference on average that is attributed to 
the fact that I preprocess (parse/store) all requests before forwarding and 
that the code is not the most optimzed version right now.

c) For deferred queue functionality, I specifically wanted to test 
scenarios where both active and deferred requests are to be sent out 
simultaneously and if user defined concurrency limits are still valid.

Let me know if I should provide more details on a specific feature.

Thanks,
Ankit

On Friday, May 18, 2018 at 8:21:12 PM UTC+5:30, matthe...@gmail.com wrote:
>
> Hi Ankit, thanks for the Apache license and for sharing here. Here’s a 
> code review.
>
> These are my unfiltered opinions and I hope that they are useful.
>
> Without looking at any code yet, the packages might not be idiomatic. 
> Packages should contain specific behavior that can be decoupled from the 
> application. These concepts could be represented as files and symbols in 
> package main.
>
> SQP_K_LISTENER_PORT might be more regularly represented as 
> SQPKListenerPort.
>
> In config_manager_test.go you could embed model.ServiceQProperties and 
> error in type Properties for better readability.
>
> The newlines in the functions don’t help readability.
>
> Instead of this:
>
> if sqp, err := getProperties(getPropertyFilePath()); err == nil {
> …
> } else {
> fmt.Fprintf(os.Stderr…
>
> this may be more readable:
>
> // or if …; err != nil {
> sqp, err := getProperties(getPropertyFilePath())
> if err != nil {
> fmt.Fprintf(os.Stderr…
> return
> }
> // regular functionality
>
> Generally “err == nil” shouldn’t be in the code.
>
> In getListener a similar improvement could be made to avoid the 
> unnecessary indentation:
>
> if sqp.SSLEnabled == false {
> return …
> }
> // longer behavior
>
> In TestWorkAssignment the sqp could be simpler:
>
> sqp := model.ServiceQProperty{
> ListenerPort: “5252”,
> Proto:“http”,
> …
>
> More if improvement in algorithm.ChooseServiceIndex:
>
> if retry != 0 {
> return …
> }
> // longer behavior
>
> The else after “if sumErr == 0” is unnecessary.
>
> The mutex could be embedded in model.ServiceQProperties.
>
> How did you validate this program?
>
> Thanks,
> Matt
>
> On Friday, May 18, 2018 at 2:34:20 AM UTC-5, Ankit Gupta wrote:
>>
>> Hello gophers,
>>
>> I recently built a small HTTP load balancer with capabilities built 
>> around error feedback - https://github.com/gptankit/serviceq
>> Provides two primary functionalities - deferred request queue and 
>> probabilitically reducing errored nodes selection.
>>
>> I am using channel as a in-memory data structure for storing deferred 
>> requests. Would love some feedback on this approach and on the project in 
>> general.
>>
>>
>>
-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemina

[go-nuts] Re: Load balancing with error feedback capabilities

2018-05-19 Thread Ankit Gupta
Hi Matt,

Ok, if you meant the type embedding -- I usually prefer it for composition 
purpose, so that I can pass around the composed type (or pointer) to 
function calls. Did not find any such need.

I haven’t gotten far enough into network services to have much to say about 
> the features although maybe I will in the future. I was curious about this:
>
> The buffered requests are forwarded in FIFO order when the service is 
>> available next.
>
>
> wouldn’t you want to do these concurrently if possible?
>

I did give it a thought before implementing, but I considered this 
situation - the cluster is down for x mins, and due to the fact no requests 
are getting forwarded, the request buffer fills up quickly and might reach 
the user defined concurrency limit. Now when the cluster is up, and there 
are active requests being accepted too, whom should I give preference to? 
Because I maintain a central work queue for both active and deferred 
requests, I let the program flow decide the order of processing. Perhaps I 
can build an approach to have deferred requests run concurrently if there 
are no active requests in queue and switch back to sequential if there are. 
Or it can be another user defined parameter.

Thanks,
Ankit


On Saturday, May 19, 2018 at 3:16:08 AM UTC+5:30, matthe...@gmail.com wrote:
>
> By embedding I meant this:
>
> type ServiceQProperties struct {
> ...
> sync.Mutex
> }
>
> which allows you to call p.Lock() instead of p.REMutex.Lock(). It’s just a 
> personal preference that I was happy about when I learned about it.
>
> One thought here is you could make it a *sync.Mutex and not use a pointer 
> in these function arguments. Maps vars are pointers so you are doing a 
> double dereference when accessing RequestErrorLog. This avoids (*sqp) but 
> there may be extra memory used and work done to copy the entire struct var 
> as an argument. If you get into performance details I would look at pprof 
> or package testing benchmarking to decide if it matters, but I try to 
> choose cleanest code first.
>
> Thanks for sharing your verification approach.
>
> I haven’t gotten far enough into network services to have much to say 
> about the features although maybe I will in the future. I was curious about 
> this:
>
> The buffered requests are forwarded in FIFO order when the service is 
>> available next.
>
>
> wouldn’t you want to do these concurrently if possible?
>
> Matt
>
> On Friday, May 18, 2018 at 11:50:56 AM UTC-5, Ankit Gupta wrote:
>>
>> Hi Matt,
>>
>> First of all, thanks so much for the review.
>>
>> I will revisit the package structure and take care of err handling in a 
>> more idiomatic way. Few points - 
>>
>> - The mutex is embedded in model.ServiceQProperties. Here is the 
>> definition in model.balancer_properties.go - 
>>
>> type ServiceQProperties struct {
>> ...
>> REMutex sync.Mutex
>> }
>>
>> This is used in two places - error logging to service map in 
>> service_error.go and reading in select_service.go.
>>
>> - I validated 3 things (all tests were done on a cluster of aws t2 medium 
>> linux machines) -  
>>
>> a) Program should reduce probability of selection of errored nodes - this 
>> was done by continously bringing 1 to n-1 services down/up and noting the 
>> trend of requests sent to each node after every state change. As an 
>> example, for a 3 node cluster with 1 node down for 2 mins, the probability 
>> of selection of that node reduced (from 33%) by around 1-2% on each 
>> subsequent hit.
>>
>> b) For performance testing, I used apache bench for issuing large number 
>> of concurrent requests/issuing requests within a time frame and 
>> benchmarking against nginx. There was a 10% difference on average that is 
>> attributed to the fact that I preprocess (parse/store) all requests before 
>> forwarding and that the code is not the most optimzed version right now.
>>
>> c) For deferred queue functionality, I specifically wanted to test 
>> scenarios where both active and deferred requests are to be sent out 
>> simultaneously and if user defined concurrency limits are still valid.
>>
>> Let me know if I should provide more details on a specific feature.
>>
>> Thanks,
>> Ankit
>>
>> On Friday, May 18, 2018 at 8:21:12 PM UTC+5:30, matthe...@gmail.com 
>> wrote:
>>>
>>> Hi Ankit, thanks for the Apache license and for sharing here. Here’s a 
>>> code review.
>>>
>>> These are my unfiltered opinions and I hope that they are useful.
>>>
>>> Without looking at a

Re: [go-nuts] Load balancing with error feedback capabilities

2018-05-19 Thread Ankit Gupta
@Jakob Can you explain it further? Two different instances of 
ServiceQProperties should each get their own reference of underlying 
sync.Mutex. So, Lock() and Unlock() should be on different objects.

Thanks,
Ankit

On Saturday, May 19, 2018 at 3:39:40 AM UTC+5:30, Jakob Borg wrote:
>
> That also means anyone else can call Lock() and Unlock() on your type. 
> This is often not what you want, unless your type *is* a kind of lock (as 
> opposed to *uses* a lock).
>
> On 18 May 2018, at 23:45, matth...@gmail.com  wrote:
>
> By embedding I meant this:
>
> type ServiceQProperties struct {
> ...
> sync.Mutex
> }
>
> which allows you to call p.Lock() instead of p.REMutex.Lock(). It’s just a 
> personal preference that I was happy about when I learned about it.
>
>
>
-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
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] http.ReadRequest doesn't recognize http2?

2018-05-21 Thread Ankit Gupta
Hello gophers,

I am trying to read http2 request on a tcp connection, which is set up like 
this - 

cert, err := tls.LoadX509KeyPair(certfile, certkeyfile)
if err != nil {
return nil, err
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
ServerName:   "mysrvr",
NextProtos:   []string{"h2", "http/1.1", 
"http/1.0"},
Time: time.Now,
Rand: rand.Reader,
}
tlsConfig.BuildNameToCertificate()
tlsConfig.PreferServerCipherSuites = true
listener := tls.Listen("tcp", ":"+sqp.ListenerPort, 
tlsConfig)

for {
   conn, err := listener.Accept()
   reader := bufio.NewReader(conn)
   req, err := http.ReadRequest(reader) // problem here
   // do other things with req
 }

When I do **curl https://127.0.0.1:8000 -k --http2** to the above server, I 
was expecting http.ReadRequest to parse the request same as it does for 
http/1.1 or 1.0.

What I saw was that the request contained PRI method (which is defined in 
http2 rfc) and even if I ignore the complete connection preface and the 
SETTINGS frame after it, I still don't get the original request. Though if 
I try reading directly from tcp connection, I get a blob right after PRI 
and SETTINGS frame. 

I looked at ParseHTTPVersion 
(https://golang.org/src/net/http/request.go?s=29537:29588#L708) called from 
readRequest and it doesn't even have a case for HTTP/2. Does it mean I 
can't use http.ReadRequest for HTTP/2 requests?

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
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: http.ReadRequest doesn't recognize http2?

2018-05-21 Thread Ankit Gupta
This issue is now opened https://go-review.googlesource.com/c/113817/

I am still looking for an alternative though - to know if a certain 
sequence of bytes contains http2 data with method/headers/body.

On Monday, May 21, 2018 at 5:24:09 PM UTC+5:30, Ankit Gupta wrote:
>
> Hello gophers,
>
> I am trying to read http2 request on a tcp connection, which is set up 
> like this - 
>
> cert, err := tls.LoadX509KeyPair(certfile, certkeyfile)
> if err != nil {
> return nil, err
> }
> tlsConfig := &tls.Config{
> Certificates: []tls.Certificate{cert},
> ServerName:   "mysrvr",
> NextProtos:   []string{"h2", "http/1.1", 
> "http/1.0"},
> Time: time.Now,
> Rand: rand.Reader,
> }
> tlsConfig.BuildNameToCertificate()
> tlsConfig.PreferServerCipherSuites = true
> listener := tls.Listen("tcp", ":"+sqp.ListenerPort, 
> tlsConfig)
> 
> for {
>conn, err := listener.Accept()
>reader := bufio.NewReader(conn)
>req, err := http.ReadRequest(reader) // problem here
>// do other things with req
>  }
>
> When I do **curl https://127.0.0.1:8000 -k --http2** to the above server, 
> I was expecting http.ReadRequest to parse the request same as it does for 
> http/1.1 or 1.0.
>
> What I saw was that the request contained PRI method (which is defined in 
> http2 rfc) and even if I ignore the complete connection preface and the 
> SETTINGS frame after it, I still don't get the original request. Though if 
> I try reading directly from tcp connection, I get a blob right after PRI 
> and SETTINGS frame. 
>
> I looked at ParseHTTPVersion (
> https://golang.org/src/net/http/request.go?s=29537:29588#L708) called 
> from readRequest and it doesn't even have a case for HTTP/2. Does it mean I 
> can't use http.ReadRequest for HTTP/2 requests?
>

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
<http://redbus.in/>com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
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] Correct way of sending HEADERS and DATA frames in http2?

2018-05-23 Thread Ankit Gupta
I am using *golang.org/x/net/http2* and *golang.org/x/net/http2/**hpack* 
packages to do low level http2 framing. For requests with only HEADERS 
frame sent, I want to send a empy json '{}', so I send 1 HEADERS frame and 
1 DATA frame as below 

headersframe, ok := frame.(*http2.HeadersFrame)
if ok {
println("headers frame detected")

if headersframe.StreamEnded() {
 
// write HEADERS frame with 2 headers
  
hbytes := make([]byte, 0, 2048)
hbuffer := bytes.NewBuffer(hbytes)
hfield1 := hpack.HeaderField{
Name: ":status",
Value: "200",
Sensitive: false,}
hfield2 := hpack.HeaderField{
Name: "content-type",
Value: "application/json",
Sensitive: false,}

encoder := hpack.NewEncoder(hbuffer)
err := encoder.WriteField(hfield1)
err = encoder.WriteField(hfield2)
if err != nil {
println(err.Error())
}
hfp := http2.HeadersFrameParam{
StreamID: frame.Header().StreamID,
BlockFragment: hbuffer.Bytes(),
EndStream: false,
EndHeaders: true,
}
err = framer.WriteHeaders(hfp)
if err != nil {
println(err.Error())
}

// write DATA frame

data := []byte("{}")
framer.WriteData(frame.Header().StreamID, true, data)
}
return
}

On trying with *curl -v https://127.0.0.1:8000 -k --http2*, I get error as 
- 

curl: (16) Error in the HTTP2 framing layer

Is anything missing in my way of framing response?

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
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] Unsupported File Format error while building for linux-amd64 on mac os

2018-09-28 Thread Ankit Gupta
I am working with confluent-kafka-go library 
(https://github.com/confluentinc/confluent-kafka-go) which builds fine on 
the mac machine (mac OS 10.13.6) along with the code files I wrote. In 
order to deploy it on Linux server (Ubuntu 64 bit), I try this - 

$> CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build program.go


I get below linking error -


/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 
1

ld: warning: ignoring file 
/var/folders/fy/9ph54yjs6cq1kyxgs6cc9rvjvs6t0m/T/go-link-060577916/go.o, 
file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 
0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the 
architecture being linked (x86_64): 
/var/folders/fy/9ph54yjs6cq1kyxgs6cc9rvjvs6t0m/T/go-link-060577916/go.o

Undefined symbols for architecture x86_64:

  "__cgo_topofstack", referenced from:

  __cgo_f2fa82ea8f11_Cfunc_rd_kafka_conf_new in 03.o

  __cgo_f2fa82ea8f11_Cfunc_rd_kafka_conf_set in 03.o

  __cgo_f2fa82ea8f11_Cfunc_rd_kafka_topic_conf_new in 03.o

  __cgo_f2fa82ea8f11_Cfunc_rd_kafka_topic_conf_set in 03.o

  __cgo_f2fa82ea8f11_Cfunc__c_rdkafka_topic_partition_list_entry in 
04.o

  __cgo_f2fa82ea8f11_Cfunc_rd_kafka_assign in 04.o

  __cgo_f2fa82ea8f11_Cfunc_rd_kafka_assignment in 04.o

  ...

  "_main", referenced from:

 implicit entry/start for main executable

 (maybe you meant: __cgo_f2fa82ea8f11_Cfunc_rd_kafka_queue_get_main)

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see 
invocation)


It points to /var/folders which I am given to understand is a temp location 
in mac.


Any ideas on how to fix it?

-- 
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] Unsupported File Format error while building for linux-amd64 on mac os

2018-09-28 Thread Ankit Gupta
Thanks Ian for responding. Can you point me as to how to get the cross
compiler. I am farely new to Mac.

On Fri, 28 Sep 2018, 19:23 Ian Lance Taylor,  wrote:

> On Fri, Sep 28, 2018 at 2:08 AM, Ankit Gupta
>  wrote:
> >
> > I am working with confluent-kafka-go library
> > (https://github.com/confluentinc/confluent-kafka-go) which builds fine
> on
> > the mac machine (mac OS 10.13.6) along with the code files I wrote. In
> order
> > to deploy it on Linux server (Ubuntu 64 bit), I try this -
> >
> > $> CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build program.go
> >
> >
> > I get below linking error -
> >
> >
> > /usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit
> status
> > 1
> >
> > ld: warning: ignoring file
> > /var/folders/fy/9ph54yjs6cq1kyxgs6cc9rvjvs6t0m/T/go-link-060577916/go.o,
> > file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02
> 0x01
> > 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the
> > architecture being linked (x86_64):
> > /var/folders/fy/9ph54yjs6cq1kyxgs6cc9rvjvs6t0m/T/go-link-060577916/go.o
> >
> > Undefined symbols for architecture x86_64:
> >
> >   "__cgo_topofstack", referenced from:
> >
> >   __cgo_f2fa82ea8f11_Cfunc_rd_kafka_conf_new in 03.o
> >
> >   __cgo_f2fa82ea8f11_Cfunc_rd_kafka_conf_set in 03.o
> >
> >   __cgo_f2fa82ea8f11_Cfunc_rd_kafka_topic_conf_new in 03.o
> >
> >   __cgo_f2fa82ea8f11_Cfunc_rd_kafka_topic_conf_set in 03.o
> >
> >   __cgo_f2fa82ea8f11_Cfunc__c_rdkafka_topic_partition_list_entry in
> > 04.o
> >
> >   __cgo_f2fa82ea8f11_Cfunc_rd_kafka_assign in 04.o
> >
> >   __cgo_f2fa82ea8f11_Cfunc_rd_kafka_assignment in 04.o
> >
> >   ...
> >
> >   "_main", referenced from:
> >
> >  implicit entry/start for main executable
> >
> >  (maybe you meant: __cgo_f2fa82ea8f11_Cfunc_rd_kafka_queue_get_main)
> >
> > ld: symbol(s) not found for architecture x86_64
> >
> > clang: error: linker command failed with exit code 1 (use -v to see
> > invocation)
> >
> >
> > It points to /var/folders which I am given to understand is a temp
> location
> > in mac.
> >
> >
> > Any ideas on how to fix it?
>
> When cross-compiling a Go program that uses cgo, you need to be using
> a C cross-compiler.  It looks like you are using the native Darwin C
> compiler.  You need a cross-compiler from Darwin to GNU/Linux.
>
> 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] Unsupported File Format error while building for linux-amd64 on mac os

2018-10-01 Thread Ankit Gupta
Tamas,

I installed docker on mac and cross compiled using xgo like you suggested. 
Worked perfectly. Thanks a lot!

On Saturday, September 29, 2018 at 1:58:20 AM UTC+5:30, Tamás Gulácsi wrote:
>
> 2018. szeptember 28., péntek 15:59:14 UTC+2 időpontban Ankit Gupta a 
> következőt írta:
>>
>> Thanks Ian for responding. Can you point me as to how to get the cross 
>> compiler. I am farely new to Mac.
>>
>> On Fri, 28 Sep 2018, 19:23 Ian Lance Taylor,  wrote:
>>
>>> On Fri, Sep 28, 2018 at 2:08 AM, Ankit Gupta
>>>  wrote:
>>> >
>>> > I am working with confluent-kafka-go library
>>> > (https://github.com/confluentinc/confluent-kafka-go) which builds 
>>> fine on
>>> > the mac machine (mac OS 10.13.6) along with the code files I wrote. In 
>>> order
>>> > to deploy it on Linux server (Ubuntu 64 bit), I try this -
>>> >
>>> > $> CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build program.go
>>> >
>>> >
>>> > I get below linking error -
>>> >
>>> >
>>> > /usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit 
>>> status
>>> > 1
>>> >
>>> > ld: warning: ignoring file
>>> > 
>>> /var/folders/fy/9ph54yjs6cq1kyxgs6cc9rvjvs6t0m/T/go-link-060577916/go.o,
>>> > file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 
>>> 0x01
>>> > 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the
>>> > architecture being linked (x86_64):
>>> > /var/folders/fy/9ph54yjs6cq1kyxgs6cc9rvjvs6t0m/T/go-link-060577916/go.o
>>> >
>>> > Undefined symbols for architecture x86_64:
>>> >
>>> >   "__cgo_topofstack", referenced from:
>>> >
>>> >   __cgo_f2fa82ea8f11_Cfunc_rd_kafka_conf_new in 03.o
>>> >
>>> >   __cgo_f2fa82ea8f11_Cfunc_rd_kafka_conf_set in 03.o
>>> >
>>> >   __cgo_f2fa82ea8f11_Cfunc_rd_kafka_topic_conf_new in 03.o
>>> >
>>> >   __cgo_f2fa82ea8f11_Cfunc_rd_kafka_topic_conf_set in 03.o
>>> >
>>> >   __cgo_f2fa82ea8f11_Cfunc__c_rdkafka_topic_partition_list_entry in
>>> > 04.o
>>> >
>>> >   __cgo_f2fa82ea8f11_Cfunc_rd_kafka_assign in 04.o
>>> >
>>> >   __cgo_f2fa82ea8f11_Cfunc_rd_kafka_assignment in 04.o
>>> >
>>> >   ...
>>> >
>>> >   "_main", referenced from:
>>> >
>>> >  implicit entry/start for main executable
>>> >
>>> >  (maybe you meant: 
>>> __cgo_f2fa82ea8f11_Cfunc_rd_kafka_queue_get_main)
>>> >
>>> > ld: symbol(s) not found for architecture x86_64
>>> >
>>> > clang: error: linker command failed with exit code 1 (use -v to see
>>> > invocation)
>>> >
>>> >
>>> > It points to /var/folders which I am given to understand is a temp 
>>> location
>>> > in mac.
>>> >
>>> >
>>> > Any ideas on how to fix it?
>>>
>>> When cross-compiling a Go program that uses cgo, you need to be using
>>> a C cross-compiler.  It looks like you are using the native Darwin C
>>> compiler.  You need a cross-compiler from Darwin to GNU/Linux.
>>>
>>> Ian
>>>
>>
> Native compilation is much easier.
> If you have Docker installed, https://github.com/karalabe/xgo can help a 
> lot!
>

-- 
*::DISCLAIMER::




The contents of this e-mail and any attachments are confidential and 
intended for the named recipient(s) only.E-mail transmission is not 
guaranteed to be secure or error-free as information could be intercepted, 
corrupted,lost, destroyed, arrive late or incomplete, or may contain 
viruses in transmission. The e mail and its contents(with or without 
referred errors) shall therefore not attach any liability on the originator 
or redBus.com. Views or opinions, if any, presented in this email are 
solely those of the author and may not necessarily reflect the views or 
opinions of redBus.com. Any form of reproduction, dissemination, copying, 
disclosure, modification,distribution and / or publication of this message 
without the prior written consent of authorized representative of redbus. 
<http://redbus.in/>com is strictly prohibited. If you have received this 
email in error please delete it and notify the sender immediately.Before 
opening any email and/or attachments, please check them for viruses and 
other defects.*

-- 
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] Create non-variadic functions without existingType using reflection

2021-12-20 Thread &#x27;Ankit Gupta' via golang-nuts
Hey Folks, 

If I have argument type for a function: is it possible to create a function 
with those? 
*Note:* 
- we don't have reflect type for the function to be created so makeFunc can 
not be simply used.
- function inputTypes can differ so variadic can not be leveraged here.
- number of inputs can differ.

eg:
*input arg types*: TypeA, TypeB
*expected output:* func(TypeA, TypeB)

-
Also, if it makes thing easier: Base problem which I have is:

*input:* func(inputTypes) (outputTypes)
*expectedOutput:* func(inputTypes)

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/62f1ad7c-5b9b-401f-90d4-8d25fbd5fca7n%40googlegroups.com.