[go-nuts] Re: database / sql transaction error handling questions

2018-01-10 Thread Tamás Gulácsi
2018. január 10., szerda 8:05:18 UTC+1 időpontban evan a következőt írta:
>
> after reading https://golang.org/pkg/database/sql/, i'm still not quite 
> sure how to do error handling with respect to tx (transaction) operations. 
> coming from a java/c# background, where once an exception is raised, i know 
> what to do in the "catch" and "finally" blocks, i'm not as sure with go 
> errors, so i thought i'd askfor help being a go newbie.
>
> supposing i'm doing something like this in postgresql within a go func:
>
> tx, err := db.Begin()
> //Question 1: what happens if err != nil in the above statement? will tx 
> be nil or will i get a non-nil tx that is just unuseable? if the latter, 
> would it ever make sense for me to just wait until after the tx.Commit() 
> statement and just do error checking and handling once? i know that if i 
> get an error with db.Begin(), i really should just forget about trying to 
> execute the remaining code but i was just curious what other options -- if 
> any -- might make sense.
>

Generally, you can't use tx if err != nil - so here tx is unusable. This 
should happen only if the DB is on fire.


> rows, err := tx.Query(...)
>
> result, err := tx.Exec(...)
>
> err = tx.Commit()
>
>
> additional questions:
>
> (2)  kinda related to question 1 above: do i have to check for errors 
> after each statement above, or is it the case that once an error has 
> occurred, the tx object is unuseable because it "remembers" the error(s) 
> that have occurred?
>
>
Yes, you have to check the error - it has nothing to do with tx, that still 
can be valid!
For example a tx.Query returns errorr if the query has syntax error, 
tx.Exec if you've tried to validate a unique index, and so on.

If tx.Commit fails, that means you've lost contant with your DB or your DB 
is on fire.

(3)  when an error occurs, is the transaction automatically rollback'ed or 
> do i have to do this explicitly?
>

No automatic rolling back. You have to decide what to do in case of error.
 

>
> (4) if tx.Commit() fails, does the "go" runtime take care of necessary 
> resource cleanups / givebacks, etc? any potential gotchas i need to be 
> aware of?
>

No, you have to Rollback, and ALWAYS call Close on the Rows of (successful) 
Query!
 

>
> thanks for any help! 
>

-- 
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] New identifiers and selectors in short variable declarations

2018-01-10 Thread Jan Mercl
On Tue, Jan 9, 2018 at 10:08 PM Jim Bishopp  wrote:

> Has there ever been a discussion about allowing new identifiers and
selectors in short variable declarations?

FTR: There are other things that are legal on the LHS of an assignment, but
not in the short variable declaration, like x[i], *x, *f().



-- 

-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] Re: database / sql transaction error handling questions

2018-01-10 Thread evan
thanks for the detailed response. 


-- 
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] http.FileServer: how to serve static files requested from different domains?

2018-01-10 Thread Ayan George


On 01/09/2018 02:34 PM, Andy Balholm wrote:
> Try:
> 
> http.Handle(“domain1.com/assets/", http.StripPrefix("/", 
> http.FileServer(http.Dir(*webrootdomain1
> http.Handle(“domain2.com/assets/", http.StripPrefix("/", 
> http.FileServer(http.Dir(*webrootdomain2
> 

Wow! Reading is fundamental. I didn't know ServeMux handled the domain
name. I wish I could take back my previous email now. :)

-ayan

-- 
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] error: incompatible types in binary expression

2018-01-10 Thread pradam
Hi Gophers,
I am a newbie to golang, I have been working on this snippet for a while
whenever i run this snippet I am getting above error message. I am actual
searched on google but i didn't get any proper solution with an
explanation.help me with it.

package main


import (
  "fmt"
)


func pow(x int64) string {
if v := 100; v < x {
return "less than 100"
}
return "not less than 100"
}

func main(){

  fmt.Println(pow(10))
}

./if-else.go:16:17: error: incompatible types in binary expression
  if v := 100; v < x {

thank you,

-- 
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] error: incompatible types in binary expression

2018-01-10 Thread Jan Mercl
On Wed, Jan 10, 2018 at 2:29 PM pradam  wrote:

> I am a newbie to golang, I have been working on this snippet for a while
whenever i run this snippet I am getting above error message.
> I am actual searched on google but i didn't get any proper solution with
an explanation.help me with it.

'v := 100' declares 'v' with type 'int', but 'x' is 'int64'. Try 'v :=
int64(100)'.

More can be found in the language specification. Particularly, relational
operators work on equal types only and untyped constants have default types
when used in short variable declarations.




-- 

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


Re: [go-nuts] Using database/sql in a web application

2018-01-10 Thread Manlio Perillo

Il giorno venerdì 5 gennaio 2018 18:09:40 UTC+1, Chris Hopkins ha scritto:
>
> Why not use an interface?
> type TableSaver func (db *DB)
> or 
> type TableSaver func (tx *Tx) // depending on your needs
>
>
> Allowing you to:
> func (t *Table) SaveTable (...) {}
>
>
> Which in your example if you wanted use a different SaveTable  
> implementation for OtherTable you could. Otherwise it would just inherit it 
> from Table.
> Or am I missing something here?
>
>
Because the two TableSaver function code is (literally) the same, the only 
difference is the input variable.
Isn't it better for the database connection to be an interface?

> [...]


Thanks
Manlio Perillo 

-- 
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] [ANN] Graph database

2018-01-10 Thread Luis Furquim
Hello Gophers,

Just announcing my graph database called Linsang. It operates in embedded
way. No server/daemon. It has a main package which just defines the basis.
But the linsangmysql subpackage implementing the operations has most of the
code (and so the documentation). I divided this way to allow anyone not
just to create new operations but, also, replace all of them. The
operations defined use a MySQL database as the backend store. Anyone can
create new operations using others backend stores. Combining operations
from multiple backend stores is ok.

This the first realease and the code is alpha. So, 'do not use in
production' is the obvious advise and 'opinions, tests, criticism,
suggestions and contributions' the obvious request! ;)

Thank for your attention!
Luis Otavio de Colla Furquim

-- 
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] Map with multiple "indexes"

2018-01-10 Thread lee
I'm trying to come up with a data structure that I can search for map 
values quickly without having to iterate an entire (and large) map to find 
a value.

Essentially I have a map that contains lots of data and the key is the 
primary identifier where most of the lookups go to.  This is very quick to 
lookup and/or fail.  I also have some very frequent queries to search for 
values inside the map.  This is slow at the moment as I have to iterate the 
entire map to look for a value.

What I am trying to do is to create a "shadow" map that has a reference to 
the pointer.  This way when the original is deleted from the primary map it 
should/will fall off from the shadow map.  However as you cannot set a 
struct to nil this doesn't seem to work.

https://play.golang.org/p/xUP-LEruwVX

Any ideas on how I could approach this?

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] Map with multiple "indexes"

2018-01-10 Thread Burak Serdar
On Wed, Jan 10, 2018 at 7:57 AM,   wrote:
> I'm trying to come up with a data structure that I can search for map values
> quickly without having to iterate an entire (and large) map to find a value.
>
> Essentially I have a map that contains lots of data and the key is the
> primary identifier where most of the lookups go to.  This is very quick to
> lookup and/or fail.  I also have some very frequent queries to search for
> values inside the map.  This is slow at the moment as I have to iterate the
> entire map to look for a value.
>
> What I am trying to do is to create a "shadow" map that has a reference to
> the pointer.  This way when the original is deleted from the primary map it
> should/will fall off from the shadow map.  However as you cannot set a
> struct to nil this doesn't seem to work.

One way of doing this could be:

type SomeStruct struct {
   Field1 string
   Field2 string
   ...
}

type SomeStructMap struct {
f1Map map[string]*SomeStruct
f2Map map[string]*SomeStruct
}

func (m SomeStructMap) GetByF1(s string) (*SomeStruct,bool) {return m.f1Map[s]}
func (m SomeStructMap( GetByF2(s string) (*SomeStruct,bool) {return m.f2Map[s]}
func (m SomeStructMap) Set(x *SomeStruct) {
  m.f1Map[x.Field1]=x
  m.f2Map[x.Field2]=x
}

Then use instances of SomeStructMap to store and lookup data.

>
> https://play.golang.org/p/xUP-LEruwVX
>
> Any ideas on how I could approach this?
>
> 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.

-- 
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] Map with multiple "indexes"

2018-01-10 Thread lee
Of course!  Thank you!

I mocked up a full working example 
here: https://play.golang.org/p/OUtbbAbbUF1

Any idea though how I would keep deletions in sync though?

On Wednesday, January 10, 2018 at 3:24:37 PM UTC, Burak Serdar wrote:
>
> On Wed, Jan 10, 2018 at 7:57 AM,  > 
> wrote: 
> > I'm trying to come up with a data structure that I can search for map 
> values 
> > quickly without having to iterate an entire (and large) map to find a 
> value. 
> > 
> > Essentially I have a map that contains lots of data and the key is the 
> > primary identifier where most of the lookups go to.  This is very quick 
> to 
> > lookup and/or fail.  I also have some very frequent queries to search 
> for 
> > values inside the map.  This is slow at the moment as I have to iterate 
> the 
> > entire map to look for a value. 
> > 
> > What I am trying to do is to create a "shadow" map that has a reference 
> to 
> > the pointer.  This way when the original is deleted from the primary map 
> it 
> > should/will fall off from the shadow map.  However as you cannot set a 
> > struct to nil this doesn't seem to work. 
>
> One way of doing this could be: 
>
> type SomeStruct struct { 
>Field1 string 
>Field2 string 
>... 
> } 
>
> type SomeStructMap struct { 
> f1Map map[string]*SomeStruct 
> f2Map map[string]*SomeStruct 
> } 
>
> func (m SomeStructMap) GetByF1(s string) (*SomeStruct,bool) {return 
> m.f1Map[s]} 
> func (m SomeStructMap( GetByF2(s string) (*SomeStruct,bool) {return 
> m.f2Map[s]} 
> func (m SomeStructMap) Set(x *SomeStruct) { 
>   m.f1Map[x.Field1]=x 
>   m.f2Map[x.Field2]=x 
> } 
>
> Then use instances of SomeStructMap to store and lookup data. 
>
> > 
> > https://play.golang.org/p/xUP-LEruwVX 
> > 
> > Any ideas on how I could approach this? 
> > 
> > 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...@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] Map with multiple "indexes"

2018-01-10 Thread Burak Serdar
On Wed, Jan 10, 2018 at 8:30 AM,   wrote:
> Of course!  Thank you!
>
> I mocked up a full working example here:
> https://play.golang.org/p/OUtbbAbbUF1
>
> Any idea though how I would keep deletions in sync though?


func (m SomeStructMap) DeleteByF1(s string) {
  if v, ok:=m.f1Map[s]; ok {
delete(m.f1Map,s)
delete(m.f2Map,v.Field2)
  }
}

>
> On Wednesday, January 10, 2018 at 3:24:37 PM UTC, Burak Serdar wrote:
>>
>> On Wed, Jan 10, 2018 at 7:57 AM,   wrote:
>> > I'm trying to come up with a data structure that I can search for map
>> > values
>> > quickly without having to iterate an entire (and large) map to find a
>> > value.
>> >
>> > Essentially I have a map that contains lots of data and the key is the
>> > primary identifier where most of the lookups go to.  This is very quick
>> > to
>> > lookup and/or fail.  I also have some very frequent queries to search
>> > for
>> > values inside the map.  This is slow at the moment as I have to iterate
>> > the
>> > entire map to look for a value.
>> >
>> > What I am trying to do is to create a "shadow" map that has a reference
>> > to
>> > the pointer.  This way when the original is deleted from the primary map
>> > it
>> > should/will fall off from the shadow map.  However as you cannot set a
>> > struct to nil this doesn't seem to work.
>>
>> One way of doing this could be:
>>
>> type SomeStruct struct {
>>Field1 string
>>Field2 string
>>...
>> }
>>
>> type SomeStructMap struct {
>> f1Map map[string]*SomeStruct
>> f2Map map[string]*SomeStruct
>> }
>>
>> func (m SomeStructMap) GetByF1(s string) (*SomeStruct,bool) {return
>> m.f1Map[s]}
>> func (m SomeStructMap( GetByF2(s string) (*SomeStruct,bool) {return
>> m.f2Map[s]}
>> func (m SomeStructMap) Set(x *SomeStruct) {
>>   m.f1Map[x.Field1]=x
>>   m.f2Map[x.Field2]=x
>> }
>>
>> Then use instances of SomeStructMap to store and lookup data.
>>
>> >
>> > https://play.golang.org/p/xUP-LEruwVX
>> >
>> > Any ideas on how I could approach this?
>> >
>> > 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...@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.


Re: [go-nuts] [ANN] Graph database

2018-01-10 Thread Tharaneedharan Vilwanathan
Hi,

Did you forget to provide the link?

Thanks
dharani


On Wed, Jan 10, 2018 at 6:36 AM, Luis Furquim  wrote:

> Hello Gophers,
>
> Just announcing my graph database called Linsang. It operates in embedded
> way. No server/daemon. It has a main package which just defines the basis.
> But the linsangmysql subpackage implementing the operations has most of the
> code (and so the documentation). I divided this way to allow anyone not
> just to create new operations but, also, replace all of them. The
> operations defined use a MySQL database as the backend store. Anyone can
> create new operations using others backend stores. Combining operations
> from multiple backend stores is ok.
>
> This the first realease and the code is alpha. So, 'do not use in
> production' is the obvious advise and 'opinions, tests, criticism,
> suggestions and contributions' the obvious request! ;)
>
> Thank for your attention!
> Luis Otavio de Colla Furquim
>
> --
> 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] [ANN] Graph database

2018-01-10 Thread Luis Furquim
Hi,

YES, sorry! I forgot! :(
github.com/luisfurquim/linsang

Thanks!
Luis Otavio de Colla Furquim



Em qua, 10 de jan de 2018 às 16:13, Tharaneedharan Vilwanathan <
vdhar...@gmail.com> escreveu:

> Hi,
>
> Did you forget to provide the link?
>
> Thanks
> dharani
>
>
> On Wed, Jan 10, 2018 at 6:36 AM, Luis Furquim 
> wrote:
>
>> Hello Gophers,
>>
>> Just announcing my graph database called Linsang. It operates in embedded
>> way. No server/daemon. It has a main package which just defines the basis.
>> But the linsangmysql subpackage implementing the operations has most of the
>> code (and so the documentation). I divided this way to allow anyone not
>> just to create new operations but, also, replace all of them. The
>> operations defined use a MySQL database as the backend store. Anyone can
>> create new operations using others backend stores. Combining operations
>> from multiple backend stores is ok.
>>
>> This the first realease and the code is alpha. So, 'do not use in
>> production' is the obvious advise and 'opinions, tests, criticism,
>> suggestions and contributions' the obvious request! ;)
>>
>> Thank for your attention!
>> Luis Otavio de Colla Furquim
>>
>> --
>> 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: Connecting to Google Cloud Storage

2018-01-10 Thread arunnediyasala


> Hi all,
>
I want to connect my digi XBee to google cloud is there is any way to do 
that please help me on this .DIGI XBee gateway is by default connecting to 
the digi data cloud so that all the data is going to the digi cloud .I want 
to connect to google cloud  

-- 
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] Is there an equivalent of telldir in go. If not what are the alternatives?

2018-01-10 Thread Amandeep Gautam
Is there a equivalent of telldir in golang which can page reading of a 
directory.
Just using filepath.walk would be inefficient for large file systems.

>From one of the answers to this question
https://stackoverflow.com/questions/39583522/how-do-i-use-seekdir-telldir-in-golang

it looks like there is nothing for this use case, which brings me to my 
next question: Any ideas about how to go about dealing such use case.

-- 
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] Is there an equivalent of telldir in go. If not what are the alternatives?

2018-01-10 Thread Ian Lance Taylor
On Wed, Jan 10, 2018 at 3:31 PM, Amandeep Gautam
 wrote:
>
> Is there a equivalent of telldir in golang which can page reading of a
> directory.
> Just using filepath.walk would be inefficient for large file systems.

There is no telldir, but you can simply call the `Readdir` (or
`Readdirnames`) method in a loop, each time passing in the number of
files you want to see.


> From one of the answers to this question
> https://stackoverflow.com/questions/39583522/how-do-i-use-seekdir-telldir-in-golang
>
> it looks like there is nothing for this use case, which brings me to my next
> question: Any ideas about how to go about dealing such use case.

To be clear, that question, and maybe yours too, is about reading an
entire directory tree, not a single directory.  telldir won't help you
there either.  seekdir/telldir, like the `Readdir` loop, is only
helpful when reading a single directory.


And that said, why is filepath.Walk inefficient for a large file
system?  It should do fine.

What is the real problem?

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] dependency repo internal mirroring/hosting

2018-01-10 Thread Sangjin Lee
What do folks do in terms of managing/vetting dependencies and also hosting 
them internally? In other language ecosystems, there are tools such as 
Nexus or Artifactory that work as caching mirrors for binary dependencies. 
That way, a company or a team can have a stronger control/governance on 
dependencies they use. I'm curious if there is a mature solution for Go.

One strawman idea is to set up an internal git (or github) repo that acts 
as a repository of dependencies, and have our dep toml point to that 
internal repo for each and every dependency. But it is not quite an 
automated solution to the problem. I'm curious what others are doing for 
this.

-- 
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] Micali 'algorand' in go?

2018-01-10 Thread Pat Farrell
Anyone working on this? Would seem to be a natural thing to implement in 
go. He has published papers talking about a C++ implementation, but I've 
done more than enough C++ in my lifetime.

If there is no existing effort, is there any interest in joining me in one?

-- 
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] Micali 'algorand' in go?

2018-01-10 Thread Michael Jones
To save others the Google Search:

https://people.csail.mit.edu/nickolai/papers/gilad-algorand-eprint.pdf

On Wed, Jan 10, 2018 at 4:59 PM, Pat Farrell  wrote:

> Anyone working on this? Would seem to be a natural thing to implement in
> go. He has published papers talking about a C++ implementation, but I've
> done more than enough C++ in my lifetime.
>
> If there is no existing effort, is there any interest in joining me in one?
>
> --
> 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.
>



-- 
Michael T. Jones
michael.jo...@gmail.com

-- 
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] Is there an equivalent of telldir in go. If not what are the alternatives?

2018-01-10 Thread Michael Jones
...also, i have a parallel file walker that's 10x+ faster.

https://github.com/MichaelTJones

On Wed, Jan 10, 2018 at 4:07 PM, Ian Lance Taylor  wrote:

> On Wed, Jan 10, 2018 at 3:31 PM, Amandeep Gautam
>  wrote:
> >
> > Is there a equivalent of telldir in golang which can page reading of a
> > directory.
> > Just using filepath.walk would be inefficient for large file systems.
>
> There is no telldir, but you can simply call the `Readdir` (or
> `Readdirnames`) method in a loop, each time passing in the number of
> files you want to see.
>
>
> > From one of the answers to this question
> > https://stackoverflow.com/questions/39583522/how-do-i-
> use-seekdir-telldir-in-golang
> >
> > it looks like there is nothing for this use case, which brings me to my
> next
> > question: Any ideas about how to go about dealing such use case.
>
> To be clear, that question, and maybe yours too, is about reading an
> entire directory tree, not a single directory.  telldir won't help you
> there either.  seekdir/telldir, like the `Readdir` loop, is only
> helpful when reading a single directory.
>
>
> And that said, why is filepath.Walk inefficient for a large file
> system?  It should do fine.
>
> What is the real problem?
>
> 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.
>



-- 
Michael T. Jones
michael.jo...@gmail.com

-- 
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] Is there an equivalent of telldir in go. If not what are the alternatives?

2018-01-10 Thread Bakul Shah
On Wed, 10 Jan 2018 15:31:26 -0800 Amandeep Gautam  
wrote:
Amandeep Gautam writes:
> 
> Is there a equivalent of telldir in golang which can page reading of a 
> directory.
> Just using filepath.walk would be inefficient for large file systems.
> 
> >From one of the answers to this question
> https://stackoverflow.com/questions/39583522/how-do-i-use-seekdir-telldir-in-
> golang
> 
> it looks like there is nothing for this use case, which brings me to my 
> next question: Any ideas about how to go about dealing such use case.

The only reason I can think of wanting this is where you ^C a
long running treewalker before it has finished and then on
restart you want it to continue from where it left off.
Useful when you are scanning a large filesystem in a
background process and want to be able to terminate the
scanner and restart.  [If you just want to be able to stop the
scanner but not terminate/restart, your solution can be
simpler.]

If this is your use case, read on.

If your current directory is N levels deep, you have to save
the state of N partial walks.  On exit, save this state and on
restart restore from this state.  One suggestion:

func TreeWalk(state []string, callbacks ...) []string

For a brand new walk, TreeWalk's state would be {path:0}.  If
terminated prematurely, returned value would be a slice of
partial walks. If the tree was completely walked, TreeWalk
returns nil.  For a restart, state would be the result of the
previous walk.  The saved state can be put in a file, one per
line:
path:pos
To terminate early you'd need a way to tell TreeWalk to save
state and give up. This can be via a signal handler that
stuffs a value in a channel or update an atomic variable or
something.

Another way is to replace callback functions for processing
dir/files with a channel and pass appropriate data for each
dir/file for concurrent processing but saving partial state
would get slightly trickier.

-- 
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] error: incompatible types in binary expression

2018-01-10 Thread pradam
Thank you, Jan Merci, it was very helpful.

On Wed, Jan 10, 2018 at 7:05 PM, Jan Mercl <0xj...@gmail.com> wrote:

> On Wed, Jan 10, 2018 at 2:29 PM pradam 
> wrote:
>
> > I am a newbie to golang, I have been working on this snippet for a while
> whenever i run this snippet I am getting above error message.
> > I am actual searched on google but i didn't get any proper solution with
> an explanation.help me with it.
>
> 'v := 100' declares 'v' with type 'int', but 'x' is 'int64'. Try 'v :=
> int64(100)'.
>
> More can be found in the language specification. Particularly, relational
> operators work on equal types only and untyped constants have default types
> when used in short variable declarations.
>
>
>
>
> --
>
> -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] interaction of defer and named returns is too subtle and non-local

2018-01-10 Thread 'Eric Johnson' via golang-nuts
I was looking at fixing an issue flagged by gometalinter, and realized I 
didn't understand the actual behavior of defer statements. Specifically, I 
was not handling the error return of a close operation.

I wrote a test program so I could understand the behavior, which led to 
these two function

package main

import "fmt"

func checkDefer(newVal int, val *int) {
fmt.Printf("current value is %v\n", *val)
*val = newVal
}

func main() {
fmt.Printf("variableOnUnnamedReturn value is %v, expected 30\n", 
variableOnUnnamedReturn(20, 25, 30))
fmt.Printf("variableOnNamedReturn value is %v, expected 45\n", 
variableOnNamedReturn(35, 40, 45))
}

func variableOnUnnamedReturn(start, test, def int) int {
retval := start
defer checkDefer(def, &retval)
retval = test
return retval
}

func variableOnNamedReturn(start, test, def int) (retval int) {
retval = start
defer checkDefer(def, &retval)
retval = test
return retval
}


The body of the two functions differs only by a single ":", and yet, the 
output of the Printf calls differs. This appears to be due to very subtle 
differences between how named and unnamed returns are handled in the 
context of defer statements.

I looked through the language spec, and did not see this clearly spelled 
out. It is not obvious to me, a relatively experience Go developer, that 
the "variableOnUnnamedReturn" function should return a 25 in the above use, 
but the "variableOnNamedReturn" function returns a 45 in the above use.

As near as I can tell, operationally, the "unnamed" return could be 
re-written in something like the following fashion (where addDeferredOps is 
a collector for deferred operations.):

retval := start
dos := addDeferredOps(func() { checkDefer(def, &retval)} )
retval = test
_retval1_ = retval
dos.performDeferredOps()
return _retval1_

Which makes it obvious that the call to checkDefer() won't change the 
return of the function. Whereas, the "named return" version effectively 
amounts to this:

retval := start
dos := addDeferredOps(func() { checkDefer(def, &retval)} )
retval = test
dos.performDeferredOps()
return retval

I read the language spec, and simply didn't see the description of the 
difference between these two behaviors. Seems mostly like a language bug, 
to me. Feels like the named and unnamed return cases should behave the 
same. I can see why they don't (expressions on the return line, instead of 
simple uses of the variables), but that doesn't make me happy about having 
to explain the difference to others on my team.

Eric.



-- 
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: Map with multiple "indexes"

2018-01-10 Thread lee
Perfect thank you!

On Wednesday, January 10, 2018 at 2:58:34 PM UTC, Lee Armstrong wrote:
>
> I'm trying to come up with a data structure that I can search for map 
> values quickly without having to iterate an entire (and large) map to find 
> a value.
>
> Essentially I have a map that contains lots of data and the key is the 
> primary identifier where most of the lookups go to.  This is very quick to 
> lookup and/or fail.  I also have some very frequent queries to search for 
> values inside the map.  This is slow at the moment as I have to iterate the 
> entire map to look for a value.
>
> What I am trying to do is to create a "shadow" map that has a reference to 
> the pointer.  This way when the original is deleted from the primary map it 
> should/will fall off from the shadow map.  However as you cannot set a 
> struct to nil this doesn't seem to work.
>
> https://play.golang.org/p/xUP-LEruwVX
>
> Any ideas on how I could approach this?
>
> 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] interaction of defer and named returns is too subtle and non-local

2018-01-10 Thread Dave Cheney
> The body of the two functions differs only by a single ":", and yet, the 
> output of the Printf calls differs.

This is not correct. The significant difference is one version has a named 
return value, the other does not. The named return value allows you to capture 
(by name) the return value and examine it after the function has completed, but 
before the execution of the caller has resumed. 

-- 
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] interaction of defer and named returns is too subtle and non-local

2018-01-10 Thread 'Axel Wagner' via golang-nuts
On Thu, Jan 11, 2018 at 8:10 AM, 'Eric Johnson' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> I was looking at fixing an issue flagged by gometalinter, and realized I
> didn't understand the actual behavior of defer statements. Specifically, I
> was not handling the error return of a close operation.
>
> I wrote a test program so I could understand the behavior, which led to
> these two function
>
> package main
>
> import "fmt"
>
> func checkDefer(newVal int, val *int) {
> fmt.Printf("current value is %v\n", *val)
> *val = newVal
> }
>
> func main() {
> fmt.Printf("variableOnUnnamedReturn value is %v, expected 30\n",
> variableOnUnnamedReturn(20, 25, 30))
> fmt.Printf("variableOnNamedReturn value is %v, expected 45\n",
> variableOnNamedReturn(35, 40, 45))
> }
>
> func variableOnUnnamedReturn(start, test, def int) int {
> retval := start
> defer checkDefer(def, &retval)
> retval = test
> return retval
> }
>
> func variableOnNamedReturn(start, test, def int) (retval int) {
> retval = start
> defer checkDefer(def, &retval)
> retval = test
> return retval
> }
>
>
> The body of the two functions differs only by a single ":", and yet, the
> output of the Printf calls differs. This appears to be due to very subtle
> differences between how named and unnamed returns are handled in the
> context of defer statements.
>

There are basically two reasons

to use named return values: 1) Documentation, 2) Do what you are doing here.
It is interesting, though, that you find it confusing. To me, it always
seemed kind of natural, that a defered function executes *after* the
return. If you accept that part, the behavior should be very clear, IMO.

I looked through the language spec, and did not see this clearly spelled
> out.
>

It's spelled out here , that
defered functions can modify named returns. Though you are right that it's
not explicitly spelled out whether they execute before, after or concurrent
with the return statement.


> It is not obvious to me, a relatively experience Go developer, that the 
> "variableOnUnnamedReturn"
> function should return a 25 in the above use, but the "variableOnNamedReturn"
> function returns a 45 in the above use.
>

> As near as I can tell, operationally, the "unnamed" return could be
> re-written in something like the following fashion (where addDeferredOps is
> a collector for deferred operations.):
>
> retval := start
> dos := addDeferredOps(func() { checkDefer(def, &retval)} )
> retval = test
> _retval1_ = retval
> dos.performDeferredOps()
> return _retval1_
>
> Which makes it obvious that the call to checkDefer() won't change the
> return of the function. Whereas, the "named return" version effectively
> amounts to this:
>
> retval := start
> dos := addDeferredOps(func() { checkDefer(def, &retval)} )
> retval = test
> dos.performDeferredOps()
> return retval
>
> I read the language spec, and simply didn't see the description of the
> difference between these two behaviors. Seems mostly like a language bug,
> to me. Feels like the named and unnamed return cases should behave the same.
>

I don't agree. Currently, the sequence of a return is

1. The expressions in the return statement are evaluated and stored as
return values (named or unnamed)
2. All defered functions are executed (potentially modifying the named
returns)
3. Control is returned

What you'd want amounts to

1. All defered functions are executed (potentially modifying the named
returns)
2. All expressions in the return statement are evaluated and stored as
return values
3. Control is returned

Not only do I not see how this would be simpler to explain - it also opens
up some other problems.
For example, when I use named returns and modify them, I usually do it in this
pattern . In the changed sequence of
events, this would return "closing failed", instead of "stuff failed". And
how would this  work? recover can
only work, after the returned expressions where evaluated; but the defer
executes before that.

The alternative would be, to somehow make return not actually return
values, but to have something like
1. The expressions in the return statement are evaluated as references
2. All defered functions are executed
3. The references from the return statement are dereferenced and the values
stored as return values
4. Control is returned
But for that to work, you'd need to only allow addressable expressions in
return (which would be bad) or you would need to somehow introduce a new,
weird way to describe the sequence of events. Either way, this doesn't seem
simpler to explain, yet again.


> I can see why they don't (expressions on the return line, instead of
> simple uses of the variables), but that doesn't make me happ