Re: [go-nuts] Unmarshalling and tags

2016-06-21 Thread Ain

teisipäev, 21. juuni 2016 9:47.54 UTC+3 kirjutas rog:
>
> I feel your pain - we quite often have tags with entries for three 
> formats (JSON, YAML and BSON) - but I'm not sure that collapsing them 
> is necessarily a good idea, as the named tags indicate that the object 
> is explicitly intended to be able to be marshaled with those formats. 
>

Another idea is to allow the tags to be defined by more than one string:

type Payment struct { 
ActionType paypal.ActionType `xml:"actionType,omitempty"` 
 `json:"action"`
ReceiverList paypal.ReceiverList 
`xml:"receiverList,omitempty"`  `json:"receiver"`
} 

compiler would concatenate them into single string so all code will 
continue to work but this would allow the gofmt to align them into neat 
columns, making it easier to read.


ain 

-- 
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: A proposal for generic in go

2016-06-21 Thread andrew . mezoni
>> While later I realized that we still need some parameter check in the 
callee code to satisfy the interface matching (the generic version of each 
function in my proposal).

A am sorry but your judgements is not correct.
Here is a proofs:
1. It is redundant to perform check of the correctness of the assignments 
after when assignement already made.

Eg.

val i int
i = 0
// It is redundant to perform check the correctness of the assignments of 
`i` after when assignement of `i` already made.

2. Fucntion is a callable piece of code which CAN have initial variables 
(function parameters) which SHOULD be assigned (via function arguments) 
before function invocation.

Of course, these parameters can be explicit and implicit.
Eg. receiver of the method is an implicit parameter but it still a 
parameter (function variable which would be assigned before function 
invocation implicitly by the compiler, or by the reflection construction).

That is, this code is equilvalent.

var i int
i = 0
// other code, `i` already assigned

func foo(i int) {
  // other code, `i` already assigned
}


3. Also you should to know that in a generic type system (type sytem with 
the generic types) each type is potentialy a generic type.
Here is a proof.

Each type in a generic type system looks like a function.
Type can have a [0..~] number of parameters which are declared by the type 
declaration and whose parameters can be assigned by the type arguments. If 
arguments omitted then parameters assigned to default values (types).


The same as the funtions.

// Declare type with 2 parameters, K and V
type Type {}

// Declare type with 2 bounded parameters, K and V
type Type1 {}

// Instantiate new type with a specified arguments (the same as the 
function invocation)
// For simplicity we can imagine the following auto generated code
// if *__staticType1021 == nill {
//   *__staticType1021 = __createGenericType(__getType(Type1), 
__getType(string), __getType(bool))
//  That is, call to __createGenericType(*t RType, args... *RType)
// }

// foo := __newobject(*__staticType1021)

foo := Type1()

Another story when we use generic type on the callee side.

func (t *Type1) foo(key K) V {
  // Here compiler always assume that the type of `t` is a generic type 
`Type1` with a correctly assigned type arguments.
  // Assigned arguments does not need to re-check 
  // ___type0 := __getTypeOf(t)
  // Here is enough (since type are generic) rely only on that the each 
type argument bound to the type parameter
  ...
}


-- 
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] python bencoded list equivalent in golang

2016-06-16 Thread Matt Harden
We use the type interface{} for data that can contain any type. So you
might use bencode([]interface{}{4456, "Rakesh", 27}).

On Thu, Jun 16, 2016 at 9:31 AM  wrote:

> The server which I am contacting to is written in python and excepts
> bencoded list.
>
> In my existing python client code I do something like this:
> >>> import bencode
> >>> data = [4456, 'Rakesh', 27]
> >>> bdata = bencode.bencode(data)
> >>> bdata
> 'li4456e6:Rakeshi27ee'
>
>
> Server gets back the list by:
> >>> bencode.bdecode(bdata)
> [4456, 'Rakesh', 27]
>
>
> How do I achieve the client part in golang? I know that there is bencode
> packages already written, but the trick here is how do I arrive at
> 'li4456e6:Rakeshi27ee' in golang by providing a sequence of elements of
> 'different data types' so that when server(written in python) does bdecode,
> it gets back list [4456, 'Rakesh', 27].
>
> I am writing only the client in golang and don't want to change anything
> on the server side.
>
> Regards,
> Rakesh
>
>
>
>
> --
> 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] Mirror of Go SSA

2016-06-16 Thread as . utf8
Have you tried to *go get golang.org/x/tools/go/ssa *?

On Wednesday, June 15, 2016 at 10:54:05 AM UTC-7, JW Bell wrote:
>
> >>I have to say that I don't see a big benefit to mirroring a github 
> repo on github itself. 
> There isn't another way to use the ssa package.
>
> On Tuesday, June 14, 2016 at 10:15:19 PM UTC-7, Ian Lance Taylor wrote:
>>
>> On Tue, Jun 14, 2016 at 7:07 PM,   wrote: 
>> > Mirror of the Go compiler SSA library -  https://github.com/bjwbell/ssa 
>> > The mirror is automatically updated daily. 
>> > 
>> > Any feedback is welcome. I'm unsure on the licensing requirements for 
>> > mirroring. 
>>
>> The license requirements in general are in the LICENSE file.  It's no 
>> different from mirroring than for any other use. 
>>
>> I have to say that I don't see a big benefit to mirroring a github 
>> repo on github itself. 
>>
>> 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: [ANN] primegen.go: Sieve of Atkin prime number generator

2016-06-16 Thread gordonbgood
No real surprises with the no bounds checks option (-B), it just eliminated the 
array bounds checks with the rest of the code the same (version 1.7beta1):

0x00dd 00221 (main.go:37)   MOVQDI, CX
0x00e0 00224 (main.go:37)   SHRQ$5, DI
0x00e4 00228 (main.go:37)   MOVL(AX)(DI*4), R9
0x00e8 00232 (main.go:37)   MOVQCX, R10
0x00eb 00235 (main.go:37)   ANDQ$31, CX
0x00ef 00239 (main.go:37)   MOVLR8, R11
0x00f2 00242 (main.go:37)   SHLLCX, R8
0x00f5 00245 (main.go:37)   ORL R8, R9
0x00f8 00248 (main.go:37)   MOVLR9, (AX)(DI*4)
0x00fc 00252 (main.go:36)   LEAQ3(R10)(SI*2), DI
0x0101 00257 (main.go:37)   MOVLR11, R8
0x0104 00260 (main.go:36)   CMPQDI, DX
0x0107 00263 (main.go:36)   JLS $0, 221

It is now almost as fast as C/C++ code, and isn't for the same reasons as 
explained before:  excessively using registers to store things and not using 
the read/modify/write instruction (which also saves the use of a register).

The current beta will work not too badly with amd64 code but still doesn't use 
registers efficiently enough to support x86 code as it uses too many register.  
optimized C/C++ code only uses six or at most 7 registers, which the x86 
architecture has, but not the nine registers that the above requires.

So for this tight loop, golang is still slower than optimized C/C++ code, but 
not by very much if array bounds checks are disabled.

-- 
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] context for user credentials

2016-06-15 Thread daviswahl
That's *really *not what you're supposed to use a context for. If you just 
want a grab bag for random values (and really, you don't), you can just use 
a map. 

A context is for sharing scoped data across APIs, threads, and other 
boundaries. The documentation says "request scoped" but that term can be a 
lot broader than simply a web server. I think that in this use, "scoped" 
means neither above nor below the scope of a request. Values stored within 
a context should be things like a requestUUID, which can be used to trace 
the request through the graph of your system, and even out into foreign 
systems, if they adapt themselves to accept some sort of context object.  

Or, it can be used to share a cancelation channel, which can be used to 
cancel any running go routines within the scope of the context. To do this 
without a context, you'd need to pass the cancel channel from one function 
to the next. 

With a context, you can group these very specific things into a convenient 
wrapper. You really don't want to start overloading that wrapper. Do you 
*really 
*want your user credentials available to every part of the system that your 
request touches? No. But you would probably like to have a cancelation 
channel available. 

If you just want a thing that you can shove random data into, there are 
plenty of other data structures available. A seriously caution you against 
going that route though because it only leads to misery.
On Wednesday, June 8, 2016 at 11:54:48 PM UTC-4, Ian Lance Taylor wrote:
>
> On Wed, Jun 8, 2016 at 7:44 PM,   
> wrote: 
> > 
> > Is storing user credentials in Context part of it's intended use? 
> > 
> > In my case there would be validation of the credentials and then storing 
> > more information in the context. 
>
> For something like a web server that serves requests for many users, 
> yes, storing user credentials in a Context would be a normal use. 
>
> > There seems to be a pretty gray line as to what should be a parameter 
> and 
> > what should go into Context? 
>
> Yes.  A Context can always be replaced by a list of arguments.  In 
> general, for something like a web server, it's reasonable to put 
> everything that is specific to a single request into a Context.  That 
> gives you a single value you can pass around.  It's particularly 
> useful for deadlines and for gathering request- or user-specific 
> stats.  In a large server, the advantage of a Context is that you can 
> add additional values as they become useful, without having to plumb 
> them through everywhere (because you've already plumbed the Context 
> everywhere anyhow). 
>
> 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] caching of cgo compilation

2016-06-15 Thread Ian Lance Taylor
On Wed, Jun 15, 2016 at 2:54 PM, Alex Flint  wrote:
> Under what conditions does a cgo package get recompiled? I am using
> go-sqlite3 and it appears that the C compiler/linker is run every time I
> build my project, even though I am not changing any of the C sources. I
> would have expected it to be run once and then the results re-used, but
> perhaps there are some special rules for cgo recompilation?

Currently the go tool either compiles an entire package or doesn't
compile it at all.  If it is a cgo package with .c files, it compiles
those .c files every time it thinks any part of the package needs to
be recompiled--e.g., if you changed the Go code.

I thought there was an issue open about that, but I couldn't find it.

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] Re: [ANN] reform, a better ORM, reaches v1, moves to gopkg.in

2016-06-24 Thread Tong Sun
Thanks for open up and sharing you fourth milestone Alexey. I have the 
following questions:

- how to define the relations between multiple tables?
- how to deal with the case that a table has a composite primary key 
instead of just a single-field primary key?

The answers are better in the readme as well, IMO. 

On Wednesday, June 22, 2016 at 9:23:39 AM UTC-4, Alexey Palazhchenko wrote:
>
> Hi, 
>
> reform, an ORM based on non-empty interfaces, code generation, and 
> initialization-time reflection, reached version 1. Code moved to 
> https://github.com/go-reform/reform, and canonical import path now is 
> gopkg.in/reform.v1. Expect new releases to be tagged, with proper 
> changelogs, and SemVer-compatible. One can build an own library on top of 
> it without fear of compatibility breaking. 
>
> See https://github.com/go-reform/reform/blob/v1-stable/README.md for 
> details. 
>
> –-– 
> Alexey «AlekSi» Palazhchenko 
>
>

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


Fwd: [go-nuts] How to init a global map

2016-06-24 Thread Tong Sun
*(Thanks a lot for all your help Val!)*

One last question, which I wasn't able to find myself from
https://blog.golang.org/go-maps-in-action

Since a map is a pointer, for any function that take map as a parameter,
or function like,

 func (s set) Something(xxx)

Does it means the map values can be changed inside the function?

If yes, what's the proper way to declare it so as to make sure the values
cannot be changed inside the function?

Thanks, and sorry if the question seems too dumb.


-- Forwarded message --
From: Valentin Deleplace @gmail.com
Date: Fri, Jun 24, 2016 at 2:11 AM
Subject: Re: [go-nuts] How to init a global map
To: Tong Sun @gmail.com

No penalty, passing a map around never copies the values.
But a "pointer to a pointer" receiver is not strictly the same as a pointer
receiver.
Le 24 juin 2016 02:19, "Tong Sun" a écrit :

>
> On Thu, Jun 23, 2016 at 6:54 PM, Val  wrote:
>
> Even in OO style (e.g. java), you would not be able to write
>>  Set s = null;
>>  s.init( list(1,2,3) );
>>
>> This is (more or less) the same problem with value receiver... the
>> "constructor-like" idiom in go is a function NewSet, not a method :
>
>  https://play.golang.org/p/_n56yMhlRt
>
>
> * Now* I understand the reason behind such idiom in go. Yep, everything
> makes sense now.
>
> Thanks a lot for the clear explanation.
> That really helps.
>
> Hmm... wait,
>
> map is a reference type
>
>
> Does that means that, this function
>
> func (s set) Has(a string) bool { _, ok := s[a]; return ok }
>
> is exactly the same as the following?
>
> func (s *set) Has(a string) bool { _, ok := (*s)[a]; return ok }
>
> I.e., even the set is super super big, there is no pass-by-value penalty
> in the first version?
>
> Thx
>
>

-- 
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: [ANN] Gomail v2: sending emails faster

2016-06-24 Thread Bernard LEGAUT
I recently switch from go 1.5.1 to go 1.6, and gomail seems to get in 
trouble. 

Anyone with the same issue ?

Thanks,





On Wednesday, September 2, 2015 at 8:55:26 AM UTC-3, Alexandre Cesaro wrote:
>
> Hi,
>
> I just released the second version of Gomail 
> .
>
> There are quite a few backward-incompatible changes 
>  since 
> Gomail v1 but it brings lots of good stuff:
>
>- A great focus was placed on performances. Gomail v2 is way more 
>efficient than Gomail v1 to send a large number of emails (see the 
>Daemon  
>or Newsletter 
> 
>examples).
>- The API is now clearer and way more flexible.
>- The documentation  improved 
>and many examples were added.
>- All existing issues have been closed.
>- The minimum Go version is now 1.2 instead of 1.3. No external 
>dependencies are used with Go 1.5.
>
> More info on Github: https://github.com/go-gomail/gomail
>

-- 
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] Does pprof enabled in production gives a significant impact in performance?

2016-06-23 Thread Marcos Oliveira
Gophers,

We are to deploy a service in production and there's the question if we 
should keep pprof and its HTTP handlers enabled by default in the service 
or if we should have a flag that enables them when needed, but that would 
require a restart of the service.

Is a significant performance impact if we keep it enabled all the time?

Thank you,

-- Marcos

-- 
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] GitHub Squash

2016-06-23 Thread Erik Aigner
Since GitHub now supports squash merging branches, wouldn't it be possible 
to switch the Review/CL system over to GitHub?

I think this would lower the entry barrier considerably for new 
contributors.

Cheers,
Erik

-- 
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] Why is Errorf() in the fmt packages and not in the errors package?

2016-06-23 Thread jamalsmith95 . bc
The title.

-- 
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] Automatic type assertion

2016-06-23 Thread Jose Luis Aracil

I use my own "automatic" type assertion library:

https://github.com/jaracil/ei

El jueves, 9 de junio de 2016, 22:39:46 (UTC+2), Pablo Rozas-Larraondo 
escribió:
>
> Sorry I should have been more clear exposing the problem. What I meant by 
> "automatic type assertion" was something like:
>
> If a is a variable of type interface{}:
> b := a.(a.(type)) as a way of getting a's value in its own type.
>
> As I'm writing this, I'm realising of the problem behind this though. The 
> type of b would be unkown and reflection ,or a type switch, would be 
> required to get its type again. So, there's no benefit in such a function I 
> guess.
>
> Thank you for your responses, sorry for the confusion and please comment 
> if you see it in a different way.
>
> Pablo
>
> On 10 Jun 2016, at 12:36 AM, Jan Mercl <0xj...@gmail.com > 
> wrote:
>
>
> On Thu, Jun 9, 2016 at 4:13 PM Pablo Rozas Larraondo <
> p.rozas@gmail.com > wrote:
>
> > Does anyone know the reason why Go doesn't offer an automatic type 
> assertion of an interface into its underlying type? I know this could be 
> achieved by using a type switch or safe type assertions (b, ok := a.(int)) 
> but I'm wondering why this operation was not simplified or included as a 
> function in the reflection package.
>
> Please elaborate a bit more on what do you mean by "automatic type 
> assertion" and please give some small example of how you would design the 
> language feature and/or the reflection package functionality. Thanks.
>
> -- 
>
> -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] Why is Errorf() in the fmt packages and not in the errors package?

2016-06-23 Thread Tamás Gulácsi
Formatting?
Tuning the question around: fmt.Errorf = errors.New(fmt.Sprintf) - just a 
convenience function.
GMT is quite heavy, errors is light.

-- 
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: Shuffle Items in a Slice

2016-06-24 Thread Val
2 implementations here : 
http://www.programming-idioms.org/idiom/10/shuffle-a-list/1564/go

As for the map iteration trick, the runtime doesn't guarantee to randomize 
anything, although it often tries to, so developers don't rely on some 
specific order. I've seen (in the past) some map iterations consistently 
not randomized at all. This behaviour may have evolved, but don't rely on 
it.


On Friday, June 24, 2016 at 1:05:49 PM UTC+2, dc0d wrote:
>
> Hi;
>
> To shuffle items in a slice I'm doing this:
>
> var res []Item
>
> //fill res logic
>
> shuffle := make(map[int]*Item)
> for k, v := range res {
>  shuffle[k] = 
> }
> res = nil
> for _, v := range shuffle {
>  res = append(res, *v)
> }
>
> Which inserts items into a map then ranges over that map. Ranging over a 
> map in Go returns the items in random order.
>
> 1 - I thought it's a cool trick!
> 2 - Is anything bad about doing 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.


Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Martin Geisler
On Fri, Jun 24, 2016 at 1:05 PM, dc0d  wrote:
>
> Hi;
>
> To shuffle items in a slice I'm doing this:
>
> var res []Item
>
> //fill res logic
>
> shuffle := make(map[int]*Item)
> for k, v := range res {
>  shuffle[k] = 
> }
> res = nil
> for _, v := range shuffle {
>  res = append(res, *v)
> }
>
> Which inserts items into a map then ranges over that map. Ranging over a map 
> in Go returns the items in random order.
>
> 1 - I thought it's a cool trick!
> 2 - Is anything bad about doing this?

While iteration over a map is said to be random, it isn't specified
exactly how "random" the iteration is. The spec says

  https://golang.org/ref/spec#RangeClause
  The iteration order over maps is not specified and is not guaranteed
to be the same from one iteration to the next.

That is, the iteration order should not to be relied upon. A simple test like

  https://play.golang.org/p/czRE3pbMzc

shows this: the keys are printed in a scrambled order. When I run this
on my machine, I get a different order every time, but on the
playground the order seems to be fixed and I get "0 5 7 1 2 3 4 6 8 9"
every time. My guess would be that an external input is used to
initialize the hash function used behind the scene -- and on the
playground that input somehow has a fixed value.

Unless you're build a toy application, my advice would be to use a
real random generator to generate indexes into the map. Use these
indexes to swap elements and permute the array as Konstantin mentioned
(https://en.wikipedia.org/wiki/Fisher–Yates_shuffle).

-- 
Martin Geisler

-- 
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: undefined: syscall.LoadLibrary

2016-06-24 Thread Konstantin Khomoutov
On Fri, 24 Jun 2016 03:22:23 -0700 (PDT)
Andrew Mezoni  wrote:

> >> So, how exactly does this method work with Linux shared libraries?
> 
> It does not work on Linux.
> On Linux you should use the methods:
> 
> dlclose, dlopen, dlmopen - open and close a shared object
> 
> http://man7.org/linux/man-pages/man3/dlopen.3.html

Note that these calls are provided by libc, not by the kernel (that's
why their manual pages are in section 3 BTW) so using them requires
using cgo -- contrary to syscall.LoadLibary() on Windows.

I don't know whether it's at all possible to have something like
dlopen() without touching libc on Linux (and other non-Windows
platforms) because that ultimately requires running the dynamic linker
program (well, at least that's my understanding).

-- 
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: can't get Content-Type and Content-Disposition to force browser to display "file->save..." dialog in the web browser

2016-06-24 Thread David Marceau
The core problem was:
w.Header().Set("Content-Disposition","attachment;filename=" + 
strOutputFileOfJournalctl)
Should actually be:
w.Header().Add("Content-Disposition","attachment;filename=" + 
strOutputFileOfJournalctl)

I preferred to put the above line before the serveFile.

That's all. Thanks to everyone who dropped by.

On Friday, June 24, 2016 at 9:44:00 AM UTC-4, David Marceau wrote:
>
> Here is what is in my import.  Maybe I should be looking in goji instead 
> of net/http?
>
 

>
> import (
> "fmt"
> "net"
> "time"
> "strconv"
> "strings"
> "os"
> "encoding/json"
> "net/http"
> "crypto/tls"
> "crypto/rand"
> "github.com/gorilla/mux"
> "github.com/goji/httpauth"
> "github.com/zfjagann/golang-ring"
> "github.com/kabukky/httpscerts"
> "reflect"
> "io"
> "io/ioutil"
> "path/filepath"
> "html/template"
> "os/exec"
> )
>
> On Friday, June 24, 2016 at 9:40:29 AM UTC-4, David Marceau wrote:
>>
>> I tried to repeat the same ordering as the iris infrastructure within the 
>> function, but it still behaves not as expected.  It does not show the 
>> file->save... dialog.  It shows the file within the browser as a web page.
>>
>> func blah (w http.ResponseWriter, r *http.Request) {
>> strOutputFileOfJournalctl = "journalctlLog.json"
>> w.Header().Set("Content-Type","application/octet-stream")  //forces 
>> the save as dialog
>>
>> strSomeStringInJsonFormat := "{ Blah: 'blah value' }"
>> myOutput := []byte(strSomeStringInJsonFormat)
>>
>> //ATTEMPT #1
>> //w.Write(myOutput) //displays in web browser page
>> //ATTEMPT #4
>> //w.Header().Set("Content-Disposition","attachment;filename=" + 
>> strOutputFileOfJournalctl)
>>
>>
>>
>> //ATTEMPT #3
>> //w.Header().Add("Content-Length", strconv.Itoa( len(myOutput) ) )
>> //w.Write(myOutput) //displays in web browser page
>> //w.Header().Set("Content-Disposition","attachment;filename=" + 
>> strOutputFileOfJournalctl)
>>
>>
>>
>> //ATTEMPT #2
>> w.Header().Add("Content-Length", strconv.Itoa(len(myOutput)) )
>> tmpFile, _ := ioutil.TempFile(os.TempDir(), "OurGeneratedCustomLog")
>> defer os.Remove(tmpFile.Name())
>> tmpFile.Write(myOutput)
>> tmpFile.Close()
>> http.ServeFile(w, r, tmpFile.Name())
>> //ATTEMPT #5
>> w.Header().Set("Content-Disposition","attachment;filename=" + "\"" + 
>> strOutputFileOfJournalctl + "\"")
>> }
>>
>>
>> On Friday, June 24, 2016 at 7:06:59 AM UTC-4, David Marceau wrote:
>>>
>>> Again, I want to clarify the file does arrive in the browser, but I want 
>>> to ensure the "file->save..." dialog appears in the web browser when it 
>>> arrives.  I found some older code I wrote a couple of years ago that was 
>>> behaving as expected:
>>> w.Header().Set("Content-Type", "application/octet-stream")
>>> w.Header().Set("Content-Disposition", "attachment; filename=" + 
>>> myBasePdf + ".pdf")
>>> http.ServeFile(w, req, myGenPdfFileName)
>>>
>>>
>>> I acknowledge when I wrote this email I made a typo, but in my code I do 
>>> have the Itoa correctly.
>>> w.Header().Set("Content-Length", strconv.Itoa( len(myCmdOutput) ) )
>>> I never used that content-length field because I read somewhere that I 
>>> shouldn't.
>>>
>>> Last night I took a look at iris to see how they do it and found:
>>> https://github.com/kataras/iris/blob/master/context.go#L583
>>> err := ctx.ServeFile(filename, false) 
>>> if err != nil { 
>>> return err 
>>> } 
>>>
>>> ctx.RequestCtx.Response.Header.Set(contentDisposition, "
>>> attachment;filename="+destinationName)
>>>
>>> I am scratching my head since the header set content-disposition is 
>>> happening after the ServeFile which is different from what all the docs and 
>>> what I am used to seeing.  It seems calling these functions are 
>>> order-independant.  When does the connection actually send the file over 
>>> the connection?
>>>
>>> I believe the Iris send file also provides what I want as expected 
>>> behaviour, but I haven't tried it yet.  
>>>
>>> On Thursday, June 23, 2016 at 6:15:16 PM UTC-4, Val wrote:

 The commented line seems to have typo strconv.Ito

 Maybe the typo prevents proper recompilation, and server goes on with 
 old code?

>>>

-- 
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] Shuffle Items in a Slice

2016-06-24 Thread dc0d
Thanks Val for explanation & clarification;

On Friday, June 24, 2016 at 5:24:30 PM UTC+4:30, Val wrote:
>
> The playground caches everything, so running multiple times the same 
> program will just serve the previously generated output.
>
> Also in the playground everything is frozen at some point in the past : 
> the clock, the randomness sources, and you can't make outgoing requests to 
> import randomness from the network.
>
> On Friday, June 24, 2016 at 2:47:13 PM UTC+2, dc0d wrote:
>  
>
>> Better be something wrong with playground! :)
>>
>>

-- 
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] Custom syscall.Sockaddr

2016-06-24 Thread Ian Lance Taylor
On Fri, Jun 24, 2016 at 8:05 AM,   wrote:
>
> I am trying to set up an interface from Go to SocketCAN
> (https://www.kernel.org/doc/Documentation/networking/can.txt).  This
> implements the linux socket interface, however it is a completely separate
> socket type from the regular AF_INET or AF_UNIX socket types.
>
> The sockaddr struct for SocketCAN looks like this:
>
> struct sockaddr_can {
> sa_family_t can_family;
> int can_ifindex;
> union {
> /* transport protocol class address info (e.g. ISOTP) */
> struct { canid_t rx_id, tx_id; } tp;
>
> /* reserved for future CAN protocols address information */
> } can_addr;
> };
>
>
> Since the union only has one possible entry right now, this is easy enough
> to write in Go
>
> type CanID uint32
>
> type sockaddrCan struct {
>Family  uint16
>IfIndex int32
>TpRxId  CanID
>TpTxId  CanID
> }
>
>
> Everything is straight forward so far, but now if I want to pass this to
> different syscall functions ( syscall.Bind, syscall.Connect, etc.) I have to
> implement the syscall.Sockaddr interface, however looking in the code I see
> this:
>
> type Sockaddr interface {
> sockaddr() (ptr unsafe.Pointer, len _Socklen, err error) // lowercase;
> only we can define Sockaddrs
> }
>
>
> So, finally the questions:
>
> Why is this interface private? It says that it is, but provides no
> rationale.
> Does this mean that I have to reimplement all the functions syscall
> functions using raw syscall.Syscall?  Or is there some clever way around
> this so I can use the syscall package to make a Sockaddr type that is not
> already defined.

If this is going to be a standard thing in future Linux kernels, I
suggest that you add support for it to the golang.org/x/sys/unix
package.

I don't actually know the answer to why Sockaddr has a private method.
I agree that it doesn't seem strictly necessary.

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] How to be safe in Go?

2016-06-24 Thread Nick Pavlica


On Thursday, June 23, 2016 at 6:44:22 PM UTC-6, Caleb Spare wrote:
>
> > To see if the the 
> > race detector would find this potential bug for me, I ran the code with 
> the 
> > mutex(s) commented out with the  -race flag on and didn't get a warning. 
>
> Did you make some concurrent requests? The race detector only tells 
> you about races that happen, so you need to excercise the concurrent 
> code paths in some way (possibly in a test or by selectively turning 
> on -race in a production-like environment). 
>

  I just accessed the endpoint from multiple browsers, but no formal tests.
 

>
> A couple of general thoughts: 
>
> (1) The primary way to know whether a library you're using will call 
> your code concurrently from multiple goroutines is via documentation. 
> The net/http documentation, for instance, explains that Serve creates 
> a goroutine for each connection. Any other library you use should 
> clearly explain this if it's the case. 
>

  That makes sense, but seems to be a little fragile.  For example, if the 
lib wasn't originally concurrent, then is changed, it would be easy to get 
into a bad situation.  It makes me want to just wrap every variable in a 
Mutex to be safe.  I'm guessing that the pattern is to keep Go programs as 
small as possible so you can track all the corner cases effectively in your 
own mental model. 


> (2) net/http and other server packages are a slightly unusual case -- 
> there are many libraries that exist, but most don't call your code 
> concurrently. (Even packages that invoke provided callbacks are 
> themselves a minority.) If I use a package that, say, interfaces with 
> a database or implements a graph algorithm, it would be quite strange 
> if it used concurrently-invoked callbacks. 
>

As I ponder this; I wounder if some tooling could be added to the compiler 
or an outside utility that would scan all the used libraries, and notify 
you that the libraries/functions are concurrent. 

For example:

go run --chk_concurrent  mylib.go

Notice: "net/http" calls concurrent operations on the Handle function.


Thanks again for the feedback!
--Nick

-- 
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] generating interfaces from proto3 (grpc)

2016-06-18 Thread Sankar
Hi

I've a proto3 file:

==
message Any {
}

message InsertParams {
Any Record = 1;
}

service myService {
rpc Insert (InsertParams) returns (InsertResponse);
 }


where I have an "Insert" API which expects a InsertParams struct as the 
parameter. However, the InsertParams struct has a Record field, that is 
needed to work across any datatype (a byte array, struct, string, int, 
etc.).

So, I created an Any type of message in the proto file. However, the 
generated _pb.go file is making the "Any" as a struct instead of an 
interface.

Is there any way to define a proto grpc API which will work across a 
generic type of parameter ?

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] Powersets and append() confusion

2016-06-18 Thread Oliver Schmid
Hi. I made a string only version of the powerset function on Rosetta Code 
 and ran into a bug where a 
slice input to *append()* [one, two, three, four] seems to be replaced by 
[one, two, three, five]. What.

Here's the bug on the Go Playground 

The subset that gets replaced is the subset right before the subset [five], 
based on how this powerset algorithm works (by appending to all previous 
subsets) this should be [one, two, three, four] but instead it's [one, two, 
three, *five*]. This replacement later on creates the element [one, two, 
three, five, five] which isn't even a subset.

I may have misunderstood the semantics of append() but if someone else 
could take a look and explain it to me it'd be greatly appreciated. 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] Powersets and append() confusion

2016-06-18 Thread Jakob Borg
2016-06-18 19:16 GMT+02:00 Oliver Schmid :
> Hi. I made a string only version of the powerset function on Rosetta Code
> and ran into a bug where a slice input to append() [one, two, three, four]
> seems to be replaced by [one, two, three, five]. What.

Note that append() doesn't necessarily return a copy of the slice - if
there is capacity in the underlying array it is modified in place and
the length of the slice is incremented. You'll often get a slice with
extra capacity from append(). Ponder the following:

https://play.golang.org/p/1aKGTmw68t

//jb

-- 
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: Testing best practice: passing and failing test

2016-06-17 Thread paraiso . marc
By the way, Go 1.7 support subtests :

https://tip.golang.org/pkg/testing/#hdr-Subtests_and_Sub_benchmarks

Which is one of the nicest additions to Go 1.7 

Le jeudi 16 juin 2016 16:04:11 UTC+2, Rayland a écrit :
>
> Let's say I have some piece of code like this:
>
> type Foo struct {
> }
>
> func (this *Foo) Do() {
> }
>
>
> If I want to test that method Foo will pass in a certain scenario and fail 
> in another scenario should I have a test for each scenario or should I have 
> all scenarios tested in a method TestFoo_Do()?
>
>
>
>

-- 
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: [ANN] primegen.go: Sieve of Atkin prime number generator

2016-06-17 Thread
On Friday, June 17, 2016 at 3:52:27 PM UTC+2, gordo...@gmail.com wrote:
>
> I don't see the point of the exercise other than it proves that not 
> putting the result of an operation back into the same register reduces the 
> latency slightly for your processor (whatever it is?); I suspect that if 
> you used any other register such as the unused AX register rather then the 
> R11 register, the results would be the same. 
>

Why do you see no point of the exercise and at the same time you do see the 
point of optimizing 1.7beta1 code? What is the difference?

What would be interesting is to compare the run time on your processor with 
> the same eratspeed program written in golang using version 1.7beta1 with 
> and without array bounds checks.

-- 
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] When should I use the connection pool?

2016-06-17 Thread cydside
Hi to all,
I'm new here and using golang too. I've read some articles and post on 
Connection Pooling" but I'm still confused. What I'm looking for is a rule 
of thumb that make me easy to decide when use connection pool. My scenario 
isn't so complicated: 

 - a web application that makes CRUD operations on a Postgres database.
 - Minimun 10 clients connected up to 30.

Moreover, I'm going to use pgx driver. I'd be grateful if you could help me 
to get the difference from use or not the connection pool, which is the 
best practice?

Thanks in advance,

Danilo

-- 
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] Gomobile: Large .so/aar file sizes on Android

2016-06-17 Thread rajiivkanchan
Hi All
I am using Go version 1.6.2 and Gomobile (sha +6b7a416 from the tip) and to 
build an Android library. Our code is mostly networking 





"encoding/json"
"fmt"
"log"
"math/rand"
"net"
"sort"
"time"

-- 
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] export struct method to C-code as callback (cgo-related)

2016-06-17 Thread andrey
Hello,

Could you guys please help me. 

I can't find how to export method function which belongs to some go-struct 
to C-code (cgo part) as callback. I know how to export simple function 
which not belongs to any type and use it as callback for C-function, but is 
it possibly to export method of concrete struct instance? since I need 
additional info when callback will be called from C-code. As example what 
I'm trying to explain:

// extern int goCallbackHandler(int, int); static int doAdd(int a, int b) 
{// return goCallbackHandler(a, b);// }

import "C"

type A struct {
... some data which used to process callback from C-side
}

// export cgo_callback
func (a *A) cgo_callback(...){ <-main problem here
}

main {
   C.doAdd(...)
}

I can't modify c-side - I have only compiled library, so I don't know how 
to identify which instance of struct should be used to properly process 
C-call of go-side callback.

Thanks,
Andrey

-- 
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: [ANN] primegen.go: Sieve of Atkin prime number generator

2016-06-17 Thread gordonbgood
I don't see the point to the exercise as far as optimizing golang is concerned. 
 Your experiment just shows that Your compiler (GCC?) missed an optimization as 
far as reducing backend latency goes.

You may also find that swapping the order of some of the instructions such as 
the second and the third in the loop may also reduce backend latency further.

I am not on a high end Intel CPU now, but when I was I found that with a buffer 
size adjusted to the L1 cache size (8192 32-bit words or 32 Kilobytes) that 
eratspeed ran on an Intel 2700K @ 3.5 GHz at about 3.5 clock cycles per loop 
(about 405,000,000 loops for this range).

My current AMD Bulldozer CPU has a severe cache bottleneck and can't come close 
to this speed by a factor of about two.

-- 
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: importer.Default not able to find packages in $GOPATH

2016-06-17 Thread adonovan via golang-nuts
On Friday, 17 June 2016 15:21:55 UTC-4, Joshua Liebow-Feeser wrote:
>
> Hi All,
>
> I'm trying to use the go/* packages to parse and type check Go source 
> code. I've downloaded github.com/coreos/etcd to test this on, and I'm 
> currently trying it out in the etcdserver subdirectory. When I run 'go 
> build' everything works fine, but when I try to type check, none of the 
> imports are found.
>

Try running 'go install' or 'go build -i' on the packages you want to 
analyze.

The default importer works great for packages in the standard 
library, which are always available in compiled form, but poorly for user 
packages, for which it may have been days or weeks since the most recent 
install.  Take a look at the golang.org/x/tools/go/loader package, 
which loads all packages from source.

Also, you may find this tutorial helpful: 
https://github.com/golang/example/tree/master/gotypes

-- 
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] encoding/json: any way to receive number literal "10.0" into integer field?

2016-06-17 Thread jonathan
Thanks -- I should have clarified that we've ruled that option out (it
was our first approach), since we want to stick to the built in types
that won't require explicit exchange with the primitive types.

jonathan

On Fri, Jun 17, 2016 at 02:56:49PM -0700, Edward Muller wrote:
> AFAIK (and someone will probably provide something better) you need to do 
> something like this: 
> 
> https://play.golang.org/p/riq-m6cgZu
> 
> > On Jun 17, 2016, at 2:37 PM, jg...@bitgirder.com wrote:
> > 
> > We have an upstream provider of JSON data which sends integer data
> > types as floating point literals with a "0" decimal part. By default
> > json.Decoder doesn't allow this and fails:
> > 
> >https://play.golang.org/p/MEJlg1n3vs
> > 
> > Unfortunately this provider is almost certain not to change this, and
> > so we just have to deal with it as clients of their API. What are some
> > ways we could handle this?
> > 
> > Things that come to mind:
> > 
> >- Submit a change to encoding/json that allows us to set some sort
> >  of number processing function to customize its behavior (or to
> >  set some sort of policy which allows number literals ending in
> >  \.0*$ for integer targets)
> > 
> >- Create a custom io.Reader which wraps in input stream by reading
> >  individual tokens from it using an internal json.Decoder, and
> >  then emits number literals without trailing ".0". 
> > 
> >- Buffer all inbound decodes into a map[string]interface{} and set
> >  the decoder to UseNumber(), and then replace those json.Numbers
> >  with corrected ones, then serialize back and decode once more
> >  into the destination (this is similar to the token-stream
> >  approach above)
> > 
> > Are there other approaches I'm overlooking?
> > 
> > jonathan
> > 
> > -- 
> > 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] How to init a global map

2016-06-23 Thread Tong Sun
I did tried to change to,

func (s *set) Init(slice []string) {

but that gave loads of errors that I can't fix, hence the question.


On Thu, Jun 23, 2016 at 6:19 PM, Val  wrote:

> Assigning a value to the receiver will only affect local variable.
> Try pointer receiver.
>
> --
> 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/rssS79X7aUs/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.
>

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


Fwd: [go-nuts] How to init a global map

2016-06-23 Thread Tong Sun
Is it possible to fix and make the

*validSub.Init*([]string{"aa", "bb", "cc"})

works instead?

Coming from the OO world, this is a form that I feel more comfort with.

Thx.

-- Forwarded message --
From: andrey mirtchovski 
Date: Thu, Jun 23, 2016 at 6:16 PM
Subject: Re: [go-nuts] How to init a global map
To: Tong Sun 


if you just want to fix it:

https://play.golang.org/p/cL0svI8FU4

On Thu, Jun 23, 2016 at 4:12 PM, Tong Sun  wrote:
> My mind is not working and I can't find how to fix the following program
> (https://play.golang.org/p/oXxUndUSye):
>
>
> package main
>
>
> import (
>  "fmt"
> )
>
>
> type set map[string]struct{}
>
>
> var validSub set
>
>
> func init() {
>  validSub.Init([]string{"aa", "bb", "cc"})
>  fmt.Printf("%+v\n", validSub)
> }
>
>
> func (s set) Init(slice []string) {
>  s = make(map[string]struct{}, len(slice))
>  for _, s1 := range slice {
>  s[s1] = struct{}{}
>  }
> }
>
>
> func (s set) Has(a string) bool { _, ok := s[a]; return ok }
>
>
> func main() {
>  fmt.Println(validSub.Has("aa"))
>  fmt.Println(validSub.Has("dd"))
> }
>
>
>
> Please 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.

-- 
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: [?] emulating an opengl shader in cpu bound functions

2016-06-23 Thread blueblank


On Wednesday, June 22, 2016 at 5:06:38 PM UTC-4, blue...@gmail.com wrote:
>
>
> 
>
>
> Thanks for all the suggestions especially Egon, that put me ahead of my 
> learning curve.
>
> I put most of the art pipeline I'm developing here:  
> https://github.com/thrisp/art
>
> includes the Cosmic filter/shader I opened with here. 
>




And forget that, its far from being something I'd like to release clean:

here's the final for now as far I'm concerned its useful enough for now:

https://gist.github.com/thrisp/3cd7c90353e8990bab7992fb6b8e089c
 

-- 
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] Why is Errorf() in the fmt packages and not in the errors package?

2016-06-23 Thread Rob Pike
To avoid a dependency cycle. fmt depends on errors, so errors can't call
functions in fmt.

-rob


On Thu, Jun 23, 2016 at 1:15 PM,  wrote:

> The title.
>
> --
> 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: x/mobile: How to generate a builtin error type binding by gobind command?

2016-06-27 Thread Elias Naur
You can't, at least not yet. The use of the builtin error type is an 
implementation detail of CL 24100 which is about how errors and exceptions 
are represented in the generated bindings. The CL does make the path toward 
exposing error to the native languages easier in the future.

 - elias

On Monday, June 27, 2016 at 4:16:40 PM UTC+2, tenntenn wrote:
>
> Hi, all.
>
> In order to understand how gomobile bind works, I tried to run commands 
> (gobind, go build and etc.) step by step.
> But I could not generate a builtin error type binding by gobind command.
> This change makes to be able to generate builtin error type bindings by 
> gomobile bind command.
> https://go-review.googlesource.com/#/c/24100/
>
> How can I generate a builtin error type binding by gobind command?
> I think that gobind command also should be fixed to accept nil package 
> (universe scope).
>
> 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] TLS

2016-06-27 Thread Konstantin Khomoutov
On Mon, 27 Jun 2016 20:04:52 +0600
Oleg Puchinin  wrote:

> Thank you, Dave !
> Mybe you have simple sample for my ?
> Server and client initialization.

Sure, the standard package crypto/tls has tests, and your installation
of Go comes with full source code of the Go standard library.

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

2016-06-27 Thread Sam Whited
On Mon, Jun 27, 2016 at 9:42 AM, Konstantin Khomoutov
 wrote:
> Sure, the standard package crypto/tls has tests, and your installation
> of Go comes with full source code of the Go standard library.

Reading the source is not the same as documentation or examples;
please don't confuse the two. This is an easy way to drive away new
users who may not have the experience to be digging around in the
standard library source (no matter how accessible it is).

> On Mon, 27 Jun 2016 20:04:52 +0600 Oleg Puchinin  
> wrote:
> Mybe you have simple sample for my ?
> Server and client initialization.

If you look at the documentation for the tls.Dial method
(https://godoc.org/crypto/tls#Dial) there is an "Example" link just
below the method description.

—Sam


-- 
Sam Whited
pub 4096R/54083AE104EA7AD3
https://blog.samwhited.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] Trying to dynamically find interfaces

2016-06-27 Thread Jan Mercl
On Mon, Jun 27, 2016 at 4:16 PM David Koblas  wrote:

type BaseAppController struct {
*Application
IGet
IList
}

The above means that every instance of BaseAppController satisfies both the
IGet and IList interfaces and that is known statically at compile time. I
don't understand why the code tests for that at run time. However, beware
that even though the interface is implemented by embedding a field of an
interface type, without setting that field to something actually handling
the method call you will get the panic(s) as you described.

"Subclasses" and parent/child type relations make little sense in Go
because composition is not inheritance. Yes, the methods of embedded fields
are merged to the method set of the embedding struct, but there the story
ends. Method set per se does not handle any actual method calls. There must
be always a real instance of a specific type that has the method. Note:
typed nil is a real instance of a type that can handle method calls, as
long as it does not try to dereference its receiver. But the zero value of
an embedded interface is not a real instance of any specific type.

-- 

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


Re: [go-nuts] Re: Trouble querying REST API with net/http (api verified working with curl)

2016-06-27 Thread Kiki Sugiaman

Haha! Happens to the best of us every once in a while.


On 28/06/16 02:57, mark mellar wrote:
ksug, you were right... I was able to replicate the error using curl 
by changing the -x parameter from 'GET' to 'Get' .


How embarrassing, I'll go sit in the corner and think about what I've 
done...


Thanks for your help guys!

Mark.

On Monday, June 27, 2016 at 7:12:59 AM UTC+1, ksug wrote:

I know this is a bit late, so perhaps you don't care anymore...

Anyway, the server may not understand the "Get" method in this line:
|req, err := http.NewRequest("Get",
"https://"+host+".here.com:443/rest/json/flows
", nil)
|


On 27/06/16 08:22, mark mellar wrote:

For anyone else having similar issues, I found I was able to work
around this by using client.Get() rather than client.Do().

Still not sure what the root cause is though...

Cheers.

On Friday, June 24, 2016 at 7:32:36 AM UTC+1, mark mellar wrote:

Good tip on using httputil to inspect the request!
Unfortunately I'm not seeing anything obviously wrong...

Using curl -v

*   Trying ...
* Connected to host.here.com  ()
port 443 (#0)
* TLS 1.0 connection using TLS_DHE_RSA_WITH_AES_256_CBC_SHA
* Server certificate: host
> GET /rest/json/flows HTTP/1.1
> Host: host.here.com 
> User-Agent: curl/7.43.0
> Accept: */*
> Cookie:

connect.sid=s%3AeQ30DeGtFyrhrntWofMWpGXo.%2F745zwxR0ErYrpnoVDklkt%2F7H9FX5GfcroBFXg5M6Ag

> Content-Type: application/json


using httputil.DumpRequestOut

Get /rest/json/flows HTTP/1.1

Host: host.here.com:443 

User-Agent: Go-http-client/1.1

Content-Type: application/json

Cookie:

connect.sid=s%3A%2FWuxV7HdAnHDweXFvs4N8%2BaB.DuNDxfVN6sLhLO%2Flu3hIY7PfUnfMquyRIfXSllGtZpM

Accept-Encoding: gzip


I'm suspicious about the Accept-Encoding field. I tried
twiddling DisableCompression in my transport but nothing
changed...

Cheers,

Mark

On Friday, June 24, 2016 at 5:46:06 AM UTC+1, Tamás Gulácsi
wrote:

Just a blind shoot into the darkness: try to use one
(global) http.Client! Also, you can ask curl to dump the
request, and net/http/httputil also to compare them.

-- 
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] Re: formal verification in Go? someday perhaps?

2016-06-27 Thread Scott Cotton
I don't see why not either.

I think what's missing for targeting go is this:

A library taking ssa representation and producing formal representations
(formulae, transition systems, models of
parallelism,...)

I guess that may actually be many libraries, as there are many different
ways to model.  but starting out with some basics could go a long way.  bit
blasting code with no concurrency into a transition system is an obvious
starting point.
modelling the concurrency in some clean, symbolic or compact way to
represent all possible interleavings would enable lots of possibilities
downstream (spin,smt, and the go tools that are starting to show up).



2016-06-28 0:24 GMT+02:00 Daniel Skinner :

> > I think a better question is:  can go tools for formal verification
> become available?
>
> I did some research on formal verification recently, no experience
> previously. I don't really see why not. Just digging through my own code, I
> have an implementation of the simplex method which I could use to solve
> boolean and integer linear optimizations. Gonum likely has better
> optimizers up for the tasks, though i haven't looked.
>
> It just seemed like the most difficult part would be providing an
> intuitive way of defining the problem given a domain. Of course, static
> analysis is great too and you made me curious, what's missing from the `go`
> package to go that route?
>
> On Sun, Jun 26, 2016 at 3:49 PM  wrote:
>
>> I think a better question is:  can go tools for formal verification
>> become available?  The distinction is that formal verification tools can be
>> applied to
>> hardware, protocols, assembly, software, etc.   Why not do that in go?
>>
>> Most such tools are in C or C++, and the low level engines/components are
>> highly optimised.  Go can easily compete with "standard" C/C++, i.e.
>> software which has not been highly optimised.  It also provides enough
>> low-level access to be competitive against highly optimised C/C++ (e.g.
>> assembly, precision of memory representations) but it takes work.
>>
>> One of the research initiatives we are taking up is "scalable cloud
>>  architectures for formal technologies".  Basically, composable cloud
>> microservices for formal technologies like model checking, SAT/BDD/SMT,
>> theorem proving, as well as encoders for verification problems, etc, but in
>> terms of deployment in the cloud.  A related startup is satalia.  Go is a
>> natural fit for this initiative, and we already have some results with go.
>>
>> I think the biggest obstacle to formal tools targeting analysis of go
>> programs is formal representations in the golang "go" package.  Once that
>> is available, things will start to snowball.
>>
>>
>>
>>
>>
>> Le lundi 9 mars 2015 01:07:36 UTC+1, Camilo Aguilar a écrit :
>>>
>>> I ran across this post today:
>>> http://blog.adacore.com/testing-static-formal. Basically, showing how
>>> you can do formal verifications in ADA2012. Is it realistic to think that a
>>> feature like that would someday arrive to Go?
>>
>> --
>> 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.
>>
>


-- 
Scott Cotton
President, IRI France SAS
http://www.iri-labs.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] Re: x/text/runes: How can i replace LF by CRLF ?

2016-06-25 Thread mhhcbon
Thanks ! Works for me. I m looking forward to implement text stream 
processing. Next time maybe !

-- 
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] Unused var written in closure

2016-06-25 Thread Val
Hello
It seems that this code  doesn't 
compile :

func main() {
var err error
err = f()
}

*prog.go:8: err declared and not used*


but this one  does :

func main() {
var err error
g := func() {
err = f()
}
g()
}

Is the function binding regarded as a "use"?  Or does escape analysis 
decide to not check too deep about never-read variables?

Whether expected or not, I supposed this compiler behavior won't change, 
because of the Go1 compatibility promise.

Cheers
 Val

-- 
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] cgo not building on darwin

2016-06-25 Thread Michael Soulier
Experimenting with a little cgo, I did this

package main

/*
#include 
#include 
static void _FD_SET(int sysfd, void *set) {
FD_SET(sysfd, (fd_set*)set);
}
*/
import (
"C"
"unsafe"
"syscall"

...etc

Unfortunately, I'm getting this on my Mac when I try to build.

msoulier@merlin:~/work/go$ go install github.com/msoulier/mlogd
# github.com/msoulier/mlogd
could not determine kind of name for C._FD_SET

If I seperate the import it gets worse

package main

/*
#include 
#include 
static void _FD_SET(int sysfd, void *set) {
FD_SET(sysfd, (fd_set*)set);
}
*/
import "C"

import (
"unsafe"
"syscall"
"strings"

msoulier@merlin:~/work/go$ go install github.com/msoulier/mlogd
# github.com/msoulier/mlogd
could not determine kind of name for C._FD_SET

clang errors for preamble:
src/github.com/msoulier/mlogd/mlogd.go:6:21: error: expected identifier or 
'('
static void _FD_SET(int sysfd, void *set) {
^
src/github.com/msoulier/mlogd/mlogd.go:6:21: error: expected ')'
src/github.com/msoulier/mlogd/mlogd.go:6:20: note: to match this '('
static void _FD_SET(int sysfd, void *set) {
   ^
2 errors generated.

I think I'm following the rules of cgo. 

What am I doing wrong?

Mike

-- 
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] golang poll/epoll/select

2016-06-25 Thread Janne Snabb
On 2016-06-25 22:59, Michael Soulier wrote:
> I'm curious as to what I'm doing wrong with select here, and if it's
> possible to do this with a goroutine like you describe.

You should not be using select in the first place. You are making things
complicated for no reason whatsoever. (If I understand your intention
correctly.)

You should just read from os.Stdin. It will block until there is
something to read (unless you did something special to set it in
non-blocking mode). Check for EOF to know when to quit reading. Use a
goroutine if you need to do something else while the read is blocked. If
you do not need to do something else, you do not need a goroutine. Just
a plain and simple read loop.

Janne Snabb
sn...@epipe.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] small defect in os.exec.LookPath

2016-06-25 Thread mhhcbon
Ahm. Very subtle.

Changed it to 

bin := ""
bin, err = exec.LookPath(os.Args[0])
if err == nil {
wd = filepath.Dir(bin)
}


thanks for the feedback!

Le dimanche 26 juin 2016 00:00:51 UTC+2, Jan Mercl a écrit :
>
> On Sat, Jun 25, 2016 at 11:19 PM mhhcbon  > wrote:
>
> > bin, err := exec.LookPath(os.Args[0])
>
> Note that this err variable is shadowing the one declared previously.
>
> -- 
>
> -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.


Re: [go-nuts] small defect in os.exec.LookPath

2016-06-25 Thread Jan Mercl
On Sat, Jun 25, 2016 at 11:19 PM mhhcbon  wrote:

> bin, err := exec.LookPath(os.Args[0])

Note that this err variable is shadowing the one declared previously.

-- 

-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] [ANN] go-msi: generate msi package with ease

2016-06-25 Thread mhhcbon
Hi,

I have released a project to easily generate MSI package on top of wix.

I made it primarily to enhance usability of my Go packages, but it can be 
used for non go projects too.

It can handle multiple directories, multiple files, environments variable, 
and shortcuts.

https://github.com/mh-cbon/go-msi

As a first result,
https://github.com/mh-cbon/go-msi/releases/tag/0.0.17

I include two specifics recipes for unix users, like me in fact,

- Using Appveyor : 
https://github.com/mh-cbon/go-msi/blob/master/appveyor-recipe.md
- Using a vagrant box : 
https://github.com/mh-cbon/go-msi/blob/master/unice-recipe.md

I hope you ll find interest into that to share your bin with non go 
developers.

Looking forward for deb and rpm packaging!

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

2016-06-25 Thread Tamás Gulácsi
Start with https://github.com/lox/cachecontrol

-- 
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] small defect in os.exec.LookPath

2016-06-25 Thread mhhcbon
Hi,

i notice a case where LookPath is not really looking for PATH.

I have a bin with some files along it, i need to get its path at runtime to 
find the other files.

I use a func like this, minus the fmt prints


func getBinPath() (string, error) {
  var err error
  wd := ""
if filepath.Base(os.Args[0]) == "main" { // go run ...
wd, err = os.Getwd()
} else {
  bin, err := exec.LookPath(os.Args[0])
  if err == nil {
  wd = filepath.Dir(bin)
  }
}
  fmt.Printf("%q\n", wd)
  fmt.Printf("%q\n", os.Args)
return wd, err
}

When i run the command from a lambda dir, things are good,

C:\>go-msi generate-templates -h
"C:\\Program Files\\go-msi"
["go-msi" "generate-templates" "-h"]

Now the case where LookPath behaves unexpectedly occurs when i run the same 
from command, from a directory where a `go-msi.exe` file exists

C:\vagrant>go-msi generate-templates -h
"."
["go-msi" "generate-templates" "-h"]

It is unexpected in the sense that PATH does not contains '.' (C:\vagrant\ 
in that case).

Looks like LookPath is looking for '.' by itself.

C:\>echo %PATH%
C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\MakeMsi\;
C:\Program Files (x86)\WiX Toolset v3.10\bin;
C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\MakeMsi\;
C:\ProgramFiles (x86)\WiX Toolset v3.10\bin;
C:\wix310;
C:\Program Files\go-msi\


I guess if LookPath would search '.', after PATH, i would not have noticed 
this behavior.

-- 
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 proxy ?

2016-06-27 Thread Caleb Doxsey
For postgres use pgbouncer. For mysql there's youtube's vitess.

On Monday, June 27, 2016 at 12:24:32 PM UTC-4, Tieson Molly wrote:
>
>
> Are there any existing packages or libraries that implement a generic 
> database/sql proxy?
>
> My goal was to create a small service that connected to the database and 
> implemented a connection pool.
>
> Then other services would proxy their database/sql calls to this service 
> rather than make their own connection to the database.
>
>
> Best regards,
>
> Ty
>

-- 
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] File method WriteString frequent calls led to a large system cache

2016-06-27 Thread Tamás Gulácsi
Don't Stat on every log line, but use some other mechanism (mutex, channel) to 
rotate the logs every day.

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


[go-nuts] Re: Go application hanging and throwing Proxy error: Request Canceled or I/O timeout

2016-06-28 Thread Dave Cheney
Your application has probably run out of file descriptors. 

On linux you can get a sense of the number of active file descriptors your 
program is using by looking in the /proc/$PID/fd directory. Where $PID is 
the process id of your program.

/proc/$PID/limits will tell you the current limits for that process.

On Tuesday, 28 June 2016 14:25:56 UTC+10, dkbala...@gmail.com wrote:
>
> I am currently facing an issue in my load environment during the load 
> testing. The description of the issue is given below,
>
>
> We have a Jersey REST application which is being guarded by a GO 
> application. GO app validates the browser cookie and creates a single host 
> reverse proxy and serve the request if its a valid one, Initially we got 
> the below error 
>
> http: proxy error: dial tcp HOSTNAME:PORT can't assign requested address
>
>
> Even after upgrading it to 1.6, the same issue is happening but GO App log 
> shows the below error
> "http: proxy error: net/http: request canceled"
>
>
> I've enabled the DisableKeepAlives and performed the load testing and the 
> same issue is happening, Now Go app shows the below errors.
>
> http: proxy error: dial tcp HOSTNAME:PORT: i/o timeout
> http: proxy error: net/http: request canceled
>
>
> Code snippet for creating proxy is given below
>
>
> var proxy = httputil.NewSingleHostReverseProxy(proxy_url)
> http.DefaultTransport.(*http.Transport).DisableKeepAlives = true
>
>
> We use proxy.ServeHttp after we validate the request.  Normally the above 
> proxy error is not occurring suddenly but it occurs after 2 or 3 hours 
> after which load testing is started
>
> After disabling keep alive connection, we see lots of TCP connecion in 
> TIMED_WAIT state but its not getting closed but the application is hanging 
> and see the proxy error in the log.
>
>
> So we have to either call 
> https://golang.org/pkg/net/http/#Transport.CloseIdleConnections or 
> increase MaxIdleConnsPerHost to some higher value to fix this issue.
> The same test cases were working fine in the past but its failing now 
> suddenly.
>
> Appreciate your 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] Re: Shuffle Items in a Slice

2016-06-28 Thread Kaveh Shahbazian
Thanks for the reference! BTW I love this behaviour!

On Tue, Jun 28, 2016, 00:14 Chris Hines  wrote:

> The history of this behavior is explained in the release notes for Go 1.3:
> https://golang.org/doc/go1.3#map
>
>
> On Friday, June 24, 2016 at 8:48:20 AM UTC-4, Val wrote:
>>
>> 2 implementations here :
>> http://www.programming-idioms.org/idiom/10/shuffle-a-list/1564/go
>>
>> As for the map iteration trick, the runtime doesn't guarantee to
>> randomize anything, although it often tries to, so developers don't rely on
>> some specific order. I've seen (in the past) some map iterations
>> consistently not randomized at all. This behaviour may have evolved, but
>> don't rely on it.
>>
>>
>> On Friday, June 24, 2016 at 1:05:49 PM UTC+2, dc0d wrote:
>>>
>>> Hi;
>>>
>>> To shuffle items in a slice I'm doing this:
>>>
>>> var res []Item
>>>
>>> //fill res logic
>>>
>>> shuffle := make(map[int]*Item)
>>> for k, v := range res {
>>>  shuffle[k] = 
>>> }
>>> res = nil
>>> for _, v := range shuffle {
>>>  res = append(res, *v)
>>> }
>>>
>>> Which inserts items into a map then ranges over that map. Ranging over a
>>> map in Go returns the items in random order.
>>>
>>> 1 - I thought it's a cool trick!
>>> 2 - Is anything bad about doing this?
>>>
>> --
> 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/UIYHKFeIf_k/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.
>
-- 
Regards,
Kaveh Shahbazian

-- 
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: x/text/runes: How can i replace LF by CRLF ?

2016-06-28 Thread mpvl
This does not work in cases where someone want to use a Transformer in a
streaming context (e.g. to create a Reader or Writer or to include the
Transform in a Chain).

It may we useful to add something like strings.Replacer in runes as well.

Alternatively, I have once implemented a generic rewriter for package runes
that makes it much easier to create a Transform for arbitrary rewrites than
writing one from scratch.  It is a bit more involved than a Replacer. It
was deemed a bit out of place in the runes package, so it was never
submitted. I could add it to my github repo, though, if there is any
interest.

On Sat, Jun 25, 2016 at 5:47 PM, Matt Harden  wrote:

> Sorry, make that
>
> strings.NewReplacer("\r\n", "\r\n", "\n", "\r\n").Replace(mystring)
>
> On Sat, Jun 25, 2016 at 8:46 AM Matt Harden  wrote:
>
>> Don't use x/text/runes for this. It's overkill.
>>
>> import "strings"
>> ...
>> strings.NewReplacer("\r\n", "\r\n", "\r", "\r\n").Replace(mystring)
>>
>>
>> On Fri, Jun 24, 2016 at 2:00 PM mhhcbon 
>> wrote:
>>
>>> I forgot to mention another difficulty i have using replacement.
>>>
>>> As it will receive only one rune at a time in
>>> runes.Map(func(r rune) rune {})
>>>
>>> If the file already contains \r\n, i guess i will be doubling the \r,
>>> resulting in an ugly \r\r\n
>>>
>>> Any ideas ?
>>>
>>>
>>>
>>> Le vendredi 24 juin 2016 22:54:35 UTC+2, mhhcbon a écrit :

 Hi,

 I have a small func like this


 func WriteAsWindows1252 (src string, dst string) error {
   bSrc, err := ioutil.ReadFile(src)
   if err != nil {
   return err
   }

   bDst := make([]byte, len(bSrc)*2)
   replaceNonAscii := runes.Map(func(r rune) rune {
 if r > unicode.MaxASCII {
 return rune('?')
 }
 return r
   })
   transformer := transform.Chain(replaceNonAscii, charmap.Windows1252.
 NewEncoder())
   _, _, err = transformer.Transform(bDst, bSrc, true)
   if err != nil {
   return err
   }

   return ioutil.WriteFile(dst, bDst, 0644)
 }

 I would like to add a new replacement of \n to \r\n.

 I don't see how i can do that as rune can take only \r or \n but not
 both. And runes.Map take a function which returns a unique rune. If i don t
 mistake.

 Is there a way to achieve this with Chain ? Or i got to go with a
 []byte.Replace https://golang.org/pkg/bytes/#Replace ?

 BTW, is it the correct way to encode an utf-8 file to windows1252 ?

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

-- 
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] Question - type assertion x.(*T)

2016-06-28 Thread Michael Wain
Why would I use *T over just T ?

Michael

> On 28 Jun 2016, at 10:05, Jan Mercl <0xj...@gmail.com> wrote:
> 
> On Tue, Jun 28, 2016 at 11:02 AM Michael Wain  
> wrote:
> 
> > So a := x.(*T) is the same as a := x.(T) ?
> 
> No, because T and *T are distinct types.
> 
> 
> 
> -- 
> -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.


Re: [go-nuts] Question - type assertion x.(*T)

2016-06-28 Thread Michael Wain
So a := x.(*T) is the same as a := x.(T) ?

Michael

> On 27 Jun 2016, at 23:33, Axel Wagner  wrote:
> 
> Hm? It's this syntax:
> https://golang.org/ref/spec#Type_assertions
> using *T as the type.
> 
>> On Mon, Jun 27, 2016 at 11:08 PM,  wrote:
>> Hi,
>> 
>> Reading through gaoling spec regarding type assertions, in some code I've 
>> see type assertions like:
>> a := x.(*T)
>> 
>> i don't see a mention of that syntax in the spec, what is it doing?
>> -- 
>> 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] Question - type assertion x.(*T)

2016-06-28 Thread Jan Mercl
On Tue, Jun 28, 2016 at 11:13 AM Michael Wain 
wrote:

> Why would I use *T over just T ?

Consider this program

package main

import (
"fmt"
)

type T int

func main() {
var a, b T = 42, 314
var i, j interface{} = a, 
fmt.Println(i.(T), *j.(*T))
}

https://play.golang.org/p/mbXVkovY4G



-- 

-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] [ANN] moved github organization zalando-techmonkeys - Gin middleware projects

2016-06-28 Thread Sandor Szuecs
Hi!

We moved our Gin[1] middleware projects[2,3,4] from
zalando-techmonkeys to zalando [5,6,7], so if you use one of them
please rename your imports.

In gin-oauth2 we have a new feature implemented, Google OAuth2 is now available.

[1] https://github.com/gin-gonic/gin
[2] https://github.com/zalando-techmonkeys/gin-glog
[3] https://github.com/zalando-techmonkeys/gin-gomonitor
[4] https://github.com/zalando-techmonkeys/gin-oauth2
[5] https://github.com/zalando/gin-glog
[6] https://github.com/zalando/gin-gomonitor
[7] https://github.com/zalando/gin-oauth2

All the best, sandor
--
Sandor Szücs | Platform Nina | http://tech.zalando.org/

-- 
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: x/text/runes: How can i replace LF by CRLF ?

2016-06-28 Thread Tamás Gulácsi
I've used bufio.Scanner to implement a custom transforming stream reader.

-- 
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: Shuffle Items in a Slice

2016-06-27 Thread Chris Hines
The history of this behavior is explained in the release notes for Go 
1.3: https://golang.org/doc/go1.3#map

On Friday, June 24, 2016 at 8:48:20 AM UTC-4, Val wrote:
>
> 2 implementations here : 
> http://www.programming-idioms.org/idiom/10/shuffle-a-list/1564/go
>
> As for the map iteration trick, the runtime doesn't guarantee to randomize 
> anything, although it often tries to, so developers don't rely on some 
> specific order. I've seen (in the past) some map iterations consistently 
> not randomized at all. This behaviour may have evolved, but don't rely on 
> it.
>
>
> On Friday, June 24, 2016 at 1:05:49 PM UTC+2, dc0d wrote:
>>
>> Hi;
>>
>> To shuffle items in a slice I'm doing this:
>>
>> var res []Item
>>
>> //fill res logic
>>
>> shuffle := make(map[int]*Item)
>> for k, v := range res {
>>  shuffle[k] = 
>> }
>> res = nil
>> for _, v := range shuffle {
>>  res = append(res, *v)
>> }
>>
>> Which inserts items into a map then ranges over that map. Ranging over a 
>> map in Go returns the items in random order.
>>
>> 1 - I thought it's a cool trick!
>> 2 - Is anything bad about doing 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.


Re: [go-nuts] Re: x/text/runes: How can i replace LF by CRLF ?

2016-06-28 Thread mhhcbon
> > This does not work in cases where someone want to use a Transformer in 
a streaming context (e.g. to create a Reader or Writer or to include the 
Transform in a Chain).

This really is what i was looking to implement, somehow,

src -> transform -> transform -> sink


> I've used bufio.Scanner to implement a custom transforming stream reader.

Indeed, that is a step forward for a much better implementation than 
previous solution. thanks!

Is there any formalized stream transform like apis in go that i missed ? 
Something like another language implements :x


Le mardi 28 juin 2016 11:54:25 UTC+2, Tamás Gulácsi a écrit :
>
> I've used bufio.Scanner to implement a custom transforming stream reader.

-- 
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: x/text/runes: How can i replace LF by CRLF ?

2016-06-28 Thread mpvl
On Tue, Jun 28, 2016 at 12:36 PM, mhhcbon 
wrote:

> > > This does not work in cases where someone want to use a Transformer in
> a streaming context (e.g. to create a Reader or Writer or to include the
> Transform in a Chain).
>
> This really is what i was looking to implement, somehow,
>
> src -> transform -> transform -> sink
>
>
> > I've used bufio.Scanner to implement a custom transforming stream
> reader.
>
> Indeed, that is a step forward for a much better implementation than
> previous solution. thanks!
>
> Is there any formalized stream transform like apis in go that i missed ?
> Something like another language implements :x
>
Are you referring to something like streams in NodeJS?

The equivalent of this in Go would be io.Reader and io.Writer and friends.
Transformers in text are lower-level and allow for easier to implement, but
above all, more efficient implementations of transforms. For text the
latter is often quite important.

Once you created a transform using Chain, you can convert it to a Reader or
Writer, for instance, using transform.Reader or transform.Writer.

BTW, regarding your original problem, it is often more desirable to replace
non-ASCII by encoding.ASCIISub (U+001a). This is the default behavior of
the charmap.Windows1252 encoder.  If you want to use "?" instead, it may be
better to replace U+001a with '?' instead of just replacing non-ASCII.






>
>
> Le mardi 28 juin 2016 11:54:25 UTC+2, Tamás Gulácsi a écrit :
>>
>> I've used bufio.Scanner to implement a custom transforming stream reader.
>
> --
> 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: database proxy ?

2016-06-27 Thread Tamás Gulácsi
Why do you need such a thing? gopkg.in/rana/ora.v3 (esp. the current master 
branch) has a simple Pool implementation for reusing connections - but no 
connection limit.
Oracle does have a SessionPool implementation, but haven't used it yet.

Otherwise, database/sql/driver is quite limited, you could create an gRPC proxy 
for it easily.

-- 
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] Best practice when putting large amounts of functionality behind an interface

2016-06-27 Thread Tyler Compton
Right now, I have a web server with an interface that defines methods for 
every kind of database read/write operation my application has. 
Unsurprisingly, it's pretty large for a Go interface at around 30 methods. 
I originally did this because I wanted to be able to support multiple 
implementations of my database layer, but now it's only so that I can mock 
out this functionality for testing, which is still important to me.

This works fine, but it doesn't /feel/ right, whatever that means. As the 
proverb goes, "the bigger the interface, the weaker the abstraction." To be 
fair, I'm not really going for a lot of abstraction here. The only objects 
that should implement this interface would be geared very heavily towards 
my needs. Maybe that's where I went wrong.

Is there a more idiomatic way I could be doing 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.


Re: [go-nuts]

2016-06-25 Thread Justin Israel
On Sat, Jun 25, 2016 at 11:25 PM Oleg Puchinin 
wrote:

> Hello !
> How to make (and load) GUI form in Go ?
>

Pick a GUI library:
https://github.com/avelino/awesome-go#gui


>
> Oleg.
>
> --
> 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] How to be safe in Go?

2016-06-24 Thread Justin Israel
On Sat, 25 Jun 2016, 6:27 AM Nick Pavlica  wrote:

>
>
> On Thursday, June 23, 2016 at 6:44:22 PM UTC-6, Caleb Spare wrote:
>>
>> > To see if the the
>> > race detector would find this potential bug for me, I ran the code with
>> the
>> > mutex(s) commented out with the  -race flag on and didn't get a
>> warning.
>>
>> Did you make some concurrent requests? The race detector only tells
>> you about races that happen, so you need to excercise the concurrent
>> code paths in some way (possibly in a test or by selectively turning
>> on -race in a production-like environment).
>>
>
>   I just accessed the endpoint from multiple browsers, but no formal tests.
>
>
>>
>> A couple of general thoughts:
>>
>> (1) The primary way to know whether a library you're using will call
>> your code concurrently from multiple goroutines is via documentation.
>> The net/http documentation, for instance, explains that Serve creates
>> a goroutine for each connection. Any other library you use should
>> clearly explain this if it's the case.
>>
>
>   That makes sense, but seems to be a little fragile.  For example, if the
> lib wasn't originally concurrent, then is changed, it would be easy to get
> into a bad situation.  It makes me want to just wrap every variable in a
> Mutex to be safe.  I'm guessing that the pattern is to keep Go programs as
> small as possible so you can track all the corner cases effectively in your
> own mental model.
>

I feel like it shouldn't necessarily matter if the lib will call your
handlers concurrently or not. The focus should be on the fact that you are
wanting to share global state within the body of that function. Shouldn't
the answer be that you should avoid mutating global state without proper
synchronization? I don't feel like you should need to run a tool to find
out if it is calling your code concurrently. Rather just use best practices
to write safer code in the first place.


>
>> (2) net/http and other server packages are a slightly unusual case --
>> there are many libraries that exist, but most don't call your code
>> concurrently. (Even packages that invoke provided callbacks are
>> themselves a minority.) If I use a package that, say, interfaces with
>> a database or implements a graph algorithm, it would be quite strange
>> if it used concurrently-invoked callbacks.
>>
>
> As I ponder this; I wounder if some tooling could be added to the compiler
> or an outside utility that would scan all the used libraries, and notify
> you that the libraries/functions are concurrent.
>
> For example:
>
> 
> go run --chk_concurrent  mylib.go
>
> Notice: "net/http" calls concurrent operations on the Handle function.
>
> 
>
> Thanks again for the feedback!
> --Nick
>
> --
> 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] Custom syscall.Sockaddr

2016-06-26 Thread Elliot Morrison-Reed
I added the SockaddrCAN type to the golang.org/x/sys/unix package, and it
works great.  I create an issue with links the patch and some test code.

https://github.com/golang/go/issues/16188

On Fri, Jun 24, 2016 at 8:57 PM, Elliot Morrison-Reed 
wrote:

> SocketCAN has been part of mainline linux since kernel 2.6.25 (so getting
> close to a decade now), and it is pretty much the standard for all CAN bus
> communication on linux.
>
> Thanks for the hint, I will look into adding support in the
> golang.org/x/sys/unix package.
>
> Regards,
> Elliot
>
> On Fri, Jun 24, 2016 at 7:52 PM, Ian Lance Taylor  wrote:
>
>> On Fri, Jun 24, 2016 at 8:05 AM,   wrote:
>> >
>> > I am trying to set up an interface from Go to SocketCAN
>> > (https://www.kernel.org/doc/Documentation/networking/can.txt).  This
>> > implements the linux socket interface, however it is a completely
>> separate
>> > socket type from the regular AF_INET or AF_UNIX socket types.
>> >
>> > The sockaddr struct for SocketCAN looks like this:
>> >
>> > struct sockaddr_can {
>> > sa_family_t can_family;
>> > int can_ifindex;
>> > union {
>> > /* transport protocol class address info (e.g. ISOTP) */
>> > struct { canid_t rx_id, tx_id; } tp;
>> >
>> > /* reserved for future CAN protocols address information */
>> > } can_addr;
>> > };
>> >
>> >
>> > Since the union only has one possible entry right now, this is easy
>> enough
>> > to write in Go
>> >
>> > type CanID uint32
>> >
>> > type sockaddrCan struct {
>> >Family  uint16
>> >IfIndex int32
>> >TpRxId  CanID
>> >TpTxId  CanID
>> > }
>> >
>> >
>> > Everything is straight forward so far, but now if I want to pass this to
>> > different syscall functions ( syscall.Bind, syscall.Connect, etc.) I
>> have to
>> > implement the syscall.Sockaddr interface, however looking in the code I
>> see
>> > this:
>> >
>> > type Sockaddr interface {
>> > sockaddr() (ptr unsafe.Pointer, len _Socklen, err error) //
>> lowercase;
>> > only we can define Sockaddrs
>> > }
>> >
>> >
>> > So, finally the questions:
>> >
>> > Why is this interface private? It says that it is, but provides no
>> > rationale.
>> > Does this mean that I have to reimplement all the functions syscall
>> > functions using raw syscall.Syscall?  Or is there some clever way around
>> > this so I can use the syscall package to make a Sockaddr type that is
>> not
>> > already defined.
>>
>> If this is going to be a standard thing in future Linux kernels, I
>> suggest that you add support for it to the golang.org/x/sys/unix
>> package.
>>
>> I don't actually know the answer to why Sockaddr has a private method.
>> I agree that it doesn't seem strictly necessary.
>>
>> 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] golang subnet calculation.

2016-06-26 Thread hellobhaskar
Hello

I have a requirement to take a supernet ("10.0.0.0/8") and split it into 
small subnets say /24 size.
is there any library which i can use ? in python netaddr has useful 
routines which i can use to do the same
on a side note any one aware of  open source IPAM suite written in golang.

-- 
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] Interface{} constrains on specific types

2016-06-24 Thread 'Thomas Bushnell, BSG' via golang-nuts
The trick is to do this:

Decl special_interface

and then special_interface requires an unexported interface which you
implement in the specific (new) types that you can store in the thing.

On Fri, Jun 24, 2016 at 3:10 PM 'Mihai B' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

>  I'm developing a json schema generator (json schema from Go ast and the
> other way around). There is a keyword "oneOf" which requires  exactly one
> schema to be valid in this keyword's value. In Go I translate it by using
> an empty interface{}. The issue is that when I convert the interface{} to
> json schema I can only say that the object can be of any type even if I
> know that it can hold only a small subset.
>  Therefore I'm wondering if placing some constrains on the types that
> could be implemented by the interface would be a good idea. For example
> instead of `type interface{}` which implements any type we could define the
> types it can implement (e.g.  type  X interface{T1, T2, T3} ). This way we
> don't have a totally black box so it improves the documentation/semantics
> and we avoid specific bugs using static analysis. Currently the practice
> seems to be documenting the types in pure comments[0] which cannot be
> analysed statically. Another option that I'm considering now is to use the
> empty interface but with specific tags [1] and use an external tool. This
> might have been proposed before but I can't find it on the mailing list.
> What do you think?
>
> [0]  https://golang.org/pkg/go/ast/#Object
> [1]
>
> type Object struct {
> Name string   // declared 
> name
> Decl interface{} 
> `interface:"Field,FuncDecl,LabeledStmt,external.Scope" //
>
> }
>
> --
> 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] golang poll/epoll/select

2016-06-24 Thread graham4king
If you have a specific case that isn't covered by blocking in a go-routine, 
you can always use the syscall's directly, with a very similar API to what 
you would do in C. 

For example here's the epoll ones in stdlib: 
https://golang.org/pkg/syscall/#EpollCreate

New syscall wrappers are in the x/sys repo: 
https://godoc.org/golang.org/x/sys/unix

On Thursday, 22 September 2011 07:04:03 UTC-7, vase wrote:
>
>
>
> 2011/9/22 André Moraes 
>
>> In most cases you should not need to poll explicity.
>> Write a goroutine that blocks while reading the contents of your fd
>> (file, network, etc...), and then send the data read across a channel.
>>
>> Under the hood Go will take care of the poll for you.
>>
>> But if you really need to poll explicitly, I can't help you since I
>> never had to do that.
>>
>
> Hm... Can somebody from golang team tell me, what is the best way to 
> provide this (example written in C):
> xs_watch() // create a hook, that watch to specific path to cheange
> epoll_wait() //wait to event on fd that returned by watch
> xs_read_watch() //read watched data that appeared
> xs_unwatch() //delete watch and stops recive notify
>
> As i see, i need to create goroutine in xs_watch(worker), that runs worker 
> function with read, then some data appeared, goroutine read and do some 
> stuff, xs_unwatch destroy groutine and stops watching... Right? 
>
>
>
> -- 
> Vasiliy Tolstov,
> Clodo.ru
> e-mail: v.to...@selfip.ru 
> jabber: va...@selfip.ru 
>
>

-- 
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] Interface{} constrains on specific types

2016-06-24 Thread 'Mihai B' via golang-nuts
 I'm developing a json schema generator (json schema from Go ast and the 
other way around). There is a keyword "oneOf" which requires  exactly one 
schema to be valid in this keyword's value. In Go I translate it by using 
an empty interface{}. The issue is that when I convert the interface{} to 
json schema I can only say that the object can be of any type even if I 
know that it can hold only a small subset.
 Therefore I'm wondering if placing some constrains on the types that could 
be implemented by the interface would be a good idea. For example instead 
of `type interface{}` which implements any type we could define the types 
it can implement (e.g.  type  X interface{T1, T2, T3} ). This way we don't 
have a totally black box so it improves the documentation/semantics and we 
avoid specific bugs using static analysis. Currently the practice seems to 
be documenting the types in pure comments[0] which cannot be analysed 
statically. Another option that I'm considering now is to use the empty 
interface but with specific tags [1] and use an external tool. This might 
have been proposed before but I can't find it on the mailing list. What do 
you think?

[0]  https://golang.org/pkg/go/ast/#Object 
[1]  

type Object struct {
Name string   // declared 
name
Decl interface{} `interface:"Field,FuncDecl,LabeledStmt,external.Scope" 
//
   
}

-- 
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: Any keyboard players here?

2016-06-26 Thread Daniel Skinner
Finally have a place to setup my keyboard and tgui-harm worked well, nice
work.

On Sun, Jun 26, 2016 at 3:25 AM  wrote:

> Hi Daniel,
>
> I already investigated your piano and snd projects at github, but could
> not get them working: too much unknown libraries. Anyhow, it seemed to be
> aiming at the Android platform, with an on-screen piano keyboard and no
> MIDI interface. For Android this is a sensible project, but for a musician
> it qualifies as a toy app, not fit to play real music, and competing with a
> lot of similar apps. In the past I created several myself, and believe me:
> you cannot use a touch screen as a real piano keyboard. It's unplayable.
>
> About the speed of Go: that depends on what you compare it to. In the past
> I wrote similar programs in C++. There I used more complicated algorithms,
> with more calculations at each signal frame, and still the program could
> run at 48000Hz without problems. So apparently in this area Go is 2x slower
> then C++. I tried all known trics to increase the speed, like: no garbage
> creation, and also pre-calculate as much as possible. Increasing the buffer
> size had little effect, because all needed calculations still must be done.
>
> I would love to hear how your piano is sounding. Can't you update your
> github projects and also augment the README's such that a simple user like
> me can build something that works?
>
> Wouter Boeke
>
> --
> 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: formal verification in Go? someday perhaps?

2016-06-26 Thread wsc
I think a better question is:  can go tools for formal verification become 
available?  The distinction is that formal verification tools can be 
applied to
hardware, protocols, assembly, software, etc.   Why not do that in go?

Most such tools are in C or C++, and the low level engines/components are 
highly optimised.  Go can easily compete with "standard" C/C++, i.e. 
software which has not been highly optimised.  It also provides enough 
low-level access to be competitive against highly optimised C/C++ (e.g. 
assembly, precision of memory representations) but it takes work.  

One of the research initiatives we are taking up is "scalable cloud 
 architectures for formal technologies".  Basically, composable cloud 
microservices for formal technologies like model checking, SAT/BDD/SMT, 
theorem proving, as well as encoders for verification problems, etc, but in 
terms of deployment in the cloud.  A related startup is satalia.  Go is a 
natural fit for this initiative, and we already have some results with go.

I think the biggest obstacle to formal tools targeting analysis of go 
programs is formal representations in the golang "go" package.  Once that 
is available, things will start to snowball.

 



Le lundi 9 mars 2015 01:07:36 UTC+1, Camilo Aguilar a écrit :
>
> I ran across this post today: 
> http://blog.adacore.com/testing-static-formal. Basically, showing how you 
> can do formal verifications in ADA2012. Is it realistic to think that a 
> feature like that would someday arrive to Go? 

-- 
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] Append to slice... what happens?

2016-06-26 Thread Peter Kleiweg
This:

https://play.golang.org/p/AE670rTMpE

I don't know what I expected, but it's weird. Don't mess with slices.

-- 
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] Append to slice... what happens?

2016-06-26 Thread Jan Mercl
On Mon, Jun 27, 2016 at 12:26 AM Peter Kleiweg  wrote:

> I don't know what I expected, but it's weird. Don't mess with slices.

Well, working as expected, considering slice backing array is possibly
shared wrt the result of append. (Or other slice op, b/c slices _are_
values.)

However, it's easy to avoid the append sharing when/where not desirable:
https://play.golang.org/p/oIFHamYWB-


-- 

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


Re: [go-nuts] Where is .gosymtab in go binaries with cgo?

2016-06-26 Thread Tamás Gulácsi


2016. június 26., vasárnap 21:42:15 UTC+2 időpontban Ian Lance Taylor a 
következőt írta:
>
> On Sun, Jun 26, 2016 at 12:18 AM, Tamás Gulácsi  > wrote: 
> > I want to find out the source package's given the binary. 
> > 
> > github.com/FiloSottile/gorebuild (and github.com/rjeczalik/which) works 
> fine 
> > with binaries built with the "go" tool. 
> > But fails if cgo (and thus I think gcc) is included in the build 
> procedure. 
> > 
> > A minimal example is attached to 
> > https://github.com/FiloSottile/gorebuild/issues/3 
> > 
> > Can anybody help me? 
>
> I don't see how the .gosymtab section is relevant here.  It's 
> currently always empty.  When using external linking, as when building 
> a program that uses cgo, it gets dropped.  But even when it remains in 
> the file, it is empty.  I don't think gosymtab has had any contents 
> since the 1.2 release.  Yes, the situation is somewhat confusing, and 
> I'm not sure I entirely understand it. 
>
> Ian 
>

Ok, than anz other idea to get the binary's main.main function's package's 
path, from the binary?
The other way around (go list -e .../binary) has its own weaknesses (dirs 
with same names)...

-- 
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: Trouble querying REST API with net/http (api verified working with curl)

2016-06-26 Thread mark mellar
For anyone else having similar issues, I found I was able to work around 
this by using client.Get() rather than client.Do().

Still not sure what the root cause is though...

Cheers.

On Friday, June 24, 2016 at 7:32:36 AM UTC+1, mark mellar wrote:
>
> Good tip on using httputil to inspect the request! Unfortunately I'm not 
> seeing anything obviously wrong...
>
> Using curl -v
>
> *   Trying ...
> * Connected to host.here.com () port 443 (#0) 
> * TLS 1.0 connection using TLS_DHE_RSA_WITH_AES_256_CBC_SHA 
> * Server certificate: host 
> > GET /rest/json/flows HTTP/1.1 
> > Host: host.here.com 
> > User-Agent: curl/7.43.0 
> > Accept: */* 
> > Cookie: 
> connect.sid=s%3AeQ30DeGtFyrhrntWofMWpGXo.%2F745zwxR0ErYrpnoVDklkt%2F7H9FX5GfcroBFXg5M6Ag
>  
>
> > Content-Type: application/json
>
>
> using httputil.DumpRequestOut
>
> Get /rest/json/flows HTTP/1.1
>
> Host: host.here.com:443
>
> User-Agent: Go-http-client/1.1
>
> Content-Type: application/json
>
> Cookie: 
> connect.sid=s%3A%2FWuxV7HdAnHDweXFvs4N8%2BaB.DuNDxfVN6sLhLO%2Flu3hIY7PfUnfMquyRIfXSllGtZpM
>
> Accept-Encoding: gzip
>
> I'm suspicious about the Accept-Encoding field. I tried 
> twiddling DisableCompression in my transport but nothing changed...
>
> Cheers,
>
> Mark
>
> On Friday, June 24, 2016 at 5:46:06 AM UTC+1, Tamás Gulácsi wrote:
>>
>> Just a blind shoot into the darkness: try to use one (global) 
>> http.Client! Also, you can ask curl to dump the request, and 
>> net/http/httputil also to compare them.
>
>

-- 
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 it safe enough to read uint without lock/atomic operation?

2016-06-26 Thread 苏沛
https://github.com/golang/go/blob/master/src/runtime/chan.go#L655

func reflect_chancap(c *hchan) int {
if c == nil {
return 0
}
return int(c.dataqsiz)
}


-- 
苏沛

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

2016-06-25 Thread Mohammad Nasirifar
Btw I would like to work on it

On Sat, Jun 25, 2016 at 5:16 PM, Mohammad Nasirifar 
wrote:

> Btw I would like to work on it!
>
> On Sat, Jun 25, 2016 at 5:11 PM, Henrik Johansson 
> wrote:
>
>> Cache headers, etags etc and dynamic scheduling of re-fetch sounds
>> useful. Why not start a little library?
>>
>> On Sat, Jun 25, 2016, 13:51 Johann Höchtl 
>> wrote:
>>
>>>
>>>
>>> Am Donnerstag, 23. Juni 2016 17:04:54 UTC+2 schrieb Shawn Milochik:

 What do you need it to do, specifically? Doing an http.Get on a page
 and storing and comparing the bytes or a hash is something you could write
 in under a minute. Why not just do that?

>>>
>>> Get notified when a change happens. Your approach would certainly work
>>> but it's super-naive. Perform a Head Lookup and check the Timestamp when
>>> the resurce was changed, ETags, etc. all come to my mind to checl before
>>> downloading the whle resource. Or being able to specify a nesting level
>>> upto which embeded resources will be fetched recursively to check for
>>> change etc.
>>>
>>> So I think somebody else spent more time to think about that. There are
>>> services in other languages of course but I was hoping for some sort of
>>> getable service in Golang / package.
>>>
>>> --
>>> 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.
>>
>
>

-- 
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] golang poll/epoll/select

2016-06-25 Thread Michael Soulier


On Friday, June 24, 2016 at 6:59:28 PM UTC-4, Ian Lance Taylor wrote:
>
> In Go you normally simply start a goroutine that reads from Stdin and 
> sends the data over a channel. 
>
> Goroutines are cheap. 
>
>
Sure, but when you read and get an EOF you return immediately, so the 
goroutine would be busy waiting when there's nothing to read, would it not?

Mike 

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

2016-06-25 Thread Mohammad Nasirifar
Btw I would like to work on that!

On Saturday, June 25, 2016 at 5:11:34 PM UTC+4:30, Henrik Johansson wrote:
>
> Cache headers, etags etc and dynamic scheduling of re-fetch sounds useful. 
> Why not start a little library? 
>
> On Sat, Jun 25, 2016, 13:51 Johann Höchtl  > wrote:
>
>>
>>
>> Am Donnerstag, 23. Juni 2016 17:04:54 UTC+2 schrieb Shawn Milochik:
>>>
>>> What do you need it to do, specifically? Doing an http.Get on a page and 
>>> storing and comparing the bytes or a hash is something you could write in 
>>> under a minute. Why not just do that?
>>>
>>
>> Get notified when a change happens. Your approach would certainly work 
>> but it's super-naive. Perform a Head Lookup and check the Timestamp when 
>> the resurce was changed, ETags, etc. all come to my mind to checl before 
>> downloading the whle resource. Or being able to specify a nesting level  
>> upto which embeded resources will be fetched recursively to check for 
>> change etc.
>>
>> So I think somebody else spent more time to think about that. There are 
>> services in other languages of course but I was hoping for some sort of 
>> getable service in Golang / package.
>>
>> -- 
>> 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] golang poll/epoll/select

2016-06-25 Thread Michael Soulier
I thought I got select working but now it's returning immediately even 
without any input to stdin.

// loop forever - we expect to be killed with a SIGTERM or SIGINT
for {
logger.Debug("going into select on stdin")
var r_fdset syscall.FdSet
for i := 0; i < 16; i++ {
r_fdset.Bits[i] = 0
}
r_fdset.Bits[0] = 1
selerr := syscall.Select(1, _fdset, nil, nil, nil)
if selerr != nil {
logger.Warning(selerr)
}

So I'm doing something wrong. 

-- 
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: Trouble querying REST API with net/http (api verified working with curl)

2016-06-27 Thread Kiki Sugiaman

I know this is a bit late, so perhaps you don't care anymore...

Anyway, the server may not understand the "Get" method in this line:
|req, err := http.NewRequest("Get", 
"https://"+host+".here.com:443/rest/json/flows;, nil)

|


On 27/06/16 08:22, mark mellar wrote:
For anyone else having similar issues, I found I was able to work 
around this by using client.Get() rather than client.Do().


Still not sure what the root cause is though...

Cheers.

On Friday, June 24, 2016 at 7:32:36 AM UTC+1, mark mellar wrote:

Good tip on using httputil to inspect the request! Unfortunately
I'm not seeing anything obviously wrong...

Using curl -v

*   Trying ...
* Connected to host.here.com  () port
443 (#0)
* TLS 1.0 connection using TLS_DHE_RSA_WITH_AES_256_CBC_SHA
* Server certificate: host
> GET /rest/json/flows HTTP/1.1
> Host: host.here.com 
> User-Agent: curl/7.43.0
> Accept: */*
> Cookie:

connect.sid=s%3AeQ30DeGtFyrhrntWofMWpGXo.%2F745zwxR0ErYrpnoVDklkt%2F7H9FX5GfcroBFXg5M6Ag

> Content-Type: application/json


using httputil.DumpRequestOut

Get /rest/json/flows HTTP/1.1

Host: host.here.com:443 

User-Agent: Go-http-client/1.1

Content-Type: application/json

Cookie:

connect.sid=s%3A%2FWuxV7HdAnHDweXFvs4N8%2BaB.DuNDxfVN6sLhLO%2Flu3hIY7PfUnfMquyRIfXSllGtZpM

Accept-Encoding: gzip


I'm suspicious about the Accept-Encoding field. I tried
twiddling DisableCompression in my transport but nothing changed...

Cheers,

Mark

On Friday, June 24, 2016 at 5:46:06 AM UTC+1, Tamás Gulácsi wrote:

Just a blind shoot into the darkness: try to use one (global)
http.Client! Also, you can ask curl to dump the request, and
net/http/httputil also to compare them.

--
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] Re: Shuffle Items in a Slice

2016-06-27 Thread Martin Geisler
Hi Val

On Fri, Jun 24, 2016 at 2:48 PM, Val  wrote:
> 2 implementations here :
> http://www.programming-idioms.org/idiom/10/shuffle-a-list/1564/go
>
> As for the map iteration trick, the runtime doesn't guarantee to randomize
> anything, although it often tries to, so developers don't rely on some
> specific order.

That's a nice feature and very helpful when writing tests... otherwise
you end up with a test that works fine on one version/architecture and
"suddenly" breaks later.

Randomizing the order "on purpose" is probably also done for security
reasons. Python works much the same, and some years ago, the CPython
VM began randomizing the dict (map) type. The problem was that
carefully crafted input would trigger a worst-case scenario in the
hash table used behind the scenes and suddenly make your server crawl
to a halt.

The input could be HTTP headers, for example, with carefully chosen
names: these are normally read from the client and used as keys in a
map. With the right keys, you can trigger hash collisions and make the
map allocate much more memory than you would expect with typical keys.

Having the runtime add a bit of randomness to the keys prevents this
scenario. When the randomness changes at every execution, it further
helps the developers by highlighting the nondeterministic iteration
order of the hash table.

> I've seen (in the past) some map iterations consistently not
> randomized at all. This behaviour may have evolved, but don't rely on it.

That's good advice :-)

-- 
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: Getting a pointer in a type switch gives a *interface {} if case lists several options

2016-06-26 Thread Constantin Konstantinidis
This is (old) documented issue https://github.com/golang/go/issues/460 
related to multiple values in one case of the switch.

On Sunday, June 26, 2016 at 5:40:55 PM UTC+2, Constantin Konstantinidis 
wrote:
>
> A part of the answer is in the specifications as the method set is 
> inherited from the type https://golang.org/ref/spec#Method_sets
>
>
> On Wednesday, June 22, 2016 at 12:02:02 AM UTC+2, raido...@gmail.com 
> wrote:
>>
>> I have encountered some unexpected and inconsistent behavior with type 
>> switches. Can someone shed some light as to why Go behaves this way?
>>
>> Take a look at https://play.golang.org/p/YPV5YPtWF8
>>
>> I would expect both of the switches to behave the same way, but for some 
>> reason the one with multiple options in the case ends up with a pointer to 
>> an interface and the one with just one option ends up with a pointer to the 
>> correct type.
>>
>

-- 
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] Append to slice... what happens?

2016-06-26 Thread Martin Geisler
Hi Henry,

On Mon, Jun 27, 2016 at 3:55 AM, Henry  wrote:
> If you were to change the code a bit as follows 
> https://play.golang.org/p/VwtWRQBrEe , it will work as you expect.
>
> I think it is probably safer to instantiate a slice without specifying the 
> initial capacity.

Having the capacity larger than the number of used elements (the
length of the slice) is indeed the problem. However, not specifying
the capacity can also fail you. Here I changed the numbers of elements
appended slightly and print the capacity after each operation:

  https://play.golang.org/p/WBTRvgJJKW

As you can see, append will over-allocate and set the capacity of the
underlying array to 4 when we go from an empty slice to a slice with
length 3. This in turn makes the following appends to a and b share
the 4th slot in the array and appending to a will ultimately update
the value you see in b.

In your example you were "lucky" since you started with a = [1, 2] and
cap(a) = 2. When you create b, append notices that the capacity is
exhausted and *creates a new underlying array for b*. After that step,
a and b are no longer "entangled" like this and updates to one cannot
affect the other.

-- 
Martin Geisler

-- 
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] Shuffle Items in a Slice

2016-06-27 Thread Martin Geisler
On Fri, Jun 24, 2016 at 2:54 PM, Val  wrote:
> The playground caches everything, so running multiple times the same program
> will just serve the previously generated output.

Thanks, that's good to know! Makes a lot of sense too.

> Also in the playground everything is frozen at some point in the past : the
> clock, the randomness sources, and you can't make outgoing requests to
> import randomness from the network.

I found this blog post with a lot more background information:

  https://blog.golang.org/playground

-- 
Martin Geisler

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


[go-nuts] Question - type assertion x.(*T)

2016-06-27 Thread michaelwain1990
Hi,

Reading through gaoling spec regarding type assertions, in some code I've 
see type assertions like:
a := x.(*T)

i don't see a mention of that syntax in the spec, what is it doing?

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

2016-06-25 Thread Johann Höchtl


Am Donnerstag, 23. Juni 2016 17:04:54 UTC+2 schrieb Shawn Milochik:
>
> What do you need it to do, specifically? Doing an http.Get on a page and 
> storing and comparing the bytes or a hash is something you could write in 
> under a minute. Why not just do that?
>

Get notified when a change happens. Your approach would certainly work but 
it's super-naive. Perform a Head Lookup and check the Timestamp when the 
resurce was changed, ETags, etc. all come to my mind to checl before 
downloading the whle resource. Or being able to specify a nesting level  
upto which embeded resources will be fetched recursively to check for 
change etc.

So I think somebody else spent more time to think about that. There are 
services in other languages of course but I was hoping for some sort of 
getable service in Golang / package.

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

2016-06-25 Thread Henrik Johansson
Cache headers, etags etc and dynamic scheduling of re-fetch sounds useful.
Why not start a little library?

On Sat, Jun 25, 2016, 13:51 Johann Höchtl  wrote:

>
>
> Am Donnerstag, 23. Juni 2016 17:04:54 UTC+2 schrieb Shawn Milochik:
>>
>> What do you need it to do, specifically? Doing an http.Get on a page and
>> storing and comparing the bytes or a hash is something you could write in
>> under a minute. Why not just do that?
>>
>
> Get notified when a change happens. Your approach would certainly work but
> it's super-naive. Perform a Head Lookup and check the Timestamp when the
> resurce was changed, ETags, etc. all come to my mind to checl before
> downloading the whle resource. Or being able to specify a nesting level
> upto which embeded resources will be fetched recursively to check for
> change etc.
>
> So I think somebody else spent more time to think about that. There are
> services in other languages of course but I was hoping for some sort of
> getable service in Golang / package.
>
> --
> 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] russian language books about Go

2016-06-26 Thread adonovan via golang-nuts
On Friday, 24 June 2016 03:10:56 UTC-4, Oleg Puchinin wrote:
>
> Hello !
> Where I can find subject ?
>

Hi Oleg,

our book The Go Programming Language (gopl.io) is now available in Russian, 
thanks to Williams Press:
http://www.williamspublishing.com/Books/978-5-8459-2051-5.html

The ozon.ru site features some sample chapters so you can try before you 
buy:
http://www.ozon.ru/context/detail/id/34671680/

cheers
alan


-- 
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] Append to slice... what happens?

2016-06-26 Thread Henry
If you were to change the code a bit as follows 
https://play.golang.org/p/VwtWRQBrEe , it will work as you expect. 

I think it is probably safer to instantiate a slice without specifying the 
initial capacity.

-- 
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] golang poll/epoll/select

2016-06-25 Thread Jesse McNelis
On 25 Jun 2016 11:08 p.m., "Michael Soulier"  wrote:
>
> Sure, but when you read and get an EOF you return immediately, so the
goroutine would be busy waiting when there's nothing to read, would it not?
>

You'll only get an EOF if the file descriptor has been closed, if it's
closed then you're not going to be able to read anything more anyway.

What are you trying to do?

-- 
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: can't get Content-Type and Content-Disposition to force browser to display "file->save..." dialog in the web browser

2016-06-25 Thread Matt Harden
That's very strange. Why didn't Set work? Was there some already-existing
Content-Disposition value in the header that you needed to retain?

On Fri, Jun 24, 2016 at 7:57 AM David Marceau 
wrote:

> The core problem was:
> w.Header().Set("Content-Disposition","attachment;filename=" +
> strOutputFileOfJournalctl)
> Should actually be:
> w.Header().Add("Content-Disposition","attachment;filename=" +
> strOutputFileOfJournalctl)
>
> I preferred to put the above line before the serveFile.
>
> That's all. Thanks to everyone who dropped by.
>
>
> On Friday, June 24, 2016 at 9:44:00 AM UTC-4, David Marceau wrote:
>>
>> Here is what is in my import.  Maybe I should be looking in goji instead
>> of net/http?
>>
>
>
>>
>> import (
>> "fmt"
>> "net"
>> "time"
>> "strconv"
>> "strings"
>> "os"
>> "encoding/json"
>> "net/http"
>> "crypto/tls"
>> "crypto/rand"
>> "github.com/gorilla/mux"
>> "github.com/goji/httpauth"
>> "github.com/zfjagann/golang-ring"
>> "github.com/kabukky/httpscerts"
>> "reflect"
>> "io"
>> "io/ioutil"
>> "path/filepath"
>> "html/template"
>> "os/exec"
>> )
>>
>> On Friday, June 24, 2016 at 9:40:29 AM UTC-4, David Marceau wrote:
>>>
>>> I tried to repeat the same ordering as the iris infrastructure within
>>> the function, but it still behaves not as expected.  It does not show the
>>> file->save... dialog.  It shows the file within the browser as a web page.
>>>
>>> func blah (w http.ResponseWriter, r *http.Request) {
>>> strOutputFileOfJournalctl = "journalctlLog.json"
>>> w.Header().Set("Content-Type","application/octet-stream")  //forces
>>> the save as dialog
>>>
>>> strSomeStringInJsonFormat := "{ Blah: 'blah value' }"
>>> myOutput := []byte(strSomeStringInJsonFormat)
>>>
>>> //ATTEMPT #1
>>> //w.Write(myOutput) //displays in web browser page
>>> //ATTEMPT #4
>>> //w.Header().Set("Content-Disposition","attachment;filename=" +
>>> strOutputFileOfJournalctl)
>>>
>>>
>>>
>>> //ATTEMPT #3
>>> //w.Header().Add("Content-Length", strconv.Itoa( len(myOutput) ) )
>>> //w.Write(myOutput) //displays in web browser page
>>> //w.Header().Set("Content-Disposition","attachment;filename=" +
>>> strOutputFileOfJournalctl)
>>>
>>>
>>>
>>> //ATTEMPT #2
>>> w.Header().Add("Content-Length", strconv.Itoa(len(myOutput)) )
>>> tmpFile, _ := ioutil.TempFile(os.TempDir(), "OurGeneratedCustomLog")
>>> defer os.Remove(tmpFile.Name())
>>> tmpFile.Write(myOutput)
>>> tmpFile.Close()
>>> http.ServeFile(w, r, tmpFile.Name())
>>> //ATTEMPT #5
>>> w.Header().Set("Content-Disposition","attachment;filename=" + "\"" +
>>> strOutputFileOfJournalctl + "\"")
>>> }
>>>
>>>
>>> On Friday, June 24, 2016 at 7:06:59 AM UTC-4, David Marceau wrote:

 Again, I want to clarify the file does arrive in the browser, but I
 want to ensure the "file->save..." dialog appears in the web browser when
 it arrives.  I found some older code I wrote a couple of years ago that was
 behaving as expected:
 w.Header().Set("Content-Type", "application/octet-stream")
 w.Header().Set("Content-Disposition", "attachment; filename=" +
 myBasePdf + ".pdf")
 http.ServeFile(w, req, myGenPdfFileName)


 I acknowledge when I wrote this email I made a typo, but in my code I
 do have the Itoa correctly.
 w.Header().Set("Content-Length", strconv.Itoa( len(myCmdOutput) ) )
 I never used that content-length field because I read somewhere that I
 shouldn't.

 Last night I took a look at iris to see how they do it and found:
 https://github.com/kataras/iris/blob/master/context.go#L583
 err := ctx.ServeFile(filename, false)
 if err != nil {
 return err
 }

 ctx.RequestCtx.Response.Header.Set(contentDisposition, "
 attachment;filename="+destinationName)

 I am scratching my head since the header set content-disposition is
 happening after the ServeFile which is different from what all the docs and
 what I am used to seeing.  It seems calling these functions are
 order-independant.  When does the connection actually send the file over
 the connection?

 I believe the Iris send file also provides what I want as expected
 behaviour, but I haven't tried it yet.

 On Thursday, June 23, 2016 at 6:15:16 PM UTC-4, Val wrote:
>
> The commented line seems to have typo strconv.Ito
>
> Maybe the typo prevents proper recompilation, and server goes on with
> old code?
>
 --
> 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 

Re: [go-nuts] Re: x/text/runes: How can i replace LF by CRLF ?

2016-06-25 Thread Matt Harden
Don't use x/text/runes for this. It's overkill.

import "strings"
...
strings.NewReplacer("\r\n", "\r\n", "\r", "\r\n").Replace(mystring)


On Fri, Jun 24, 2016 at 2:00 PM mhhcbon  wrote:

> I forgot to mention another difficulty i have using replacement.
>
> As it will receive only one rune at a time in
> runes.Map(func(r rune) rune {})
>
> If the file already contains \r\n, i guess i will be doubling the \r,
> resulting in an ugly \r\r\n
>
> Any ideas ?
>
>
>
> Le vendredi 24 juin 2016 22:54:35 UTC+2, mhhcbon a écrit :
>>
>> Hi,
>>
>> I have a small func like this
>>
>>
>> func WriteAsWindows1252 (src string, dst string) error {
>>   bSrc, err := ioutil.ReadFile(src)
>>   if err != nil {
>>   return err
>>   }
>>
>>   bDst := make([]byte, len(bSrc)*2)
>>   replaceNonAscii := runes.Map(func(r rune) rune {
>> if r > unicode.MaxASCII {
>> return rune('?')
>> }
>> return r
>>   })
>>   transformer := transform.Chain(replaceNonAscii, charmap.Windows1252.
>> NewEncoder())
>>   _, _, err = transformer.Transform(bDst, bSrc, true)
>>   if err != nil {
>>   return err
>>   }
>>
>>   return ioutil.WriteFile(dst, bDst, 0644)
>> }
>>
>> I would like to add a new replacement of \n to \r\n.
>>
>> I don't see how i can do that as rune can take only \r or \n but not
>> both. And runes.Map take a function which returns a unique rune. If i don t
>> mistake.
>>
>> Is there a way to achieve this with Chain ? Or i got to go with a
>> []byte.Replace https://golang.org/pkg/bytes/#Replace ?
>>
>> BTW, is it the correct way to encode an utf-8 file to windows1252 ?
>>
>> 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.


[go-nuts] 'go tool pprof' only shows "Type: CPU" and not a callgraph

2016-06-27 Thread Dave Cheney
What are the exact commands you used?

It is easy to misuse proof, here is a slide with some of the gotchas.

http://talks.godoc.org/github.com/davecheney/presentations/writing-high-performance-go.slide#11

-- 
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: Best practice when putting large amounts of functionality behind an interface

2016-06-27 Thread Chad
What does the interface look like currently?

On Monday, June 27, 2016 at 10:54:31 PM UTC+2, Tyler Compton wrote:
>
> Right now, I have a web server with an interface that defines methods for 
> every kind of database read/write operation my application has. 
>
Any example ?
 

> Unsurprisingly, it's pretty large for a Go interface at around 30 methods. 
> I originally did this because I wanted to be able to support multiple 
> implementations of my database layer, but now it's only so that I can mock 
> out this functionality for testing, which is still important to me.
>
> This works fine, but it doesn't /feel/ right, whatever that means. As the 
> proverb goes, "the bigger the interface, the weaker the abstraction." To be 
> fair, I'm not really going for a lot of abstraction here. The only objects 
> that should implement this interface would be geared very heavily towards 
> my needs. Maybe that's where I went wrong.
>
> Is there a more idiomatic way I could be doing this?
>

Interfaces are composable so you could probably make a slight refactor 
where you assemble methods by usage. It may help keep things clearer. 

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


<    1   2   3   4   5   6   7   8   9   10   >