[go-nuts] Re: Compare values in a for loop that ranges over string array of array

2018-03-05 Thread Ignacio Gómez
Hi, Ashish.

If you have a map[string]int (or int 64, float 64, etc.) "m", doing

m[key] += value


is equivalent to this:

m[key] = m[key] + value.


Thus, on each iteration we sum the value at dataarray[j][1] (which you 
stored at sumFloat) to the current value of sums[dataarray[j][0]] (on first 
iteration, it just gets initialized to the zero value, in this case 0.0) in 
order to sum values among the same letter, which are used as keys for the 
map. So, in short, yes, that's accurate. Take a look at this to get some 
more info on maps: https://blog.golang.org/go-maps-in-action

El lunes, 5 de marzo de 2018, 18:35:11 (UTC-3), Ashish Timilsina escribió:
>
> Hi Ignacio,
>
> This is excellent, works perfectly. Thank you so much. 
> I will try to do my research but just out of curiosity and make sure I 
> understand the code, what does this line do? I also don't have proper 
> understanding of golang maps 
> sums[dataarray[j][0]] += sumFloat
>
>
> So 'sum' map is taking the first index in dataarray as key, summing the 
> second index and assigning it as the value to the key. As it is looping 
> through the array, if it sees that the key is the same, it automatically 
> sums it up? Is that accurate?
>

-- 
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: Compare values in a for loop that ranges over string array of array

2018-03-05 Thread Ignacio Gómez
You can use a map to keep track of a letters sum. Here's your example 
slightly modified (it uses float64 as you were using 
that): https://play.golang.org/p/98L9fDXSN_A

El lunes, 5 de marzo de 2018, 15:28:54 (UTC-3), Ashish Timilsina escribió:
>
> Hi,
>
> I have an array of array string ([][]string{}). I am looping through them 
> and trying to sum the second value of the arrays based on the first value. 
> For example: 
>  a := []string{"a", "1"}
>  a1 := []string{"a", "2"}
>  a2 := []string{"a", "3"}
>  b := []string{"b", "4"}
>  b1 := []string{"b", "1"}
>
> Sum all the 'a' values and 'b' values. 
> Here's the sample code: 
> package main
>
>
> import (
>  "fmt"
>  "log"
>  "strconv"
> )
>
>
> func main() {
>
>
>  a := []string{"a", "1"}
>  a1 := []string{"a", "2"}
>  a2 := []string{"a", "3"}
>  b := []string{"b", "4"}
>  b1 := []string{"b", "2"}
>  b2 := []string{"b", "1"}
>  dataarray := [][]string{}
>  dataarray = append(dataarray, a, a1, a2, b, b1, b2)
>  var totalSum float64
>  for j, _ := range dataarray {
>  sumFloat, err := strconv.ParseFloat(dataarray[j][1], 64)
>  if err != nil {
>  log.Fatal(err)
>  }
>  totalSum += sumFloat
>
>
>  }
>  fmt.Println(totalSum)
> }
>
> Right now, its summing all the values. The result I want is:
> a: 6
> b: 7
>
> Let me know if there's a way to do this. Here's the link to go playground: 
> https://play.golang.org/p/KL8GQ7LPJNi
>
>

-- 
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] where is an online version of older versions like 1.8 1.6 golang pkg doc ?

2018-01-19 Thread Ignacio Gómez
I think this old discussion about dropping support for ARMv5 
(https://github.com/golang/go/issues/17082) makes a point for having docs 
for older Go versions. It's not always a matter of laziness, sometimes 
there's no choice. Yeah, the poor lad inheriting a legacy system may and 
probably will have to generate docs locally, and it takes work and time to 
maintain docs archives, but if someone is willing to do it, I think there 
are good cases for it.

El viernes, 19 de enero de 2018, 20:54:34 (UTC-3), Florin Pățan escribió:
>
> I think this would further encourage people to be lazy and not upgrade to 
> newer Go versions.
>
> This always leads to problems, especially when things like tooling is 
> involved, and especially
> when the debugger side of Go improved so much between versions.
>
> I always liked the fact that Go only shows the docs for the current 
> version, forcing everyone
> else to either upgrade or run their own godoc locally for their Go version.
>
> As such, I think it would be a mistake to support anything else but the 
> current version (and tip, ofc).
>
> On Friday, January 19, 2018 at 6:07:49 PM UTC, Ian Lance Taylor wrote:
>>
>> On Fri, Jan 19, 2018 at 9:49 AM, derek  wrote: 
>> > On Thu, Jan 18, 2018 at 7:39 PM, Ian Lance Taylor  
>> wrote: 
>> >>> Like for Nodejs, and Python and many other language has permanent 
>> >>> archived docs for olders versions: 
>> >>> 
>> >>> https://nodejs.org/docs/v8.4.0/api/http2.html   is permanent URL for 
>> >>> nodejs v8.4.0 
>> >>> 
>> >>> https://nodejs.org/api/http2.htmlis always pointing to latest 
>> version 
>> >> 
>> >> We don't have that.  You can build it yourself easily enough: clone 
>> >> the git repo, check out 1.6 and run godoc with the -goroot option 
>> >> pointing at that directory. 
>> > 
>> > I know how to set up a godoc site locally, but the problem then is not 
>> > Google searchable... harder to share via a single link about a 
>> > historic library function design... 
>> > So I prefer if anyone knows a 3rd party godoc service online for a 
>> > longer period? 
>> > 
>> > And question to the ones behind the official golang.org/doc/..  , Is 
>> > there a reason intentionally not doing so?  for the archived docs for 
>> > older versions? 
>> > It's unbelievable not providing any information online about historic 
>> > versions, all because relatively young age? 
>> > 
>> > I know the Go designer's goal for 1.x at least is to be backward 
>> > compatible for all historic versions down to 1.0? 
>> > So when every newer 1.x version release, it's kind of calling everyone 
>> > to upgrade, 
>> > But if suppose there's a Go 1.x version market share research, I don't 
>> > believe the current latest 1.9 has taken all 100% of share?  The Go1.8 
>> > may still have 20% and Go1.6 10% ? 
>> > 
>> > I don't have the exact numbers, but The archived docs for an older 
>> > version still must have some value; 
>> > 
>> > In the longer future, when Go 2 released,   it can't take 100% market 
>> > share at day1, right?  it might take some years to convince every Go 
>> > user to upgrade, Would you have an archived godoc for the last 1.x ? 
>>
>> Perhaps.  It's certainly worth considering. 
>>
>> Maintaining online docs for older Go versions sounds like a fine idea 
>> to me.  It also sounds like work that somebody has to do. 
>>
>>
>> > To any 3rd party Go related site owners,  would you like to setup such 
>> > archives service? 
>>
>> Sounds like a good approach.  Or I'm also open to someone writing the 
>> necessary code for golang.org. 
>>
>> 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.


[go-nuts] Mosquitto auth plugin

2018-01-10 Thread Ignacio Gómez
Hi, guys.

I've recently written an authentication/authorization plugin for mosquitto, 
a well known open-source MQTT broker, using cgo. The basic idea was to 
export some Go functions to mosquitto's C plugin interface, and write all 
the logic in Go. It implements a bunch of backends available, and also 
offers the possibility to add your own using the "plugin" package.

I was hoping someone could find it useful, and also to receive ideas on any 
missing backend that you'd like to see implemented. Also, I'd love some 
criticism/feedback, as this is my first "real" open-source project. Of 
course, there are some "issues" I'm aware of, such as a lot of exported 
thing that really shouldn't be (though they are not exposed to the C code, 
so it isn't thaaat troublesome) and that I'll refactor soon. But if you see 
anything that raises a warning, seems odd or is plain wrong, please give me 
a heads up: I'll very much appreciate it.

Here's the repo for the project: 
https://github.com/iegomez/mosquitto-go-auth.

Cheers!

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