[go-nuts] How to render a single webpage without templates?

2017-03-08 Thread so . query
In my handler I want to return a single webpage.

But when using http.ServeFile, the images on the page aren't rendered.
https://golang.org/pkg/net/http/#ServeFile

And using http.FileServer, returns a handler that renders an entire 
directory (and children)
https://golang.org/pkg/net/http/#FileServer

How would I respond back with a single webpage and all its images, js and 
css?
Also the images, js and css are in different folders.





-- 
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] Deploying go https servers

2017-03-08 Thread Sankar P
I am looking more for a checklist of things to do, rather than a set of
tools.

2017-03-09 0:38 GMT+05:30 Shawn Milochik :

> That sounds a good use-case for Ansible to me. It's pretty easy to use and
> get started.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/sTsDhJLKTqU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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] sort.Slice arguments

2017-03-08 Thread Jérôme Champion
As itinerary and the reslicing operation use the same backing array, you 
could just offset your indexes:
https://play.golang.org/p/2ZzKST5J1g

I'm not sure if it's a good idea, could the sort.Slice implementation 
change in the future and make a regression?

Le mercredi 8 mars 2017 18:22:48 UTC+1, Ain a écrit :
>
>
> Another, OO-ish fix is to use method on custom type (
> https://play.golang.org/p/a5S5rNog5h):
>
> type itinerary []string
>
> func (t itinerary) sort() {
> sort.Slice(t, func(i, j int) bool {
> return t[i] < t[j]
> })
> }
>
> func main() {
> itinerary := itinerary{"Philadelphia", "Chicago", "Boston", "Austin"}
> itinerary[1:].sort()
> fmt.Println("My new itinerary is", itinerary)
> }
>
>
> ain
>
>
> On Wednesday, March 8, 2017 at 5:01:08 PM UTC+2, Val wrote:
>>
>> Sorry for not elaborating in the first place (I was trying to make the 
>> point very concise).
>>
>> This is the starting city :  Philadelphia
>>
>> This are the other cities :   Chicago, Boston, Austin
>>
>> The itinerary is the concatenation of starting city + other cities to be 
>> visited :   [Philadelphia, Chicago, Boston, Austin]
>>
>> In this contrived example the first city is fixed, because this is where 
>> I am now, wherever I decide to go next. That's why I decide to reorder all 
>> cities of my itinerary except the first one.
>>
>> This is what my naive code what trying to achieve (expected value of 
>> slice itinerary after partial sort) : [Philadelphia Austin Boston Chicago]
>>
>> This is what the code actually produces (value of slice itinerary after 
>> partial sort) : [Philadelphia Boston Chicago Austin] , which is why i say 
>> it is broken : the last 3 items don't end up in alphabetical order like I 
>> expected them to be.
>>
>> In a real program, there would be various legit reasons to sort only part 
>> of a slice, and the items would not always have a builtin type like string, 
>> rather custom struct types.
>>
>> @CBanning  Thanks, I had not thought of StringSlice!  But it's not 
>> applicable in my real programs, which deal with custom struct types (not 
>> strings).
>>
>> @David  Sorting the whole slice is not what I was trying to achieve, 
>> because I can't change my starting point.
>>
>> The bug in my code is that the two arguments I pass to sort.Slice are 
>> inconsistent : the portion to be sorted is a reslicing from itinerary, 
>> while the "less" closure indexes items of the whole itinerary.
>>
>> I brought up the "go vet" idea because I feel that whenever someone will 
>> do some reslicing directly in the first argument,
>> - either the result will be "broken" like mine,
>> - or the code in the less function will have to refer to the same 
>> (unnamed) resliced portion, which is imo convoluted : fix 1 
>>  or fix 2 
>>  .
>>
>> The most readable alternative I can think of while still using sort.Slice 
>> is to reslice in a new variable prior to sorting : fix 3 
>>  .
>>
>> Best regards
>> Val
>>
>> On Wednesday, March 8, 2017 at 3:25:48 PM UTC+1, David Peacock wrote:
>>>
>>> On Wed, Mar 8, 2017 at 8:32 AM, Valentin Deleplace  
>>> wrote:
>>>
 I did explain the expected result : "and I want to visit other cities 
 in alphabetical order"

>>>
>>> Jan is correct; the characterization of a problem hinges on accurately 
>>> describing what you expect and what happened instead.  Terms such as 
>>> "broken" and "does not work" are best avoided because others don't know 
>>> what your definitions are for these in the given context. :-)
>>>
>>> That being said, your alphabetical order is returned as you intend if 
>>> you adjust line 17 thusly:
>>>
>>> sort.Slice(itinerary[:], func(i, j int) bool {
>>>
>>> Cheers,
>>> David
>>>  
>>>

 Le 8 mars 2017 2:16 PM, "Jan Mercl" <0xj...@gmail.com> a écrit :

> On Wed, Mar 8, 2017 at 2:10 PM Val  wrote:
>
> > What do you think?
>
> You should explain what you've expected to get instead of what you've 
> got. Without that, I for one, cannot figure out what you see as broken 
> and 
> I have no idea why do you think it's not a good idea to sort a slice of a 
> slice. After all, it's just a slice as any other.
>
> -- 
>
> -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...@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 

[go-nuts] Re: escape analysis improvements?

2017-03-08 Thread keith . randall
Yes, this is a limitation of the current escape analysis.  It doesn't 
realize that the proto.Buffer can be stack allocated.
I suspect this is because b.Marshal is recursive, and escape analysis gives 
up on recursive things.

On Tuesday, March 7, 2017 at 8:22:42 PM UTC-8, apo...@google.com wrote:
>
> I'm guessing this is related to the same related questions about 
> "bytes.Buffer" and escape analysis.
>
> The golang protobuf package (https://github.com/golang/protobuf) has a 
> "proto.Buffer" type (
> https://github.com/golang/protobuf/blob/master/proto/lib.go#L309).
>
> The following program always heap allocates it:
>
> "
>
> package trial
>
> import (
> "log"
>
> "github.com/gogo/protobuf/proto"
>
> "google.golang.org/trial/codec_perf" // irrelevant protobuf code 
> generated by protoc compiler
> )
>
> func main() {
> // protobuf struct here is irrelevant, any valid argument will cause 
> the behavior
> p := _perf.Buffer{}
>
> // b gets heap allocated
> b := {}
>
> b.SetBuf(make([]byte, proto.Size(p)))
>
> if err := b.Marshal(p); err != nil {
> log.Fatal(err)
> }
> }
>
> "
>
>
> compiling with: 'go build -gcflags "-m=1"'
>
>
> shows at the bottom of the log:
>
>
> "
>
> # google.golang.org/trial
> ./main.go:17: inlining call to (*proto.Buffer).SetBuf
> ./main.go:17: make([]byte, proto.Size(p)) escapes to heap
> ./main.go:17: p escapes to heap
> ./main.go:12: _perf.Buffer literal escapes to heap
> ./main.go:15:  literal escapes to heap
> ./main.go:19: p escapes to heap
> ./main.go:20: err escapes to heap
> ./main.go:20: main ... argument does not escape
>
> "
>
>
> FYI output of "go version":
>
> 'go version devel +4cce27a3fa Sat Jan 21 03:20:55 2017 + linux/amd64'
>
>
>
> This might just be a golang/protobuf issue, but it also seems very similar to 
> https://github.com/golang/go/issues/7661.
>
>
>
> Wondering is this just due to escape analysis missing the opportunity? 
> Possibly heap allocs like this will go away in a future version?
>
>

-- 
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] Sample code with races needed for presentation

2017-03-08 Thread Ian Lance Taylor
On Wed, Mar 8, 2017 at 2:51 PM, Haddock  wrote:
>
> I'm working on a comparison between concurency in Go and on the JVM. For
> that reason I would like to show some Go code that has problem with
> incorrect synchronization and will cause race conditions or deadlocks. Ich
> want to demonstrate how they are partially caught at compile time or at
> runtime using the runtime analysis tool for that. This would be an
> eye-opener, because that does not exist on the JVM (except for some very
> expensive runtime analysis tools).
>
> I can write a small Go programm, but I'm not that proficient in Go to
> construct that kind of sample code myself in reasonable time. So that's why
> I wrote this post.

You may want to look at the collection of tests in
runtime/race/testdata.  Those are programs that will cause the race
detector to report errors if run with -race.

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] Sample code with races needed for presentation

2017-03-08 Thread Haddock
Hello,

I'm working on a comparison between concurency in Go and on the JVM. For 
that reason I would like to show some Go code that has problem with 
incorrect synchronization and will cause race conditions or deadlocks. Ich 
want to demonstrate how they are partially caught at compile time or at 
runtime using the runtime analysis tool for that. This would be an 
eye-opener, because that does not exist on the JVM (except for some very 
expensive runtime analysis tools).  

I can write a small Go programm, but I'm not that proficient in Go to 
construct that kind of sample code myself in reasonable time. So that's why 
I wrote this post.

Thanks in advance, Haddock

-- 
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: gwenn/gosqlite, go1.8, runtime error: cgo argument has Go pointer to Go pointer

2017-03-08 Thread Basile Starynkevitch


On Wednesday, March 8, 2017 at 9:40:05 PM UTC+1, Ian Lance Taylor wrote:
>
> On Wed, Mar 8, 2017 at 11:34 AM, Basile Starynkevitch 
>  wrote: 
> > 
> > On Wednesday, March 8, 2017 at 8:24:26 PM UTC+1, Ian Lance Taylor wrote: 
> >> 
> >> On Wed, Mar 8, 2017 at 7:54 AM, Basile Starynkevitch 
> >>  wrote: 
> >> I don't have any particular recommendations but I believe that 
> >> github.com/mattn/go-sqlite3 works correctly with cgo.  I know that 
> >> because I sent in patches myself 
> >> 
> >> (
> https://github.com/mattn/go-sqlite3/commit/b76c61051faaf0baf3215e6f811003d98639b702,
>  
>
> >> 
> >> 
> https://github.com/mattn/go-sqlite3/commit/8c66b9cf5ed003dff18db01a55cbd45d35a0990f).
>  
>
> >> 
> > 
> > Thanks Ian. And what about sqlite3_config with SQLITE_CONFIG_LOG ? How 
> do I 
> > call that from Go code? I really want the sqlite log (error) message to 
> > appear somewhere 
> > (just C stderr could be enough). 
>
> I'm sorry, I have no idea.  I've never actually used go-sqlite except 
> to run the tests.  Perhaps someone else here knows more. 
>

Thanks Ian. I managed to write my first cgo thing calling it in my new file 
src/objvalmo/sqlitelog.go 
  



Basile

-- 
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: gwenn/gosqlite, go1.8, runtime error: cgo argument has Go pointer to Go pointer

2017-03-08 Thread Ian Lance Taylor
On Wed, Mar 8, 2017 at 11:34 AM, Basile Starynkevitch
 wrote:
>
> On Wednesday, March 8, 2017 at 8:24:26 PM UTC+1, Ian Lance Taylor wrote:
>>
>> On Wed, Mar 8, 2017 at 7:54 AM, Basile Starynkevitch
>>  wrote:
>> I don't have any particular recommendations but I believe that
>> github.com/mattn/go-sqlite3 works correctly with cgo.  I know that
>> because I sent in patches myself
>>
>> (https://github.com/mattn/go-sqlite3/commit/b76c61051faaf0baf3215e6f811003d98639b702,
>>
>> https://github.com/mattn/go-sqlite3/commit/8c66b9cf5ed003dff18db01a55cbd45d35a0990f).
>>
>
> Thanks Ian. And what about sqlite3_config with SQLITE_CONFIG_LOG ? How do I
> call that from Go code? I really want the sqlite log (error) message to
> appear somewhere
> (just C stderr could be enough).

I'm sorry, I have no idea.  I've never actually used go-sqlite except
to run the tests.  Perhaps someone else here knows more.

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] Re: gwenn/gosqlite, go1.8, runtime error: cgo argument has Go pointer to Go pointer

2017-03-08 Thread Basile Starynkevitch


On Wednesday, March 8, 2017 at 8:24:26 PM UTC+1, Ian Lance Taylor wrote:
>
> On Wed, Mar 8, 2017 at 7:54 AM, Basile Starynkevitch 
>  wrote: 
> I don't have any particular recommendations but I believe that 
> github.com/mattn/go-sqlite3 works correctly with cgo.  I know that 
> because I sent in patches myself 
> (
> https://github.com/mattn/go-sqlite3/commit/b76c61051faaf0baf3215e6f811003d98639b702,
>  
>
>
> https://github.com/mattn/go-sqlite3/commit/8c66b9cf5ed003dff18db01a55cbd45d35a0990f).
>  
>
>
>
Thanks Ian. And what about sqlite3_config 
 with SQLITE_CONFIG_LOG 
 ? How do I 
call that from Go code? I really want the sqlite log (error) message to 
appear somewhere
(just C stderr could be enough).
 

-- 
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: gwenn/gosqlite, go1.8, runtime error: cgo argument has Go pointer to Go pointer

2017-03-08 Thread Ian Lance Taylor
On Wed, Mar 8, 2017 at 7:54 AM, Basile Starynkevitch
 wrote:
>
> On Wednesday, March 8, 2017 at 2:23:12 PM UTC+1, Tamás Gulácsi wrote:
>>
>> It's quite straightforward: gwenn/gosqlite has an error, by passing a Go
>> pointer to the C side. This check is in effect since Go1.6.
>>
>> You should try to refresh your gosqlite library, or find a better
>> maintained one.
>
>
> AFAIU I'm using the latest commit of gosqlite.
>
> What concrete sqlite glue library for Go do you recommend me, and most
> importantly, how to configure log using  sqlite3_config with
> SQLITE_CONFIG_LOG? I'm ok with any solution.

I don't have any particular recommendations but I believe that
github.com/mattn/go-sqlite3 works correctly with cgo.  I know that
because I sent in patches myself
(https://github.com/mattn/go-sqlite3/commit/b76c61051faaf0baf3215e6f811003d98639b702,
https://github.com/mattn/go-sqlite3/commit/8c66b9cf5ed003dff18db01a55cbd45d35a0990f).

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] Deploying go https servers

2017-03-08 Thread Shawn Milochik
That sounds a good use-case for Ansible to me. It's pretty easy to use and
get started.

-- 
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] Deploying go https servers

2017-03-08 Thread Sankar
Hi

I have written a golang REST API server and a react webapp that talks to 
this REST server. There is a mysql server that the golang server talks to. 
There is an init script with a bunch of SQL statements to create a few 
tables and indexes. Everything works fine in my local machine. I have 
bought a domain name too. I have a VM on cloud with ssh access. 

I wanted to find out if there are any good blog posts or talks or tutorials 
or "checklists" documenting the process to deploy such a golang server + a 
web front end behind a domain name (example.com for the react webapp and 
api.example.com for the golang) and both accessible only via HTTPS, with 
the API Server probably behind a load balancer, and all certificates being 
valid, etc.

I understand that I can use kubernetes for such orchestration. But I wanted 
to find out a deploy solution which could work reliably and easily (without 
depending on too many third party projects) on AWS. GKE does not exist in 
my region (India) and so cannot use Kube. Any pointers ?

Thanks.

Sankar

-- 
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: Japronto vs Go net/http

2017-03-08 Thread szeptweb
Thanks for the answers.

-- 
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] sort.Slice arguments

2017-03-08 Thread Ain

Another, OO-ish fix is to use method on custom type 
(https://play.golang.org/p/a5S5rNog5h):

type itinerary []string

func (t itinerary) sort() {
sort.Slice(t, func(i, j int) bool {
return t[i] < t[j]
})
}

func main() {
itinerary := itinerary{"Philadelphia", "Chicago", "Boston", "Austin"}
itinerary[1:].sort()
fmt.Println("My new itinerary is", itinerary)
}


ain


On Wednesday, March 8, 2017 at 5:01:08 PM UTC+2, Val wrote:
>
> Sorry for not elaborating in the first place (I was trying to make the 
> point very concise).
>
> This is the starting city :  Philadelphia
>
> This are the other cities :   Chicago, Boston, Austin
>
> The itinerary is the concatenation of starting city + other cities to be 
> visited :   [Philadelphia, Chicago, Boston, Austin]
>
> In this contrived example the first city is fixed, because this is where I 
> am now, wherever I decide to go next. That's why I decide to reorder all 
> cities of my itinerary except the first one.
>
> This is what my naive code what trying to achieve (expected value of slice 
> itinerary after partial sort) : [Philadelphia Austin Boston Chicago]
>
> This is what the code actually produces (value of slice itinerary after 
> partial sort) : [Philadelphia Boston Chicago Austin] , which is why i say 
> it is broken : the last 3 items don't end up in alphabetical order like I 
> expected them to be.
>
> In a real program, there would be various legit reasons to sort only part 
> of a slice, and the items would not always have a builtin type like string, 
> rather custom struct types.
>
> @CBanning  Thanks, I had not thought of StringSlice!  But it's not 
> applicable in my real programs, which deal with custom struct types (not 
> strings).
>
> @David  Sorting the whole slice is not what I was trying to achieve, 
> because I can't change my starting point.
>
> The bug in my code is that the two arguments I pass to sort.Slice are 
> inconsistent : the portion to be sorted is a reslicing from itinerary, 
> while the "less" closure indexes items of the whole itinerary.
>
> I brought up the "go vet" idea because I feel that whenever someone will 
> do some reslicing directly in the first argument,
> - either the result will be "broken" like mine,
> - or the code in the less function will have to refer to the same 
> (unnamed) resliced portion, which is imo convoluted : fix 1 
>  or fix 2 
>  .
>
> The most readable alternative I can think of while still using sort.Slice 
> is to reslice in a new variable prior to sorting : fix 3 
>  .
>
> Best regards
> Val
>
> On Wednesday, March 8, 2017 at 3:25:48 PM UTC+1, David Peacock wrote:
>>
>> On Wed, Mar 8, 2017 at 8:32 AM, Valentin Deleplace  
>> wrote:
>>
>>> I did explain the expected result : "and I want to visit other cities 
>>> in alphabetical order"
>>>
>>
>> Jan is correct; the characterization of a problem hinges on accurately 
>> describing what you expect and what happened instead.  Terms such as 
>> "broken" and "does not work" are best avoided because others don't know 
>> what your definitions are for these in the given context. :-)
>>
>> That being said, your alphabetical order is returned as you intend if you 
>> adjust line 17 thusly:
>>
>> sort.Slice(itinerary[:], func(i, j int) bool {
>>
>> Cheers,
>> David
>>  
>>
>>>
>>> Le 8 mars 2017 2:16 PM, "Jan Mercl" <0xj...@gmail.com> a écrit :
>>>
 On Wed, Mar 8, 2017 at 2:10 PM Val  wrote:

 > What do you think?

 You should explain what you've expected to get instead of what you've 
 got. Without that, I for one, cannot figure out what you see as broken and 
 I have no idea why do you think it's not a good idea to sort a slice of a 
 slice. After all, it's just a slice as any other.

 -- 

 -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...@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] Cross compiling from Windows to Linux produces non-working go routines

2017-03-08 Thread jmontgomery
On Wednesday, March 8, 2017 at 9:50:09 AM UTC-5, Chris Hines wrote:
>
> The infinite loops in each function will busy loop and consume a core 
> without allowing the runtime scheduler a chance to run other goroutines on 
> that core. If your virtual machine doesn't have enough cores then some 
> goroutines may starve.
>
> Change the loops to select {} to block infinitely without busy looping and 
> see if that behaves as expected.
>

I like to use "<-make(chan interface{}) " as a one line "block forever" 
statement.

-- 
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: gwenn/gosqlite, go1.8, runtime error: cgo argument has Go pointer to Go pointer

2017-03-08 Thread Konstantin Khomoutov
On Wed, 8 Mar 2017 08:17:30 -0800 (PST)
Basile Starynkevitch  wrote:

> > So if you're not really tied to SQLite as such (and picked it
> > merely because you're familiar with it or because it's a sane go-to
> > choice for single-file structured data persistence solution) other
> > pure-Go solutions exist. 
> >
> 
> I'm ok with other pure-Go persistence solution, but what are you
> thinking about? A GDBM like thing is perhaps not enough for me 

How about [1]?

There also several K/V stores.  [2] comes to mind.  Supposedly other
folks would throw in their own favorites.

1. https://godoc.org/github.com/cznic/ql
2. https://godoc.org/github.com/boltdb/bolt

-- 
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: gwenn/gosqlite, go1.8, runtime error: cgo argument has Go pointer to Go pointer

2017-03-08 Thread Basile Starynkevitch


On Wednesday, March 8, 2017 at 5:09:06 PM UTC+1, Konstantin Khomoutov wrote:

>
> So if you're not really tied to SQLite as such (and picked it merely 
> because you're familiar with it or because it's a sane go-to choice for 
> single-file structured data persistence solution) other pure-Go 
> solutions exist. 
>

I'm ok with other pure-Go persistence solution, but what are you thinking 
about? A GDBM like thing is perhaps not enough for me 

-- 
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: gwenn/gosqlite, go1.8, runtime error: cgo argument has Go pointer to Go pointer

2017-03-08 Thread Konstantin Khomoutov
On Wed, 8 Mar 2017 07:54:14 -0800 (PST)
Basile Starynkevitch  wrote:

> > It's quite straightforward: gwenn/gosqlite has an error, by passing
> > a Go pointer to the C side. This check is in effect since Go1.6.
> >
> > You should try to refresh your gosqlite library, or find a better 
> > maintained one.
> >
> 
> AFAIU I'm using the latest commit of gosqlite. 
> 
> What concrete sqlite glue library for Go do you recommend me, and
> most importantly, how to configure log using  sqlite3_config 
>  with SQLITE_CONFIG_LOG?
> I'm ok with any solution.

Not to answer the question as stated, but do you really need SQLite
precisely or you'd be fine with other single-file database solution?

I'm asking because to my knowlede there exist no pure-Go solutions
implementing SQLite support, so your program will rely on C bindings
which a) creates portability troubles; b) slow.

So if you're not really tied to SQLite as such (and picked it merely
because you're familiar with it or because it's a sane go-to choice for
single-file structured data persistence solution) other pure-Go
solutions exist.

-- 
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: gwenn/gosqlite, go1.8, runtime error: cgo argument has Go pointer to Go pointer

2017-03-08 Thread James Bardin
That package documents the behavior on all the relevant methods:

> Cannot be used with Go >= 1.6 and cgocheck enabled.

If you trust the author to have written something that is correct despite 
the checks done by cgo, you can disable cgocheck to use those methods. 


On Wednesday, March 8, 2017 at 10:54:15 AM UTC-5, Basile Starynkevitch 
wrote:
>
>
>
> On Wednesday, March 8, 2017 at 2:23:12 PM UTC+1, Tamás Gulácsi wrote:
>>
>> It's quite straightforward: gwenn/gosqlite has an error, by passing a Go 
>> pointer to the C side. This check is in effect since Go1.6.
>>
>> You should try to refresh your gosqlite library, or find a better 
>> maintained one.
>>
>
> AFAIU I'm using the latest commit of gosqlite. 
>
> What concrete sqlite glue library for Go do you recommend me, and most 
> importantly, how to configure log using  sqlite3_config 
>  with SQLITE_CONFIG_LOG? I'm ok 
> with any solution.
>

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


[go-nuts] Re: gwenn/gosqlite, go1.8, runtime error: cgo argument has Go pointer to Go pointer

2017-03-08 Thread Basile Starynkevitch


On Wednesday, March 8, 2017 at 2:23:12 PM UTC+1, Tamás Gulácsi wrote:
>
> It's quite straightforward: gwenn/gosqlite has an error, by passing a Go 
> pointer to the C side. This check is in effect since Go1.6.
>
> You should try to refresh your gosqlite library, or find a better 
> maintained one.
>

AFAIU I'm using the latest commit of gosqlite. 

What concrete sqlite glue library for Go do you recommend me, and most 
importantly, how to configure log using  sqlite3_config 
 with SQLITE_CONFIG_LOG? I'm ok 
with any solution.

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


Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread David Peacock
On Wed, Mar 8, 2017 at 10:01 AM, Val  wrote:

> Sorry for not elaborating in the first place (I was trying to make the
> point very concise).
>

Thank you for detailing further! :-)

> The bug in my code is that the two arguments I pass to sort.Slice are
> inconsistent : the portion to be sorted is a reslicing from itinerary,
> while the "less" closure indexes items of the whole itinerary.
>
> I brought up the "go vet" idea because I feel that whenever someone will
> do some reslicing directly in the first argument,
> - either the result will be "broken" like mine,
> - or the code in the less function will have to refer to the same
> (unnamed) resliced portion, which is imo convoluted : fix 1
>  or fix 2
>  .
>
> The most readable alternative I can think of while still using sort.Slice
> is to reslice in a new variable prior to sorting : fix 3
>  .
>

Personally, I would favor fix 3 in this context.

Cheers,
David

-- 
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] sort.Slice arguments

2017-03-08 Thread James Bardin


On Wednesday, March 8, 2017 at 10:01:08 AM UTC-5, Val wrote:
>
>
> - or the code in the less function will have to refer to the same 
> (unnamed) resliced portion, which is imo convoluted : fix 1 
>  or fix 2 
>  .
>

Having recently written code that is pretty much the same as fix #1, I 
wouldn't want vet to flag that as incorrect when it isn't.  That's more a 
lint issue, but I'm not convinced it's a problem when unit test coverage of 
the code should pick out the problem fairly quickly. 

-- 
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] Cross compiling from Windows to Linux produces non-working go routines

2017-03-08 Thread ascii88
Fantastic! In my main program I had the main in an infinite for. That was 
burning the only core of my vm.
I've changed that to select and now it's working fine.

Thank you Konstantin, for your answer, too.

El miércoles, 8 de marzo de 2017, 11:50:09 (UTC-3), Chris Hines escribió:
>
> The infinite loops in each function will busy loop and consume a core 
> without allowing the runtime scheduler a chance to run other goroutines on 
> that core. If your virtual machine doesn't have enough cores then some 
> goroutines may starve.
>
> Change the loops to select {} to block infinitely without busy looping and 
> see if that behaves as expected.
>
> On Wednesday, March 8, 2017 at 9:20:39 AM UTC-5, Rodrigo Pardo wrote:
>>
>> I've made this test program
>>
>>
>> package main
>>
>> import "fmt"
>>
>> func func1() {
>> fmt.Println("running func1")
>> for {
>>
>> }
>> }
>>
>> func func2() {
>> fmt.Println("running func1")
>> for {
>>
>> }
>> }
>>
>> func func3() {
>> fmt.Println("running func1")
>> for {
>>
>> }
>> }
>>
>> func main() {
>>
>> go func1()
>> fmt.Println("run func1")
>> go func2()
>> fmt.Println("run func2")
>> go func3()
>> fmt.Println("run func3")
>> for {
>>
>> }
>>
>> }
>>
>> On windows I get 
>> go run test.go
>>
>> run func1
>> running func1
>> run func2
>> running func1
>> run func3
>> running func1
>>
>> On Linux, cross compiled (go build -v) I get
>> ./test
>>
>> run func1
>> run func2
>> run func3
>>
>> Now I've installed go to my linux and I'm compiling directly from there 
>> (gopath set to shared folder)
>> go run test.go 
>>
>> run func1
>> run func2
>> run func3
>>
>>
>> El miércoles, 8 de marzo de 2017, 10:48:26 (UTC-3), Ayan George escribió:
>>>
>>>
>>>
>>> On 03/08/2017 08:30 AM, asc...@gmail.com wrote: 
>>>
>>> > In the main function I call various go routines, I've set println 
>>> after 
>>> > each call, so I know they are being executed. But I don't get the 
>>> > printlns I've set inside of some of those routines, for the same 
>>> purpose. 
>>> > 
>>>
>>> So you are seeing some Println()s but not others or are you not seeing 
>>> any Println()s at all? 
>>>
>>> -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.


Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread Val
Sorry for not elaborating in the first place (I was trying to make the 
point very concise).

This is the starting city :  Philadelphia

This are the other cities :   Chicago, Boston, Austin

The itinerary is the concatenation of starting city + other cities to be 
visited :   [Philadelphia, Chicago, Boston, Austin]

In this contrived example the first city is fixed, because this is where I 
am now, wherever I decide to go next. That's why I decide to reorder all 
cities of my itinerary except the first one.

This is what my naive code what trying to achieve (expected value of slice 
itinerary after partial sort) : [Philadelphia Austin Boston Chicago]

This is what the code actually produces (value of slice itinerary after 
partial sort) : [Philadelphia Boston Chicago Austin] , which is why i say 
it is broken : the last 3 items don't end up in alphabetical order like I 
expected them to be.

In a real program, there would be various legit reasons to sort only part 
of a slice, and the items would not always have a builtin type like string, 
rather custom struct types.

@CBanning  Thanks, I had not thought of StringSlice!  But it's not 
applicable in my real programs, which deal with custom struct types (not 
strings).

@David  Sorting the whole slice is not what I was trying to achieve, 
because I can't change my starting point.

The bug in my code is that the two arguments I pass to sort.Slice are 
inconsistent : the portion to be sorted is a reslicing from itinerary, 
while the "less" closure indexes items of the whole itinerary.

I brought up the "go vet" idea because I feel that whenever someone will do 
some reslicing directly in the first argument,
- either the result will be "broken" like mine,
- or the code in the less function will have to refer to the same (unnamed) 
resliced portion, which is imo convoluted : fix 1 
 or fix 2 
 .

The most readable alternative I can think of while still using sort.Slice 
is to reslice in a new variable prior to sorting : fix 3 
 .

Best regards
Val

On Wednesday, March 8, 2017 at 3:25:48 PM UTC+1, David Peacock wrote:
>
> On Wed, Mar 8, 2017 at 8:32 AM, Valentin Deleplace  > wrote:
>
>> I did explain the expected result : "and I want to visit other cities in 
>> alphabetical order"
>>
>
> Jan is correct; the characterization of a problem hinges on accurately 
> describing what you expect and what happened instead.  Terms such as 
> "broken" and "does not work" are best avoided because others don't know 
> what your definitions are for these in the given context. :-)
>
> That being said, your alphabetical order is returned as you intend if you 
> adjust line 17 thusly:
>
> sort.Slice(itinerary[:], func(i, j int) bool {
>
> Cheers,
> David
>  
>
>>
>> Le 8 mars 2017 2:16 PM, "Jan Mercl" <0xj...@gmail.com > a 
>> écrit :
>>
>>> On Wed, Mar 8, 2017 at 2:10 PM Val  
>>> wrote:
>>>
>>> > What do you think?
>>>
>>> You should explain what you've expected to get instead of what you've 
>>> got. Without that, I for one, cannot figure out what you see as broken and 
>>> I have no idea why do you think it's not a good idea to sort a slice of a 
>>> slice. After all, it's just a slice as any other.
>>>
>>> -- 
>>>
>>> -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...@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] Cross compiling from Windows to Linux produces non-working go routines

2017-03-08 Thread Konstantin Khomoutov
On Wed, 8 Mar 2017 06:20:25 -0800 (PST)
asci...@gmail.com wrote:

> I've made this test program
> 
> 
> package main
> 
> import "fmt"
> 
> func func1() {
> fmt.Println("running func1")
> for {
> 
> }
[...]
> func main() {
> 
> go func1()
> fmt.Println("run func1")
> go func2()
> fmt.Println("run func2")
> go func3()
> fmt.Println("run func3")
> for {
> 
> }
> 
> }
[...]

Each for { } produces a "busy loop" which burns a single CPU
core/socket and effectively binds a goroutine it executes in to its
underlying OS thread.

This means that if your Linux VM has different idea of CPU
cores/sockets available than your Windows host (supposedly, fewer), you
will get different printouts because certain goroutines simply won't
have a chance to run.

Please read up any Go book / HOWTO on goroutine synchronization
techniques and use any of them to properly synchronize your main() with
your goroutines (sync.WaitGroup might be the simplest one for this
case).  Don't ever use busy loops.

-- 
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] Cross compiling from Windows to Linux produces non-working go routines

2017-03-08 Thread Chris Hines
The infinite loops in each function will busy loop and consume a core 
without allowing the runtime scheduler a chance to run other goroutines on 
that core. If your virtual machine doesn't have enough cores then some 
goroutines may starve.

Change the loops to select {} to block infinitely without busy looping and 
see if that behaves as expected.

On Wednesday, March 8, 2017 at 9:20:39 AM UTC-5, Rodrigo Pardo wrote:
>
> I've made this test program
>
>
> package main
>
> import "fmt"
>
> func func1() {
> fmt.Println("running func1")
> for {
>
> }
> }
>
> func func2() {
> fmt.Println("running func1")
> for {
>
> }
> }
>
> func func3() {
> fmt.Println("running func1")
> for {
>
> }
> }
>
> func main() {
>
> go func1()
> fmt.Println("run func1")
> go func2()
> fmt.Println("run func2")
> go func3()
> fmt.Println("run func3")
> for {
>
> }
>
> }
>
> On windows I get 
> go run test.go
>
> run func1
> running func1
> run func2
> running func1
> run func3
> running func1
>
> On Linux, cross compiled (go build -v) I get
> ./test
>
> run func1
> run func2
> run func3
>
> Now I've installed go to my linux and I'm compiling directly from there 
> (gopath set to shared folder)
> go run test.go 
>
> run func1
> run func2
> run func3
>
>
> El miércoles, 8 de marzo de 2017, 10:48:26 (UTC-3), Ayan George escribió:
>>
>>
>>
>> On 03/08/2017 08:30 AM, asc...@gmail.com wrote: 
>>
>> > In the main function I call various go routines, I've set println after 
>> > each call, so I know they are being executed. But I don't get the 
>> > printlns I've set inside of some of those routines, for the same 
>> purpose. 
>> > 
>>
>> So you are seeing some Println()s but not others or are you not seeing 
>> any Println()s at all? 
>>
>> -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.


Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread David Peacock
On Wed, Mar 8, 2017 at 8:32 AM, Valentin Deleplace 
wrote:

> I did explain the expected result : "and I want to visit other cities in
> alphabetical order"
>

Jan is correct; the characterization of a problem hinges on accurately
describing what you expect and what happened instead.  Terms such as
"broken" and "does not work" are best avoided because others don't know
what your definitions are for these in the given context. :-)

That being said, your alphabetical order is returned as you intend if you
adjust line 17 thusly:

sort.Slice(itinerary[:], func(i, j int) bool {

Cheers,
David


>
> Le 8 mars 2017 2:16 PM, "Jan Mercl" <0xj...@gmail.com> a écrit :
>
>> On Wed, Mar 8, 2017 at 2:10 PM Val  wrote:
>>
>> > What do you think?
>>
>> You should explain what you've expected to get instead of what you've
>> got. Without that, I for one, cannot figure out what you see as broken and
>> I have no idea why do you think it's not a good idea to sort a slice of a
>> slice. After all, it's just a slice as any other.
>>
>> --
>>
>> -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.
>

-- 
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] Cross compiling from Windows to Linux produces non-working go routines

2017-03-08 Thread ascii88
I've made this test program


package main

import "fmt"

func func1() {
fmt.Println("running func1")
for {

}
}

func func2() {
fmt.Println("running func1")
for {

}
}

func func3() {
fmt.Println("running func1")
for {

}
}

func main() {

go func1()
fmt.Println("run func1")
go func2()
fmt.Println("run func2")
go func3()
fmt.Println("run func3")
for {

}

}

On windows I get 
go run test.go

run func1
running func1
run func2
running func1
run func3
running func1

On Linux, cross compiled (go build -v) I get
./test

run func1
run func2
run func3

Now I've installed go to my linux and I'm compiling directly from there 
(gopath set to shared folder)
go run test.go 

run func1
run func2
run func3


El miércoles, 8 de marzo de 2017, 10:48:26 (UTC-3), Ayan George escribió:
>
>
>
> On 03/08/2017 08:30 AM, asc...@gmail.com  wrote: 
>
> > In the main function I call various go routines, I've set println after 
> > each call, so I know they are being executed. But I don't get the 
> > printlns I've set inside of some of those routines, for the same 
> purpose. 
> > 
>
> So you are seeing some Println()s but not others or are you not seeing 
> any Println()s at all? 
>
> -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.


Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread C Banning
https://play.golang.org/p/Pqd0Wk-yqe


-- 
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: constant 256 overflows byte

2017-03-08 Thread Paul Hankin
On Tuesday, 7 March 2017 19:02:59 UTC-5, Eric Brown wrote:
>
> memoryBlock := make([]byte, 4)
>
> binary.LittleEndian.PutUint32(memoryBlock, 12345678)  
>
>   
>
> memoryBlock[2] = 256 - (187 - memoryBlock[2]) ' results in error: 
> constant 256 overflows byte
> memoryBlock[2] = 255 - (187 - memoryBlock[2]) + 1 ' results in no errors  
>
>
> Why is this, and what would be your suggested method of handling this?
> I don't like having to do the later as it just looks sloppy.
>
>
Byte operations work modulo 256, so adding 256 does nothing.

Using that, you can simplify your expression to this:
memoryBlock[2] -= 187

https://play.golang.org/p/5ljs4wIeq9
 -- 
Paul Hankin

-- 
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] Cross compiling from Windows to Linux produces non-working go routines

2017-03-08 Thread Ayan George


On 03/08/2017 08:30 AM, asci...@gmail.com wrote:

> In the main function I call various go routines, I've set println after
> each call, so I know they are being executed. But I don't get the
> printlns I've set inside of some of those routines, for the same purpose.
> 

So you are seeing some Println()s but not others or are you not seeing
any Println()s at all?

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


Re: [go-nuts] How can I implement a TCP server using a model which similar to epoll (or kqueue, IOCP) rather than just using goroutine for each client?

2017-03-08 Thread Leonardo Santagada
First step in fixing memory problems is measuring it. A goroutine IIRC 
reserves 2kb of stack space only, so removing goroutines from your program 
and probably rewriting everything keeping all else the same will save you 
100*2kb memory. Seems like a lot of work for little to no gain. Do present 
a memory profile of your program and lets see what is the culprit/culprits 
of this memory usage.

On Monday, March 6, 2017 at 1:42:54 PM UTC+1, Nick Rio wrote:
>
> I don't know. I thought about it before but believe it will create some 
> design complexity in my application.
>
> As currently I maybe able to re-implement some kind of polling mechanism 
> from the ground level, I don't think I'll play that large'n'small buffer 
> game. + It's always fun to play with the lower level system call.
>
> But who knows, I may come back to it when I'm in despair.
>
> On Monday, March 6, 2017 at 8:27:05 PM UTC+8, Jakob Borg wrote:
>>
>> If most of your connections are idle most of the time, and your memory 
>> usage comes from something like 
>>
>> buf := make([]byte, 65536) 
>> n, err := conn.Read(buf) // <-- block here for ever 
>>
>> you could simply use a smaller buffer for the read that takes a long 
>> time. For example, if the message is length prefixed, just read into a 
>> [4]byte or similar and *then* grab a buffer from a sync.Pool or create one 
>> when you know the size to read. Even if the message is not length prefixed 
>> but you know it's long, you can still read the first few bytes into a small 
>> buffer and then read the rest once that call returns, appending to the 
>> first read. This won't be efficient in a tight loop, but if you know a 
>> point where may clients idle it may be worth it. 
>>
>> //jb 
>>
>> > On 6 Mar 2017, at 09:26, Nick Rio  wrote: 
>> > 
>> > The application is working right now. Current work for me is to found a 
>> way to reduce it's memory footprint as it will take at least 1GB memory to 
>> hold only C10K idle connections. 
>>
>>

-- 
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] sort.Slice arguments

2017-03-08 Thread Valentin Deleplace
I did explain the expected result : "and I want to visit other cities in
alphabetical order"

Le 8 mars 2017 2:16 PM, "Jan Mercl" <0xj...@gmail.com> a écrit :

> On Wed, Mar 8, 2017 at 2:10 PM Val  wrote:
>
> > What do you think?
>
> You should explain what you've expected to get instead of what you've got.
> Without that, I for one, cannot figure out what you see as broken and I
> have no idea why do you think it's not a good idea to sort a slice of a
> slice. After all, it's just a slice as any other.
>
> --
>
> -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] Cross compiling from Windows to Linux produces non-working go routines

2017-03-08 Thread ascii88
Hello, I'm running go1.8 windows/amd64

I have a working program, which I want to compile to Linux. So I set 
GOOS=linux and then go build

I have a virtual machine with Debian 7. And I run the program. However it 
functions incorrectly.

In the main function I call various go routines, I've set println after 
each call, so I know they are being executed. But I don't get the printlns 
I've set inside of some of those routines, for the same purpose.

Can this have something to do with the program being cross compiled? What 
should I test to see if I can get it working?

Thanks in advance
Rodrigo

-- 
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] gwenn/gosqlite, go1.8, runtime error: cgo argument has Go pointer to Go pointer

2017-03-08 Thread Tamás Gulácsi
It's quite straightforward: gwenn/gosqlite has an error, by passing a Go 
pointer to the C side. This check is in effect since Go1.6.

You should try to refresh your gosqlite library, or find a better maintained 
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.


[go-nuts] Re: Building Cross Platform GUI apps in Go and Electron

2017-03-08 Thread mhhcbon
hi,

same interest here. Have you checked 
https://electron.atom.io/docs/tutorial/application-distribution/ ?

If i m correct the front end could be the packager app,
i was reading at electron-builder, 
to include the backend, i d simply
add the files to the builder manifest,
like described at
https://github.com/electron-userland/electron-builder/wiki/Options#source-and-destination-directories

I have not dig yet too much about
- menu/desktop links
- growler (? desktop app notifications)

an easier solution seems 
https://github.com/electron-userland/electron-packager

But, i read https://github.com/electron-userland/electron-packager#about

Note that packaged Electron applications can be relatively large. A zipped 
> barebones OS X Electron application is around 40MB.
>

And 
https://github.com/electron-userland/electron-builder#electron-builder---

... support out of the box. NPM packages management: 
>
>- Native application dependencies 
> 
>compilation (including Yarn  support).
>
>

So in my case, maybe i ll simply make a go executable 
and rely on the browser without electron.
40 mb is huge... I don t want either to install the whole nodejs ecosystem 
for such app.

On Wednesday, March 8, 2017 at 1:32:14 PM UTC+1, Nyah Check wrote:
>
> Hi Gophers,
>
> I have this project to build an SSH client for Windows, Linux and Mac OS. 
> I have built the back end in Go and intend to build the front end in 
> electron. I'm currently stuck getting the GUI to work. The back end of the 
> app works well on the Linux browser. I just wish to know if there are any 
> Go packages that facilitate the building of cross platform Desktop apps 
> with Go and electron.  I've found Gallium 
>  and Murlok 
> ; but they all seem to support only 
> Mac OS only. 
>
> Any ideas?
>
> Thanks,
> Nyah
> -- 
> "The heaviest penalty for declining to rule is to be ruled by someone 
> inferior to yourself." --*Plato* 
>

-- 
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] sort.Slice arguments

2017-03-08 Thread Jan Mercl
On Wed, Mar 8, 2017 at 2:10 PM Val  wrote:

> What do you think?

You should explain what you've expected to get instead of what you've got.
Without that, I for one, cannot figure out what you see as broken and I
have no idea why do you think it's not a good idea to sort a slice of a
slice. After all, it's just a slice as any other.

-- 

-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] sort.Slice arguments

2017-03-08 Thread Val
Hello fellows
The following code (playground ) :

//
// I am in Philadelphia, and I want to visit other cities
//
itinerary := []string{"Philadelphia", "Chicago", "Boston", "Austin"}

//
// I am in Philadelphia, and I want to visit other cities in 
alphabetical order
//
sort.Slice(itinerary[1:], func(i, j int) bool {
return itinerary[i] < itinerary[j]
})

is broken for retrospectively obvious reasons.  Yet, I scratched my head 
for several minutes before finding the bug in my actual code.
So I wonder if this would be a good case for a new vet rule.  Something 
like "slicing the first argument is not a good idea, it will lead to 
something that is either broken or convoluted".
What do you think?

-- 
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] Building Cross Platform GUI apps in Go and Electron

2017-03-08 Thread Nyah Check
When I compile the source with gox for the different platforms. packing the
electron files with the respective shell scripts the binaries don't seem to
work on windows. So I'm guessing I've messed up the electron configs
somewhere. I just hoped there might have been a go package developed for
this to make it easier to build for different platforms.

On Wed, Mar 8, 2017 at 1:46 PM, Michael Banzon  wrote:

> I have no deep knowledge of this - but is also looking into a project with
> similar characteristics.
>
> I'm wondering what specifically isn't working for you?
>
> On Wed, Mar 8, 2017 at 1:33 PM Nyah Check  wrote:
>
>> Hi Gophers,
>>
>> I have this project to build an SSH client for Windows, Linux and Mac OS.
>> I have built the back end in Go and intend to build the front end in
>> electron. I'm currently stuck getting the GUI to work. The back end of the
>> app works well on the Linux browser. I just wish to know if there are any
>> Go packages that facilitate the building of cross platform Desktop apps
>> with Go and electron.  I've found Gallium
>>  and Murlok
>> ; but they all seem to support only
>> Mac OS only.
>>
>> Any ideas?
>>
>> Thanks,
>> Nyah
>> --
>> "The heaviest penalty for declining to rule is to be ruled by someone
>> inferior to yourself." --*Plato*
>>
>> --
>> 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 Banzon
> https://michaelbanzon.com/
>



-- 
"The heaviest penalty for declining to rule is to be ruled by someone
inferior to yourself." --*Plato*

-- 
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] Building Cross Platform GUI apps in Go and Electron

2017-03-08 Thread Michael Banzon
I have no deep knowledge of this - but is also looking into a project with
similar characteristics.

I'm wondering what specifically isn't working for you?

On Wed, Mar 8, 2017 at 1:33 PM Nyah Check  wrote:

> Hi Gophers,
>
> I have this project to build an SSH client for Windows, Linux and Mac OS.
> I have built the back end in Go and intend to build the front end in
> electron. I'm currently stuck getting the GUI to work. The back end of the
> app works well on the Linux browser. I just wish to know if there are any
> Go packages that facilitate the building of cross platform Desktop apps
> with Go and electron.  I've found Gallium
>  and Murlok
> ; but they all seem to support only
> Mac OS only.
>
> Any ideas?
>
> Thanks,
> Nyah
> --
> "The heaviest penalty for declining to rule is to be ruled by someone
> inferior to yourself." --*Plato*
>
> --
> 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 Banzon
https://michaelbanzon.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.


[go-nuts] Building Cross Platform GUI apps in Go and Electron

2017-03-08 Thread Nyah Check
Hi Gophers,

I have this project to build an SSH client for Windows, Linux and Mac OS. I
have built the back end in Go and intend to build the front end in
electron. I'm currently stuck getting the GUI to work. The back end of the
app works well on the Linux browser. I just wish to know if there are any
Go packages that facilitate the building of cross platform Desktop apps
with Go and electron.  I've found Gallium
 and Murlok
; but they all seem to support only Mac
OS only.

Any ideas?

Thanks,
Nyah
-- 
"The heaviest penalty for declining to rule is to be ruled by someone
inferior to yourself." --*Plato*

-- 
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: Registering a Go app as a protocol handler under Mac OS X

2017-03-08 Thread Joe Blue
thansk nathan, i will try it out now.

I am curious if anyone else has done this for windows, Linux, Android and 
IOS ?

I am working on building apps with golang and QT, and need to be able to do 
it cross platform. QT has aweful support for this, and i think a golang lib 
that does this, will allow all GUI toolkits using golang to benefit from 
this.

i am willing to bring it al together into a single library that is agnostic 
to OS and wraps the special things each OS needs.
Then from your golang code you just call the agnostic lib,

I know this is a bit of a boiling the ocean idea, but the more i looked 
into it the more i found he differences between OS to be huge.

Please let me knwo what you think ...

joe


On Monday, February 20, 2017 at 6:32:08 PM UTC+1, Nathan Kerr wrote:
>
> I managed to get this working.
>
> https://gist.github.com/nathankerr/38d8b0d45590741b57f5f79be336f07c
>
> I don't know what sort of app you are making, so I made a simple gui that 
> displays the url received, with some filler text before any are. I think 
> the non-ui parts should transfer to whatever you are doing.
>
> A few notes:
>
> - main.go lines 3-8 (cgo and import C) are important. They tell go how to 
> build the c and obj-c parts.
> - after C.StartURLHandler is called, HandlerURL will be called. HandleURL 
> needs to be non-blocking as it seems to block the whole UI, so put 
> long-running stuff in another go routine. I had to buffer labelText so the 
> a url received at the same time the app starts will not hang the program.
> - I had to put C.StartURLHandler before the ui.Main stuff so the first url 
> would not be lost when the app is opened with `open myapp://whatever` and 
> the app was not already running.
> - running `make` will setup the app, including building it. You will need 
> to `go get -u github.com/andlabs/ui`  
> before doing so.
> - You might need to change the url scheme to something else because you 
> (presumably) already have an app that registers myapp. I didn't think of 
> this earlier as I was trying to follow your question.
> - Before trying to open the url, open the app itself. This will register 
> the url scheme with macOS. After doing so, the app will work if it is 
> already running or not.
> - I was not able to get cmd-Q to close the app. Just click the close (red) 
> button on the window. This seems to be a limit of the ui package.
>
> This worked for me using go1.8 on macOS 10.12.3 and the latest version of 
> the ui package.
>
> Hope it helps you out.
>
> Nathan
>
> On Wednesday, July 6, 2016 at 11:50:02 PM UTC+2, chris...@gmail.com wrote:
>>
>> Hi,
>>
>> I'm trying to hook up a Go application to a URL protocol handler in Mac 
>> OS X.  I want a user to be able to click on a link such as myapp://foo/bar 
>> and have that launch myapp and be able to access the full query parameters. 
>>  I've made it as far as getting the OS to register the handler and launch 
>> the app.  That's done by bundling the Go binary into a OS X-style .app 
>> package with a Info.plist file like this:  
>> https://gist.github.com/chrissnell/db95a3c5ad6ceca4c673e96cca0f7548
>>
>> The challenge now is to figure out how to reference the query parameters 
>> within Go.  I've determined that they're not passed as command-line 
>> arguments.   From what I can tell, you have to use Cocoa libraries to get 
>> at them  [1].  I don't know Objective-C or Swift, though, so that's where 
>> I'm stumbling.
>>
>> There are cheap hacks to do this with AppleScript [2] but I wanted 
>> something more native. 
>>
>> Has anybody done this?
>>
>> Chris
>>
>>
>> [1] 
>> http://fredandrandall.com/blog/2011/07/30/how-to-launch-your-macios-app-with-a-custom-url/
>>
>> [2] 
>> https://support.shotgunsoftware.com/hc/en-us/community/posts/209485898-Launching-External-Applications-using-Custom-Protocols-under-OSX
>>
>>

-- 
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] gwenn/gosqlite, go1.8, runtime error: cgo argument has Go pointer to Go pointer

2017-03-08 Thread Basile Starynkevitch
Hello list,

It is about my (github-ed) monimelt  
(MELT monitor, in early pre-alpha stage) specifically about its commit 
44434cd991c 

 
which has some README.md 
 giving build 
instructions; I'm getting a reproducible bug that I don't understand, but I 
am still a newbie in Go.
I'm using go1.8 on Debian/Linux/Sid/x86-64 and I am building with gb 
 (not with go build). The driving idea at first is to 
persist, in sqlite database using some JSON format, the entire heap -of 
some Scheme-like "interpreter"- made of "objects" or "items" and values.

To reproduce my bug, follow my build instructions (essentially, how to use 
gb to build my MELT monitor) then run

./bin/monimelt -final-dump-dir /tmp/


What should happen is that the /tmp/ directory (of course you can 
replace that by any fresh path in /tmp or elsewhere) should be created and 
filled with two (almost empty) sqlite databases.
Actually I am creating temporary files in that directory, with some *random* 
suffix like e.g. +_9l7UhTyyJFx_p6950.tmp (of course when you'll run it 
you'll get *another* random suffix) and I want to rename these temporary 
files when at end of dump.


What is really happening is strange (and reproducible): 
2017/03/08 10:19:35 persist-init installed sqliteerrorlogmo
Monimelt starting pid 6950, Go version go1.8
2017/03/08 10:19:35 monimelt should final dump in /tmp/
2017/03/08 10:19:35 OpenDumperDirectory dirpath=/tmp/ dtempsuf=+
_9l7UhTyyJFx_p6950.tmp
2017/03/08 10:19:35 create_table globflag=true dir=/tmp/
2017/03/08 10:19:35 create_table db=&{0xc420018530 file:/tmp//
monimelt_state.sqlite+_9l7UhTyyJFx_p6950.tmp?mode=rwc=private 0 {0 0} 
[] map[] 0 0 0xc420016480 false map[] map[] 0 0 0 } sql_create_t_params
="CREATE TABLE IF NOT EXISTS t_params \n (par_name VARCHAR(35) PRIMARY KEY 
ASC NOT NULL UNIQUE, \n  par_value TEXT NOT NULL);"
panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
github.com/gwenn/gosqlite.(*Conn).ProgressHandler.func2(0x162b488, 
0xc40064, 0xc42000c940)
/home/basile/Documents/monimelt/vendor/src/github.com/gwenn/gosqlite/
trace.go:315 +0x8b
github.com/gwenn/gosqlite.(*Conn).ProgressHandler(0xc42009a640, 0x5833f8, 
0x164, 0x558460, 0xc420018440)
/home/basile/Documents/monimelt/vendor/src/github.com/gwenn/gosqlite/
trace.go:316 +0x117
github.com/gwenn/gosqlite.(*conn).ExecContext(0xc42000e060, 0x8255e0, 
0xc420018440, 0x582e9f, 0x79, 0x851af8, 0x0, 0x0, 0x0, 0x0, ...)
/home/basile/Documents/monimelt/vendor/src/github.com/gwenn/gosqlite/
driver.go:143 +0xcb
database/sql.ctxDriverExec(0x8255e0, 0xc420018440, 0x7fb37ce4e198, 
0xc42000e060, 0x582e9f, 0x79, 0x851af8, 0x0, 0x0, 0x42c0ae, ...)
/usr/local/go/src/database/sql/ctxutil.go:31 +0x28d
database/sql.(*DB).exec.func2()
/usr/local/go/src/database/sql/sql.go:1199 +0x99
database/sql.withLock(0x824ae0, 0xc42001a9a0, 0xc42004b6c0)
/usr/local/go/src/database/sql/sql.go:2545 +0x65
database/sql.(*DB).exec(0xc42009a460, 0x8255e0, 0xc420018440, 0x582e9f, 0x79
, 0x0, 0x0, 0x0, 0x101, 0x0, ...)
/usr/local/go/src/database/sql/sql.go:1200 +0x51c
database/sql.(*DB).ExecContext(0xc42009a460, 0x8255e0, 0xc420018440, 
0x582e9f, 0x79, 0x0, 0x0, 0x0, 0x145, 0x0, ...)
/usr/local/go/src/database/sql/sql.go:1165 +0xbc
database/sql.(*DB).Exec(0xc42009a460, 0x582e9f, 0x79, 0x0, 0x0, 0x0, 0xa0, 
0xc42009a500, 0x0, 0x834a80)
/usr/local/go/src/database/sql/sql.go:1179 +0x85
objvalmo.DumperMo.create_tables(0x0, 0x7ffc2316b893, 0x9, 0xc42000c900, 0x17
, 0xc42009a460, 0xc42009a500, 0x0, 0x0, 0x0, ...)
/home/basile/Documents/monimelt/src/objvalmo/persist.go:208 +0x240
objvalmo.OpenDumperDirectory(0x7ffc2316b893, 0x9, 0x0)
/home/basile/Documents/monimelt/src/objvalmo/persist.go:306 +0xb8b
objvalmo.DumpIntoDirectory(0x7ffc2316b893, 0x9)
/home/basile/Documents/monimelt/src/objvalmo/persist.go:534 +0x39
main.main()
/home/basile/Documents/monimelt/src/monimelt/monimelt.go:38 +0x8df


Now, here is my *partial* understanding of the issue.I suspect I have some 
bug in my code (but then I don't understand where), but it could be 
outside. Maybe it is related to the order of running the various init 
functions (and I don't understand that order, and I don't know how to order 
these initializations). Mayb the bug is elsewhere.

First, *I really need sqlite logging facilities*. So I need the C function 
sqlite3_config  to be called very 
early with SQLITE_CONFIG_LOG 
 and a function 
which justs log verbosely the error. The reason I need sqlite logging is 
that I sometimes am making stupid SQL mistakes, and that logging gives 
verbose enough messages to help me a lot.

So I 

[go-nuts] Japronto vs Go net/http

2017-03-08 Thread Tamás Gulácsi
Japrono is mostly written in C.
It provides only HTTP/1.1, with not-too-widespread pipelining support.
No HTTP/2, so not future proof.

As the readme says, fasthttp is only 18% slower than japronto. And we know that 
fasthttp is fast because of different design goals: it sacrifices ease of use 
and proper RFC compatibility for speed.

-- 
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] Japronto vs Go net/http

2017-03-08 Thread Wojciech S. Czarnecki
Dnia 2017-03-07, o godz. 23:34:54
Gopher  napisał(a):

> Hi.Does anyone know why the Japronto is faster?
["" from japronto github pitch.]

Because "The server is written in hand tweaked C trying to take advantage of
modern CPUs." What translates to 'it will run fast if it will'.

> Is it possible to do something about it?

Yes. Once it (japronto) will come out of "early preview with alpha quality
implementation" state and it start to implement standards you will be
pleased to see it to be gradually less and less 'faster than'.

> I noticed that the response header is larger than japronto header. 
> Response header net/http additionally includes the current date.

As said: standards.

-- 
Wojciech S. Czarnecki
   ^oo^ OHIR-RIPE

-- 
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] How to create unique IDs when ranging over data in Golang and use in Javascript

2017-03-08 Thread Rejoy Nair
Yes..thats the link.. :)  was a bit short on time.. so posted the question
in multiple forums.. was struggling a bit manipulating html elements .. so
was kind of overwhelmed by the answer provided...

On Tue, Mar 7, 2017 at 4:00 PM, Konstantin Khomoutov <
flatw...@users.sourceforge.net> wrote:

> On Tue, 7 Mar 2017 15:42:11 +0530
> Rejoy Nair  wrote:
>
> > Thanks a lot!. Your answers have been helpful. I was also provided
> > with a very good solution from another forum that I 'll post that
> > here for the benefit for anybody who 'd come across this post.
>
> You mean , don't you? ;-)
>
> > Its on the lines of what you 'd suggested. Till  then I was actually
> > beginning to think that this wasn't even really a Golang question.
>
> It can be deemed as being related to the stock Go templating, so that's
> OK even though the essense of your problem wasn't Go-specific.
>
> [...]
>

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