[go-nuts] How web site create by golang get client certificate in usb token.

2017-11-22 Thread tuanhoanganh
Hello

I am newbie of golang, I am creating a site with golang restful and
angularJS.

>From ASP WebForm, I can allow user choose certificate in this code:

namespace WebX509Certificate2
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
X509Certificate2 m_certificate;

m_certificate = GetCertificate();
}

protected X509Certificate2 GetCertificate()
{
var certificate = new
X509Certificate2(Request.ClientCertificate.Certificate);
var store = new X509Store("My", StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);


var certificates = new
X509Certificate2Collection(store.Certificates);
store.Close();

var title = "Certificate Store";
var message = "Please select Certificates (Applied for Online
Application)";
X509SelectionFlag selectionFlag;
X509Certificate2Collection certificatesSelected;
try
{

certificatesSelected =
X509Certificate2UI.SelectFromCollection(certificates,
title, message, X509SelectionFlag.SingleSelection);



if (certificatesSelected.Count == 0)
return null;
else
{
certificate = certificatesSelected[0];
return certificate;
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}

How can I do it in golang ?

Thank in advance

Tuan Hoang Anh

-- 
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: is this safe?

2017-11-22 Thread C Banning
Why not something simple like: https://play.golang.org/p/iAlflMUdEA

On Monday, November 20, 2017 at 9:48:31 AM UTC-7, Trig wrote:
>
> for i, user := range myList {
>  if user.Disabled { 
>   myList = append(myList[:i], myList[i + 1:]...) // remove user from 
> return list 
>  } 
> }
>
>
> Is using append this way (to remove an index), inside of the range loop of 
> the same array I'm working with, safe... since the size of myList is being 
> changed within it?
>

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


Re: [go-nuts] Re: Efficient to copy Hash?

2017-11-22 Thread roger peppe
On 21 November 2017 at 21:56, 'simon place' via golang-nuts
 wrote:
> i found this code, and use it on hash.Hash
>
> // copy an interface value using reflect (here for pointers to interfaces)
> func clone(i interface{}) interface{} {
> indirect := reflect.Indirect(reflect.ValueOf(i))
> newIndirect := reflect.New(indirect.Type())
> newIndirect.Elem().Set(reflect.ValueOf(indirect.Interface()))
> return newIndirect.Interface()
> }
>
> like this;
>
> branchHasher = clone(hasher).(hash.Hash)

Although this works on most hash implementations in the standard library,
I'm not sure I'd recommend doing this, as it depends on the fact that
all the state in the hash implementations will copied with a shallow copy.

Better (albeit less efficient) would be something like this, I think:

func CloneHash(h hash.Hash) hash.Hash {
type codec interface {
hash.Hash
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
}
mh, ok := h.(codec)
if !ok {
panic(fmt.Errorf("hash %T cannot be cloned", h))
}
data, err := mh.MarshalBinary()
if err != nil {
panic(fmt.Errorf("hash %T marshal failed: %v", h, err))
}
t := reflect.TypeOf(h)
if t.Kind() != reflect.Ptr {
panic(fmt.Errorf("hash %T is not of pointer type", h))
}

mh1 := reflect.New(t.Elem()).Interface().(codec)
if err := mh1.UnmarshalBinary(data); err != nil {
panic(fmt.Errorf("hash %T unmarshal failed: %v", mh1, err))
}
return mh1
}

I could understand why you might use your original version for performance
reasons, though. It could be a little simpler, I think:

// CloneHash clones the current state of the given
// hash. It works with most implementations in the standard
// library but is not guaranteed to work with all Hash
// implementations.
func CloneHash(h hash.Hash) hash.Hash {
hv := reflect.ValueOf(h)
hv1 := reflect.New(hv.Type().Elem())
hv1.Elem().Set(hv.Elem())
return hv1.Interface().(hash.Hash)
}

If I was using it in production code, I'd probably be defensive and do something
like this:

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

I think that even now that hashes that implement encoding.BinaryMarshaler and
encoding.BinaryUnmarshaler, there's probably still room for a Clone method
(or perhaps a top level hash.Clone function) in the standard library to avoid
the necessity for this kind of thing.

>
>
> On Wednesday, 8 November 2017 12:54:18 UTC, Christian LeMoussel wrote:
>>
>> Hi,
>>
>> I want to calculate hash on 3 strings. First string is always the same,
>> the other may vary.
>> The first approach is to calculate the hash each time for the 3 strings
>> (BenchmarkHash)
>> Another approach would be to calculate once for the first string, and then
>> reuse this hash to calculate the hash with the other 2
>> strings(BenchmarkCopyHash)
>> The difficulty is that sha256.New() returns a pointer, we have to copy the
>> first hash. To do this, I created the function copyHash()
>> But the performances are not exceptional.
>>
>> Do you have another idea to do this in efficient way?
>>
>>
>> BenchmarkHash-8  100  1761 ns/op
>> 176 B/op  4 allocs/op
>> BenchmarkCopyHash-8  100  1519 ns/op
>> 240 B/op  4 allocs/op
>>
>>
>> var m1 = strings.Repeat("a", 64)
>> var m2 = strings.Repeat("b", 48)
>> var m3 = strings.Repeat("c", 32)
>>
>> func BenchmarkHash(b *testing.B) {
>> var (
>> d hash.Hash
>> )
>>
>> d = sha256.New()
>> for n := 0; n < b.N; n++ {
>> d.Reset()
>> d.Write([]byte(m1))
>> d.Write([]byte(m2))
>> d.Write([]byte(m3))
>> d.Sum(nil)
>> }
>> }
>> func BenchmarkCopyHash(b *testing.B) {
>> var (
>> d1 hash.Hash
>> d2 hash.Hash
>> )
>>
>> d1 = sha256.New()
>> d1.Write([]byte(m1))
>>
>> for n := 0; n < b.N; n++ {
>> d2 = copyHash(d1)
>> d2.Write([]byte(m2))
>> d2.Write([]byte(m3))
>> d2.Sum(nil)
>> }
>> }
>>
>> func copyHash(src hash.Hash) hash.Hash {
>> typ := reflect.TypeOf(src).Elem()
>> val := reflect.ValueOf(src).Elem()
>> elem := reflect.New(typ).Elem()
>> elem.Set(val)
>> return elem.Addr().Interface().(hash.Hash)
>> }
>>
>>
>>
>>
>>
>>
> --
> 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 opti

[go-nuts] How to get explicit receiver of a method through reflect?

2017-11-22 Thread Hoping White
Hi, all

I known that method of a struct can be a function with explicit receiver,
like this

type Param struct {
v int
}

func (this *Param) Call() {
println(this.v)
}

p := &Param{v:10}
t := p.Call
t()

I wonder how can I get the receiver p from function t through
reflect. Thanks all.

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


[go-nuts] Cross compiling for BIG ENDIAN arm5te?

2017-11-22 Thread tobias . visionstream
Hi list, 

Wondering if it is possible to compile my Go applications into MSB ELF 
binaries for ARM? There appears to be no options and little documentation 
regarding endianness support. If MSB is not supported, is it likely to be 
in the next year or so? 

Thanks,

Tobiz

-- 
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] Sharing code on playground disabled.

2017-11-22 Thread mayank . jha
Is there a reason for disabling it ?

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


[go-nuts] Golang on Android

2017-11-22 Thread ivan . matmati
Hi there,


I'm sure you already tried to find an apk to run your go code on your 
Android tablet.
Certainly, like me you hit a wall. But I've juste discovered something 
unnoticed by most of us.
You can install golang on Android !
How ? Look at my post : https://www.linkedin.com/groups/3712244
Bye.

-- 
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: lambda syntax

2017-11-22 Thread kamyarm
I don't know how you can live without Generics but you can't live without 
Lambda expression. No Go Authors will not listen to anyone. 
If I could(because of the project I am working on) I would never use a 
language like Go and would never look back. There are much better choices 
out there.

On Wednesday, February 5, 2014 at 1:10:35 PM UTC-5, Felix wrote:
>
> Go as a language made a choice to leave certain things out, because
> there is other ways to solve them, I live without generics and am happy,
> no while loop no problem and etc.
>
> But am hoping that the entire Go community + Go team + who ever it may 
> concern
> that we all accept that we need a lambda syntax,
>
> ---
>
> (input parameters) => expression
>
> ---
>
> (x, y) => x == y
>
> ---
>
> () => SomeMethod()
>
> ---
>
> this will really help with things like
> implementing linq like in go check 
> https://github.com/ahmetalpbalkan/go-linq 
> ( 
> https://groups.google.com/forum/#!topicsearchin/golang-nuts/lambda%7Csort:date%7Cspell:true/golang-nuts/L-kxltsynh0
>  
> )
>
> Am looking at the lambda expression from C# 
> http://msdn.microsoft.com/en-us/library/bb397687.aspx
> this will make functional things nice in Go
>
> implementing a map over a slice like 
>
> arr := []int{2, 3, 4}
> map(x => x * 2, arr)
>
> simpler that
> map(func(x int){ x * 2}, arr)
>
> So please Command Pike don't tell me no :-)
>

-- 
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 Code Debugging

2017-11-22 Thread shanthkumar . s079


Hi Go Experts,

 Could you please share steps to debug go code using breakpoints in eclipse?

 Does it requires any third party tool.?


*Thanks and Regards*
*Shantkumar.S*

-- 
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] Sharing code on playground disabled.

2017-11-22 Thread 'Axel Wagner' via golang-nuts
AFAIK the Go playground has IP-based restrictions for when you are in an
export-restricted country (like Iran), just like golang.org is not
reachable there. The reason being, that US-laws are forbidding it. There
are several threads on golang-nuts and github discussing that, which you
can probably search for (but I don't think they have significantly more
detail about this). It's unfortunate, but a project hosted in the US has to
comply with US regulations.

On Wed, Nov 22, 2017 at 7:15 AM,  wrote:

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

-- 
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] Sharing code on playground disabled.

2017-11-22 Thread mayank jha
Does singapore come under restrictions ?

On Nov 22, 2017 10:08 PM, "Axel Wagner" 
wrote:

> AFAIK the Go playground has IP-based restrictions for when you are in an
> export-restricted country (like Iran), just like golang.org is not
> reachable there. The reason being, that US-laws are forbidding it. There
> are several threads on golang-nuts and github discussing that, which you
> can probably search for (but I don't think they have significantly more
> detail about this). It's unfortunate, but a project hosted in the US has to
> comply with US regulations.
>
> On Wed, Nov 22, 2017 at 7:15 AM,  wrote:
>
>> Is there a reason for disabling it ?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 get explicit receiver of a method through reflect?

2017-11-22 Thread Josh Humphries
The reflection package provides no way to do this. Even if it were possible
to do with unsafe (not even sure it is, but maybe?), it would be brittle
and tied to an undocumented representation of a function and its captured
variables.

Instead, use a single-method interface. It's easy to create a factory
method that takes a function and adapts it to the interface. And then the
value can be used both to invoke the logic (by calling the one method of
the interface) and for inspecting its concrete type and value.



*Josh Humphries*
jh...@bluegosling.com

On Wed, Nov 22, 2017 at 8:26 AM, Hoping White  wrote:

> Hi, all
>
> I known that method of a struct can be a function with explicit receiver,
> like this
>
> type Param struct {
> v int
> }
>
> func (this *Param) Call() {
> println(this.v)
> }
>
> p := &Param{v:10}
> t := p.Call
> t()
>
> I wonder how can I get the receiver p from function t through
> reflect. Thanks all.
>
> --
> 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] Sharing code on playground disabled.

2017-11-22 Thread 'Axel Wagner' via golang-nuts
I don't know, sorry. The filter might also be applied to other IP ranges
(e.g. Tor?). I know, that I was, at some point, on a network which had the
same problem (I think it was some mobile network? I don't remember), even
though I never visited an export restricted country.

All I can say is a) the playground works fine for me and b) I suspect that
this filter is at fault and a tunnel might help. Sorry that I can't be of
more help.

On Wed, Nov 22, 2017 at 3:09 PM, mayank jha 
wrote:

> Does singapore come under restrictions ?
>
> On Nov 22, 2017 10:08 PM, "Axel Wagner" 
> wrote:
>
>> AFAIK the Go playground has IP-based restrictions for when you are in an
>> export-restricted country (like Iran), just like golang.org is not
>> reachable there. The reason being, that US-laws are forbidding it. There
>> are several threads on golang-nuts and github discussing that, which you
>> can probably search for (but I don't think they have significantly more
>> detail about this). It's unfortunate, but a project hosted in the US has to
>> comply with US regulations.
>>
>> On Wed, Nov 22, 2017 at 7:15 AM,  wrote:
>>
>>> Is there a reason for disabling it ?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to golang-nuts+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>

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


Re: [go-nuts] Cross compiling for BIG ENDIAN arm5te?

2017-11-22 Thread Ian Lance Taylor
On Tue, Nov 21, 2017 at 7:43 PM,   wrote:
>
> Wondering if it is possible to compile my Go applications into MSB ELF
> binaries for ARM? There appears to be no options and little documentation
> regarding endianness support. If MSB is not supported, is it likely to be in
> the next year or so?

There is no current support for armbe, and nobody is currently working on it.

I expect that it would be an easy port if somebody wants to tackle it.
Probably the hardest thing would be providing a reliable builder, as
required by https://golang.org/wiki/PortingPolicy .

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: Go Code Debugging

2017-11-22 Thread gary . willoughby
I think it's a nightmare to set Eclipse up to support Go. Here's a 20 
minute tutorial:

https://www.youtube.com/watch?v=v6Wn5gUSEwM

If you fancy swapping editor, try Visual Studio Code. It's Go support is 
second to none (just install the Go plugin and you're done) and has 
excellent debugging support.

On Wednesday, 22 November 2017 13:28:39 UTC, shanthku...@gmail.com wrote:
>
>
>
> Hi Go Experts,
>
>  Could you please share steps to debug go code using breakpoints in 
> eclipse?
>
>  Does it requires any third party tool.?
>
>
> *Thanks and Regards*
> *Shantkumar.S*
>

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


Re: [go-nuts] Re: Go Code Debugging

2017-11-22 Thread Tyler Compton
If you're looking for an Eclipse-like IDE experience, you may also want to
check out Goland. I don't personally use it but I've heard a lot of good
things about it and it has debugging support.

On Wed, Nov 22, 2017 at 8:47 AM  wrote:

> I think it's a nightmare to set Eclipse up to support Go. Here's a 20
> minute tutorial:
>
> https://www.youtube.com/watch?v=v6Wn5gUSEwM
>
> If you fancy swapping editor, try Visual Studio Code. It's Go support is
> second to none (just install the Go plugin and you're done) and has
> excellent debugging support.
>
> On Wednesday, 22 November 2017 13:28:39 UTC, shanthku...@gmail.com wrote:
>>
>>
>>
>> Hi Go Experts,
>>
>>  Could you please share steps to debug go code using breakpoints in
>> eclipse?
>>
>>  Does it requires any third party tool.?
>>
>>
>> *Thanks and Regards*
>> *Shantkumar.S*
>>
> --
> 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: various odd, to me, at best undocumented, behaviour of automatic formatting in go doc

2017-11-22 Thread 'simon place' via golang-nuts
thanks for looking, you have understood and argued well against my points 
being significant.

i was trying to show-up, and see if there was agreement, that this code 
could benefit from some re-factoring/simplification.

but my problem is; i have an html doc that looks quite poor, but according 
to the documentation shouldn't, so for now, i guess i'm going to have to 
try to rewrite some comments so they look nice with, or without, the 
'implicit rule' in effect, you know, in-case it goes away in the future.

-- 
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: lambda syntax

2017-11-22 Thread Tyler Compton
It's usually best to create a new thread instead of responding to one
that's so old (more than three years in this case).

On Wed, Nov 22, 2017 at 6:28 AM  wrote:

> I don't know how you can live without Generics but you can't live without
> Lambda expression. No Go Authors will not listen to anyone.
> If I could(because of the project I am working on) I would never use a
> language like Go and would never look back. There are much better choices
> out there.
>
> On Wednesday, February 5, 2014 at 1:10:35 PM UTC-5, Felix wrote:
>>
>> Go as a language made a choice to leave certain things out, because
>> there is other ways to solve them, I live without generics and am happy,
>> no while loop no problem and etc.
>>
>> But am hoping that the entire Go community + Go team + who ever it may
>> concern
>> that we all accept that we need a lambda syntax,
>>
>> ---
>>
>> (input parameters) => expression
>>
>> ---
>>
>> (x, y) => x == y
>>
>> ---
>>
>> () => SomeMethod()
>>
>> ---
>>
>> this will really help with things like
>> implementing linq like in go check
>> https://github.com/ahmetalpbalkan/go-linq
>> (
>> https://groups.google.com/forum/#!topicsearchin/golang-nuts/lambda%7Csort:date%7Cspell:true/golang-nuts/L-kxltsynh0
>> )
>>
>> Am looking at the lambda expression from C#
>> http://msdn.microsoft.com/en-us/library/bb397687.aspx
>> this will make functional things nice in Go
>>
>> implementing a map over a slice like
>>
>> arr := []int{2, 3, 4}
>> map(x => x * 2, arr)
>>
>> simpler that
>> map(func(x int){ x * 2}, arr)
>>
>> So please Command Pike don't tell me no :-)
>>
> --
> 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] x/crypto/ssh/agent: Accept Flags in Agent.Sign()

2017-11-22 Thread KH Cheng


I was trying unsuccessfully to get ssh-agent to sign a JWT via the 
x/crypto/ssh/agent.Agent::Sign() interface.

In https://github.com/golang/crypto/blob/master/ssh/agent/client.go#L371, 
the Flags in signRequestAgentMsg was left as default (0).


req := ssh.Marshal(signRequestAgentMsg{
KeyBlob: key.Marshal(),
Data:data,
})


In OpenSSH ssh-agent, 
https://github.com/openssh/openssh-portable/blob/master/ssh-agent.c#L262, 
the signing algorithm is being determined by parsing the flags sent in the 
signRequestAgentMsg - 2 for rsa-sha2-256 and 4 for rsa-sha2-512, and 
sending 0 probably defaults the algorithm to SHA1.


It seems that allowing the caller to specify flags, or at a higher level, 
an algorithm name, would be able to resolve this, but I'm not sure what is 
the best way to implement this.

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


[go-nuts] Interest in implementing dual-pivot or 3-pivot quicksort for faster sorting?

2017-11-22 Thread David McManamon
Sometimes it takes years for great technical papers to be implemented.  As 
a fun exercise to compare Java's dual-pivot (since so much work went into 
it) with the 3-pivot described in the paper:
Multi-Pivot Quicksort: Theory and Experiments 
downloaded from:
http://epubs.siam.org/doi/pdf/10.1137/1.9781611973198.6 
I wrote the 3-pivot quicksort described in the paper and for sorting 10 
million elements it was about 10% faster than Arrays.sort() and completes 
in 1 second on my 2013 computer.
Feel free to run the code if you have any doubts:

https://github.com/dmcmanam/quicksort/tree/master/src

And I wrote a quick blog post for background which also explains why I'm 
looking for languages like Go to implement this in:

https://refactoringlightly.wordpress.com/2017/11/21/multi-pivot-quicksort-aka-3-pivot-quicksort/

Any interest in working with me to write a Go version?  Some discussion & 
pair programming would be fun since so far I have only written 1 go 
algorithm - AVL trees since I was surprised to see people using LLRB in Go 
but I was guessing there is less interest in better balanced binary search 
trees.  The project would have a few steps, working on benchmarks for edge 
cases, etc.  

--David

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


[go-nuts] Beginner Question About Structure Initialization

2017-11-22 Thread jlforrest
 I'm learning Go (using 1.9.2 on Centos 7). Consider the following 
trivial program, which works fine: 

package main 
import "fmt" 
type symbol struct { 
name string 
fn func(int) 
options int 
} 
func main() { 
symbols := [] symbol { 
{"jon",x, 4}, 
} 
symbols[0].fn(13) 
fmt.Println("symbols:  ", symbols) 
} 
func x(arg int) { 
fmt.Println("x: arg = ", arg) 
} 

This does what I expect, which is to show how to 
initialize a structure to contain various values. 

I then tried to modify this program so that the structure 
initialization is done outside any function, like so: 

package main 
import "fmt" 
type symbol struct { 
name string 
fn func(int) 
options int 
} 
var symbols = [] symbol  { 
{"jon",x, 4,} 
} 
func main() { 
symbols[0].fn(13) 
fmt.Println("symbols:  ", symbols) 
} 
func x(arg int) { 
fmt.Println("x: arg = ", arg) 
} 

However, this doesn't compile, saying 
./bad.go:12:18: syntax error: unexpected newline, expecting comma or } 

I don't understand how to fix this. I have to admit that I don't 
know why one style would be preferred over the other, but I'd like to 
understand how to correct the second case. 

Cordially, 
Jon Forrest 

-- 
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] Beginner Question About Structure Initialization

2017-11-22 Thread Jan Mercl
On Wed, Nov 22, 2017 at 7:03 PM  wrote:

> ./bad.go:12:18: syntax error: unexpected newline, expecting comma or }

Fixed: https://play.golang.org/p/fk_fopK6V1

-- 

-j

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


[go-nuts] Re: various odd, to me, at best undocumented, behaviour of automatic formatting in go doc

2017-11-22 Thread 'simon place' via golang-nuts
trying to work around these issues, i find another undocumented 'feature'

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


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


[go-nuts] Re: Beginner Question About Structure Initialization

2017-11-22 Thread jlforrest
Thanks for the quick reply! I should have seen that. Sorry for the noise.

Jon


-- 
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: Efficient to copy Hash?

2017-11-22 Thread 'simon place' via golang-nuts
thanks, 

this cloning is an optimisation, slowing it down a lot makes it pointless 
to begin with, but luckily really, the program produced has a built-in list 
of selectable, std.lib., hash routines to select from.

i will add a warning for someone forking it about this. 


BTW your improved cloning reflection code proved much faster;

func cloneHash(h hash.Hash) hash.Hash{
return clone(h).(hash.Hash)
}

func clone(i interface{}) interface{} {
hv := reflect.ValueOf(i)
hv1 := reflect.New(hv.Type().Elem())
hv1.Elem().Set(hv.Elem())
return hv1.Interface()
}   



On Wednesday, 22 November 2017 13:16:01 UTC, rog wrote:
>
> On 21 November 2017 at 21:56, 'simon place' via golang-nuts 
> > wrote: 
> > i found this code, and use it on hash.Hash 
> > 
> > // copy an interface value using reflect (here for pointers to 
> interfaces) 
> > func clone(i interface{}) interface{} { 
> > indirect := reflect.Indirect(reflect.ValueOf(i)) 
> > newIndirect := reflect.New(indirect.Type()) 
> > newIndirect.Elem().Set(reflect.ValueOf(indirect.Interface())) 
> > return newIndirect.Interface() 
> > } 
> > 
> > like this; 
> > 
> > branchHasher = clone(hasher).(hash.Hash) 
>
> Although this works on most hash implementations in the standard library, 
> I'm not sure I'd recommend doing this, as it depends on the fact that 
> all the state in the hash implementations will copied with a shallow copy. 
>
> Better (albeit less efficient) would be something like this, I think: 
>
> func CloneHash(h hash.Hash) hash.Hash { 
> type codec interface { 
> hash.Hash 
> encoding.BinaryMarshaler 
> encoding.BinaryUnmarshaler 
> } 
> mh, ok := h.(codec) 
> if !ok { 
> panic(fmt.Errorf("hash %T cannot be cloned", h)) 
> } 
> data, err := mh.MarshalBinary() 
> if err != nil { 
> panic(fmt.Errorf("hash %T marshal failed: %v", h, err)) 
> } 
> t := reflect.TypeOf(h) 
> if t.Kind() != reflect.Ptr { 
> panic(fmt.Errorf("hash %T is not of pointer type", h)) 
> } 
>
> mh1 := reflect.New(t.Elem()).Interface().(codec) 
> if err := mh1.UnmarshalBinary(data); err != nil { 
> panic(fmt.Errorf("hash %T unmarshal failed: %v", mh1, err)) 
> } 
> return mh1 
> } 
>
> I could understand why you might use your original version for performance 
> reasons, though. It could be a little simpler, I think: 
>
> // CloneHash clones the current state of the given 
> // hash. It works with most implementations in the standard 
> // library but is not guaranteed to work with all Hash 
> // implementations. 
> func CloneHash(h hash.Hash) hash.Hash { 
> hv := reflect.ValueOf(h) 
> hv1 := reflect.New(hv.Type().Elem()) 
> hv1.Elem().Set(hv.Elem()) 
> return hv1.Interface().(hash.Hash) 
> } 
>
> If I was using it in production code, I'd probably be defensive and do 
> something 
> like this: 
>
> https://play.golang.org/p/QDUlwuFAuv 
>
> I think that even now that hashes that implement encoding.BinaryMarshaler 
> and 
> encoding.BinaryUnmarshaler, there's probably still room for a Clone method 
> (or perhaps a top level hash.Clone function) in the standard library to 
> avoid 
> the necessity for this kind of thing. 
>
> > 
> > 
> > On Wednesday, 8 November 2017 12:54:18 UTC, Christian LeMoussel wrote: 
> >> 
> >> Hi, 
> >> 
> >> I want to calculate hash on 3 strings. First string is always the same, 
> >> the other may vary. 
> >> The first approach is to calculate the hash each time for the 3 strings 
> >> (BenchmarkHash) 
> >> Another approach would be to calculate once for the first string, and 
> then 
> >> reuse this hash to calculate the hash with the other 2 
> >> strings(BenchmarkCopyHash) 
> >> The difficulty is that sha256.New() returns a pointer, we have to copy 
> the 
> >> first hash. To do this, I created the function copyHash() 
> >> But the performances are not exceptional. 
> >> 
> >> Do you have another idea to do this in efficient way? 
> >> 
> >> 
> >> BenchmarkHash-8  100  1761 ns/op 
> >> 176 B/op  4 allocs/op 
> >> BenchmarkCopyHash-8  100  1519 ns/op 
> >> 240 B/op  4 allocs/op 
> >> 
> >> 
> >> var m1 = strings.Repeat("a", 64) 
> >> var m2 = strings.Repeat("b", 48) 
> >> var m3 = strings.Repeat("c", 32) 
> >> 
> >> func BenchmarkHash(b *testing.B) { 
> >> var ( 
> >> d hash.Hash 
> >> ) 
> >> 
> >> d = sha256.New() 
> >> for n := 0; n < b.N; n++ { 
> >> d.Reset() 
> >> d.Write([]byte(m1)) 
> >> d.Write([]byte(m2)) 
> >> d.Write([]byte(m3)) 
> >> d.Sum(nil) 
> >> } 
> >> } 
> >> func BenchmarkCopyHash(b *testing.B) { 
> >> var ( 
> >> d1 hash.Hash 
> >> d2 hash.Hash 
> >> ) 
> >> 
> 

Re: [go-nuts] question about GO and realtime GC interest by the user community

2017-11-22 Thread David Beberman
Hi John,
I don't know what firm realtime means.
I did look at GO's GC a bit. I'm not the expert in this, others in my 
company are.

On the question of realtime thread priorities, that is a requirement, as is 
priority inheritance.
For hard realtime systems, you want essentially "unfair" scheduling for the 
realtime
threads.
Probably significant work, but we do have the advantage of almost 2 decades
experience with hard realtime GCs.

I'm trying to gauge the market interest in doing this.
I haven't seen a lot of response on it.

David 

On Thursday, November 9, 2017 at 2:58:27 PM UTC-5, John Souvestre wrote:
>
> I occasionally see projects which have hard real-time requirements, so I’m 
> interested.
>
>  
>
> I understand your concern with GC but you have looked at Go’s current GC?  
> I don’t know if its limits (max pause time, max overhead) are “hard” but 
> they are stated.  The one which isn’t is latency due to stopping goroutines 
> since they aren’t exactly pre-emptible.  But there’s been some talk about 
> addressing this.
>
>  
>
> I would think that you would need to add priorities and perhaps fairness 
> guarantees to scheduling and synchronization methods.
>
>  
>
> It certainly sounds like a lot of work!  Perhaps firm real-time would be a 
> good first step?
>
>  
>
> John
>
> John Souvestre - New Orleans LA
>
>  
>
> *From:* golan...@googlegroups.com  [mailto:
> golan...@googlegroups.com ] *On Behalf Of *David Beberman
> *Sent:* 2017 November 09, Thu 05:59
> *To:* golang-nuts
> *Subject:* [go-nuts] question about GO and realtime GC interest by the 
> user community
>
>  
>
> Hi,
> I asked this on the golang-dev list.  They redirected me here.
> We are a hard realtime JavaVM GC company.  By hard realtime
> we mean that the GC is preemptible, reentrant, non-blocking, non-pausing.
> For multicore it is also parallel and concurrent.
> Further for realtime we support priority inheritance for synchronization 
> primitives, and of course hard realtime thread priorities.
>
> GO's requirements for GC are slightly different. The concept
> would be to add our hard RTGC to the GO runtime without
> disrupting the language.  
>
> My question is about the interest level in the GO user community.
> We have developed and marketed hard realtime Java bytecode VM's
> for 16+ years.  
> GO looks like the new kid on the block.  Maybe it moves into 
> realtime use-cases, maybe it doesn't.
>
> Kind of doing an extremely informal poll here.  
> Open to any thoughts, comments.
>
> Thanks 
> David Beberman
> Aicas GmbH
>
> -- 
> 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] Re: Efficient to copy Hash?

2017-11-22 Thread roger peppe
On 22 November 2017 at 18:57, 'simon place' via golang-nuts
 wrote:
> thanks,
>
> this cloning is an optimisation, slowing it down a lot makes it pointless to
> begin with, but luckily really, the program produced has a built-in list of
> selectable, std.lib., hash routines to select from.
>
> i will add a warning for someone forking it about this.
>
>
> BTW your improved cloning reflection code proved much faster;

That's good to hear :)

>
> func cloneHash(h hash.Hash) hash.Hash{
> return clone(h).(hash.Hash)
> }
>
> func clone(i interface{}) interface{} {
> hv := reflect.ValueOf(i)
> hv1 := reflect.New(hv.Type().Elem())
> hv1.Elem().Set(hv.Elem())
> return hv1.Interface()
> }
>
>
>
> On Wednesday, 22 November 2017 13:16:01 UTC, rog wrote:
>>
>> On 21 November 2017 at 21:56, 'simon place' via golang-nuts
>>  wrote:
>> > i found this code, and use it on hash.Hash
>> >
>> > // copy an interface value using reflect (here for pointers to
>> > interfaces)
>> > func clone(i interface{}) interface{} {
>> > indirect := reflect.Indirect(reflect.ValueOf(i))
>> > newIndirect := reflect.New(indirect.Type())
>> > newIndirect.Elem().Set(reflect.ValueOf(indirect.Interface()))
>> > return newIndirect.Interface()
>> > }
>> >
>> > like this;
>> >
>> > branchHasher = clone(hasher).(hash.Hash)
>>
>> Although this works on most hash implementations in the standard library,
>> I'm not sure I'd recommend doing this, as it depends on the fact that
>> all the state in the hash implementations will copied with a shallow copy.
>>
>> Better (albeit less efficient) would be something like this, I think:
>>
>> func CloneHash(h hash.Hash) hash.Hash {
>> type codec interface {
>> hash.Hash
>> encoding.BinaryMarshaler
>> encoding.BinaryUnmarshaler
>> }
>> mh, ok := h.(codec)
>> if !ok {
>> panic(fmt.Errorf("hash %T cannot be cloned", h))
>> }
>> data, err := mh.MarshalBinary()
>> if err != nil {
>> panic(fmt.Errorf("hash %T marshal failed: %v", h, err))
>> }
>> t := reflect.TypeOf(h)
>> if t.Kind() != reflect.Ptr {
>> panic(fmt.Errorf("hash %T is not of pointer type", h))
>> }
>>
>> mh1 := reflect.New(t.Elem()).Interface().(codec)
>> if err := mh1.UnmarshalBinary(data); err != nil {
>> panic(fmt.Errorf("hash %T unmarshal failed: %v", mh1, err))
>> }
>> return mh1
>> }
>>
>> I could understand why you might use your original version for performance
>> reasons, though. It could be a little simpler, I think:
>>
>> // CloneHash clones the current state of the given
>> // hash. It works with most implementations in the standard
>> // library but is not guaranteed to work with all Hash
>> // implementations.
>> func CloneHash(h hash.Hash) hash.Hash {
>> hv := reflect.ValueOf(h)
>> hv1 := reflect.New(hv.Type().Elem())
>> hv1.Elem().Set(hv.Elem())
>> return hv1.Interface().(hash.Hash)
>> }
>>
>> If I was using it in production code, I'd probably be defensive and do
>> something
>> like this:
>>
>> https://play.golang.org/p/QDUlwuFAuv
>>
>> I think that even now that hashes that implement encoding.BinaryMarshaler
>> and
>> encoding.BinaryUnmarshaler, there's probably still room for a Clone method
>> (or perhaps a top level hash.Clone function) in the standard library to
>> avoid
>> the necessity for this kind of thing.
>>
>> >
>> >
>> > On Wednesday, 8 November 2017 12:54:18 UTC, Christian LeMoussel wrote:
>> >>
>> >> Hi,
>> >>
>> >> I want to calculate hash on 3 strings. First string is always the same,
>> >> the other may vary.
>> >> The first approach is to calculate the hash each time for the 3 strings
>> >> (BenchmarkHash)
>> >> Another approach would be to calculate once for the first string, and
>> >> then
>> >> reuse this hash to calculate the hash with the other 2
>> >> strings(BenchmarkCopyHash)
>> >> The difficulty is that sha256.New() returns a pointer, we have to copy
>> >> the
>> >> first hash. To do this, I created the function copyHash()
>> >> But the performances are not exceptional.
>> >>
>> >> Do you have another idea to do this in efficient way?
>> >>
>> >>
>> >> BenchmarkHash-8  100  1761 ns/op
>> >> 176 B/op  4 allocs/op
>> >> BenchmarkCopyHash-8  100  1519 ns/op
>> >> 240 B/op  4 allocs/op
>> >>
>> >>
>> >> var m1 = strings.Repeat("a", 64)
>> >> var m2 = strings.Repeat("b", 48)
>> >> var m3 = strings.Repeat("c", 32)
>> >>
>> >> func BenchmarkHash(b *testing.B) {
>> >> var (
>> >> d hash.Hash
>> >> )
>> >>
>> >> d = sha256.New()
>> >> for n := 0; n < b.N; n++ {
>> >> d.Reset()
>> >> d.Write([]byte(m1))
>> >> d.Write([]byte(m2))
>> >> d.Write([]byte(m3))
>> >> d.Sum(nil)
>> >> }
>>

[go-nuts] Introspecting a type

2017-11-22 Thread Hein Meling
I have code like this:
type TestCase struct {
Namestring
Description string
OrderOp [][]Operation
}

type Concurrent []Operation
type Sequential []Operation

With the intent to do things like this:
OrderOp: [][]Operation{
Concurrent{
{ID: "A", Name: "Read", ArgumentType: "ReadRequest", Value: ""},
{ID: "B", Name: "Write", ArgumentType: "Value", Value: "7"},
},
Sequential{
{ID: "C", Name: "Read", ArgumentType: "ReadRequest", Value: ""},
{ID: "D", Name: "Write", ArgumentType: "Value", Value: "8"},
},
}

However, it seems that the OrderOp array do not preserve the type 
information, and I cannot use type assertion or reflect.TypeOf() to recover 
the types Concurrent and Sequential, that I intended to. For a full 
example, see link below.

My question is: How can I best work around this problem??

(Preferably without adding a separate field in a struct to discriminate 
between concurrent and sequential.)

https://github.com/selabhvl/cpnmbt/blob/master/rwregister/table_test.go

Thanks,
:) Hein

-- 
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 get explicit receiver of a method through reflect?

2017-11-22 Thread Hoping White
Thanks Josh. Yes, a single-method interface can do the job. I just want to
know the unsafe way for curiosity. could you please explain more?

2017-11-22 22:12 GMT+08:00 Josh Humphries :

> The reflection package provides no way to do this. Even if it were
> possible to do with unsafe (not even sure it is, but maybe?), it would be
> brittle and tied to an undocumented representation of a function and its
> captured variables.
>
> Instead, use a single-method interface. It's easy to create a factory
> method that takes a function and adapts it to the interface. And then the
> value can be used both to invoke the logic (by calling the one method of
> the interface) and for inspecting its concrete type and value.
>
>
> 
> *Josh Humphries*
> jh...@bluegosling.com
>
> On Wed, Nov 22, 2017 at 8:26 AM, Hoping White 
> wrote:
>
>> Hi, all
>>
>> I known that method of a struct can be a function with explicit receiver,
>> like this
>>
>> type Param struct {
>> v int
>> }
>>
>> func (this *Param) Call() {
>> println(this.v)
>> }
>>
>> p := &Param{v:10}
>> t := p.Call
>> t()
>>
>> I wonder how can I get the receiver p from function t through
>> reflect. Thanks all.
>>
>> --
>> 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] Sharing code on playground disabled.

2017-11-22 Thread Dave Cheney
Please raise a bug with your IP address. https://golang.org/issue/new and it 
will be escalated to the groups that manage the geoip database

-- 
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: Interest in implementing dual-pivot or 3-pivot quicksort for faster sorting?

2017-11-22 Thread Agniva De Sarker
This definitely sounds interesting. Will be glad to help out.



On Wednesday, 22 November 2017 23:33:18 UTC+5:30, David McManamon wrote:
>
> Sometimes it takes years for great technical papers to be implemented.  As 
> a fun exercise to compare Java's dual-pivot (since so much work went into 
> it) with the 3-pivot described in the paper:
> Multi-Pivot Quicksort: Theory and Experiments 
> downloaded from:
> http://epubs.siam.org/doi/pdf/10.1137/1.9781611973198.6 
> I wrote the 3-pivot quicksort described in the paper and for sorting 10 
> million elements it was about 10% faster than Arrays.sort() and completes 
> in 1 second on my 2013 computer.
> Feel free to run the code if you have any doubts:
>
> https://github.com/dmcmanam/quicksort/tree/master/src
>
> And I wrote a quick blog post for background which also explains why I'm 
> looking for languages like Go to implement this in:
>
>
> https://refactoringlightly.wordpress.com/2017/11/21/multi-pivot-quicksort-aka-3-pivot-quicksort/
>
> Any interest in working with me to write a Go version?  Some discussion & 
> pair programming would be fun since so far I have only written 1 go 
> algorithm - AVL trees since I was surprised to see people using LLRB in Go 
> but I was guessing there is less interest in better balanced binary search 
> trees.  The project would have a few steps, working on benchmarks for edge 
> cases, etc.  
>
> --David
>

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


Re: [go-nuts] Introspecting a type

2017-11-22 Thread Jakob Borg
A variable of type [][]Operation has that type and only that type. Your 
Concurrent and Sequential types are convertible to []Operation, and this is 
what happens in the assignment.

You can probably use interfaces to accomplish what you want.

type Operator interface {
Operations() []Operation
}

Make Concurrent and Sequential distinct types that both implement Operations() 
[]Operation. This can be as simple as

type Concurrent []Operation

func (c Concurrent) Operations() []Operation {
return c
}

Make your top level thing an []Operator. Use type switching or further 
interface methods as appropriate.

//jb

On 23 Nov 2017, at 00:39, Hein Meling 
mailto:hein.mel...@gmail.com>> wrote:

I have code like this:
type TestCase struct {
Namestring
Description string
OrderOp [][]Operation
}

type Concurrent []Operation
type Sequential []Operation

With the intent to do things like this:
OrderOp: [][]Operation{
Concurrent{
{ID: "A", Name: "Read", ArgumentType: "ReadRequest", Value: ""},
{ID: "B", Name: "Write", ArgumentType: "Value", Value: "7"},
},
Sequential{
{ID: "C", Name: "Read", ArgumentType: "ReadRequest", Value: ""},
{ID: "D", Name: "Write", ArgumentType: "Value", Value: "8"},
},
}

However, it seems that the OrderOp array do not preserve the type information, 
and I cannot use type assertion or reflect.TypeOf() to recover the types 
Concurrent and Sequential, that I intended to. For a full example, see link 
below.

My question is: How can I best work around this problem??

(Preferably without adding a separate field in a struct to discriminate between 
concurrent and sequential.)

https://github.com/selabhvl/cpnmbt/blob/master/rwregister/table_test.go

Thanks,
:) Hein

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