Re: [go-nuts] [crypto/x509] SystemCertPool() print subjects of ca certs

2018-10-31 Thread Natxo Asenjo


On Wednesday, October 31, 2018 at 10:46:41 PM UTC+1, golan...@geek1.de 
wrote:
>
> Hy Natxo, 
>
> check out the pkix [0] and asn1 [1] packages. You can try to parse the 
> DER encoded subject into RDNSequence. 
>
> [0]: https://golang.org/pkg/crypto/x509/pkix/#RDNSequence 
> [1]: https://golang.org/pkg/encoding/asn1/#Unmarshal 
>
> Spoiler: 
>
> This should work: 
>
> package main 
>
> import "fmt" 
> import "crypto/x509" 
> import "encoding/asn1" 
> import "crypto/x509/pkix" 
>
> func main() { 
>   store, err := x509.SystemCertPool() 
>   if err != nil { 
> panic(err) 
>   } 
>   subjects := store.Subjects() 
>   for _, rawSubject := range subjects { 
> var subject pkix.RDNSequence 
> if _, err := asn1.Unmarshal(rawSubject, ); err != nil { 
>   panic(err) 
> } 
> fmt.Printf("%+v\n", subject) 
>   } 
> } 
>
> The unmarshal code is borrowed from https://stackoverflow.com/a/50640119 
>
> Cheers, 
> Michael 
>
>  
Hi,

it works beautifully. Thanks a lot.

-- 
regards,
Natxo

-- 
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] [crypto/x509] SystemCertPool() print subjects of ca certs

2018-10-31 Thread golang-nuts via golang-nuts
Hy Natxo,

check out the pkix [0] and asn1 [1] packages. You can try to parse the
DER encoded subject into RDNSequence.

[0]: https://golang.org/pkg/crypto/x509/pkix/#RDNSequence
[1]: https://golang.org/pkg/encoding/asn1/#Unmarshal

Spoiler:

This should work:

package main

import "fmt"
import "crypto/x509"
import "encoding/asn1"
import "crypto/x509/pkix"

func main() {
  store, err := x509.SystemCertPool()
  if err != nil {
panic(err)
  }
  subjects := store.Subjects()
  for _, rawSubject := range subjects {
var subject pkix.RDNSequence
if _, err := asn1.Unmarshal(rawSubject, ); err != nil {
  panic(err)
}
fmt.Printf("%+v\n", subject)
  }
}

The unmarshal code is borrowed from https://stackoverflow.com/a/50640119

Cheers,
Michael

On 31.10.18 21:04, Natxo Asenjo wrote:
> hi,
> 
> as a learning exercise I would lke to loop through the system's
> certificate authorities store, and get the subjects of each certificate
> authority.
> 
> I have this code:
> 
> package main
> 
> import "fmt"
> import "crypto/x509"
> 
> func main() {
>     store, err := x509.SystemCertPool()
>     if err != nil {
>         panic(err)
>     }
>     fmt.Printf("%T\n", store)
>     subjects := store.Subjects()
>     fmt.Printf("%T\n", subjects)
>     for _, v := range subjects {
>         fmt.Printf("%T\n", v)
>         fmt.Println(string(v))
>     }
> }
> 
> But I am getting a lot of gibberish.
> 
> There should be a better way to do this, but I obviously do not know it.
> 
> Thanks for any pointers.
> 
> -- 
> regards,
> Natxo
> 
> -- 
> 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] [crypto/x509] SystemCertPool() print subjects of ca certs

2018-10-31 Thread Natxo Asenjo
hi,

as a learning exercise I would lke to loop through the system's certificate 
authorities store, and get the subjects of each certificate authority.

I have this code:

package main

import "fmt"
import "crypto/x509"

func main() {
store, err := x509.SystemCertPool()
if err != nil {
panic(err)
}
fmt.Printf("%T\n", store)
subjects := store.Subjects()
fmt.Printf("%T\n", subjects)
for _, v := range subjects {
fmt.Printf("%T\n", v)
fmt.Println(string(v))
}
}

But I am getting a lot of gibberish. 

There should be a better way to do this, but I obviously do not know it. 

Thanks for any pointers.

-- 
regards,
Natxo

-- 
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] Go 2 Error Handler Testing

2018-10-31 Thread Liam Breck
On Tue, Oct 30, 2018, 4:08 PM Burak Serdar  wrote:

> On Tue, Oct 30, 2018 at 2:15 PM Liam  wrote:
> >
> > I've compiled an outline of Requirements to Consider for Go 2 Error
> Handling.

> https://gist.github.com/networkimprov/961c9caa2631ad3b95413f7d44a2c98a
> >
> > Recently I was asked about support for a test harness in functions that
> contain error handlers; my document doesn't address this. My first guess is
> that the tooling could generate a function to mirror the one being tested,
> which takes a slice argument with a handler input (or function to call) for
> each handler invocation site in the function:
> >
> > func f(i int) {  // function to test
> >op hname = x(i)
> >handle hname T { ... }
> > }
> > func f_errors(i int, e [1]interface{}) { // generated for go-test
> >op hname = e[0].(T)   // or e[0].(func(int)T)(i)
> >handle hname T { ... }
> > }
> >
> >
> > I'd love to hear other ideas about triggering error handlers from a test
> harness.
>
> You don't need the new handler syntax to do this, although the 'check'
> keyword would make things much easier. You can parse a function,
> identify all error returning calls, and replace them with a call to a
> func() passed in as an argument.
>

Parse & replace, yes above I suggested the compiler could do that in a
testing pass, generating f_errors()

But something like this would be very hard to maintain, I think. When
> you reorganize the function, you need to reorder that []interface
> argument to match.
>

Need to reorder the argument, yes but that only adds burden for functions
whose effect is unchanged by reordering.

I once did something like this, in a Java project, by manually
> instrumenting the code to put named breakpoints, so I can intercept
> the execution. I think in something like this the key is to be able to
> invoke handlers by name, not by sequence. So if you already rewrote
> the function, why not pass in a map[string]func(), keyed by handler
> name?
>

f_errors(..., e map[string]interface{}) is a useful alternative. The
compiler could generate that or f_errors(..., e []interface{}), depending
on the type passed by the caller.

Thanks for the feedback!

-- 
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-Log : A better logger

2018-10-31 Thread Yashish Dua
Hey Gophers, I have built a Go logger package which provides utility on top 
of Go's normal Log package. Check this out!
https://github.com/YashishDua/Go-Log

-- 
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] Correct way to solve slice of interface type problem

2018-10-31 Thread robert engels
If you use interface based design it is repeated through out the code with no 
way to write a performant generic method.

I am not a big fan of ‘reduced lines of code’ creating obscurity the hallmark 
of Go.

In this case I think being able to pass a slice as an read only [] of interface 
makes MORE sense - since if the slice was not read only, in your case you need 
to add another 3 lines to copy the slice back… (and you might even need to do 
some merge/replace code) so a minimum of 6 lines for every method call 
(although if the calls were all of the same interface type, you would only have 
3 at the front and 3 at the end).

It is not a good coding style IMO, and fixing it would be backwards compatible 
and trivial. Sorry but we’ll probably disagree here.

> On Oct 31, 2018, at 11:21 AM, Space A.  wrote:
> 
> It's already trivial 3 lines o code. Readable, light, and simple.
> 
> And it's a question tbh, if topic starter even needs that code, or just a bad 
> implementation.
> 
> 
> среда, 31 октября 2018 г., 18:47:37 UTC+3 пользователь Jake Montgomery 
> написал:
> It is highly likely that when go2 comes out, with generics, it will be 
> trivial to write a ToInterfaceSlice() function that takes a slice of any type 
> T and returns a []interface{}. 
> 
> 
> -- 
> 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] Correct way to solve slice of interface type problem

2018-10-31 Thread Space A.
It's already trivial 3 lines o code. Readable, light, and simple.

And it's a question tbh, if topic starter even needs that code, or just a 
bad implementation.


среда, 31 октября 2018 г., 18:47:37 UTC+3 пользователь Jake Montgomery 
написал:
>
> It is highly likely that when go2 comes out, with generics, it will be 
> trivial to write a ToInterfaceSlice() function that takes a slice of any 
> type T and returns a []interface{}. 
>
>

-- 
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] Correct way to solve slice of interface type problem

2018-10-31 Thread robert engels
That’s not what I mean - the function that you would be calling now (that takes 
the []interface{}) would probably be generic for performance reasons, so you 
wouldn’t need to do the conversion - with generics a lot of interface based 
code can go away - and probably will as people chase peak performance… :( 

Still, as someone opposed to generics in Go, I would love to see read-only 
slices as parameters, so you could pass a []concrete to a slice of []interface 
efficiently and safely (or []InterfaceA as []InterfaceB) This would more than 
suffice in lieu of generics in my book...


> On Oct 31, 2018, at 10:47 AM, jake6...@gmail.com wrote:
> 
> It is highly likely that when go2 comes out, with generics, it will be 
> trivial to write a ToInterfaceSlice() function that takes a slice of any type 
> T and returns a []interface{}. 
> 
> On Tuesday, October 30, 2018 at 8:35:39 PM UTC-4, Justin Israel wrote:
> 
> 
> On Wed, Oct 31, 2018 at 1:32 PM robert engels > wrote:
> I have argued for a runtime/built-in to do this - it is so common…. (if doing 
> “kind of OO” in Go)
> 
> I would love to have the ability to do it with built-in support, but I feel 
> like it would go against the goals of not wanting to hide complexity. It 
> wouldn't be "free" to do it (as far as I know) and I doubt the Go maintainers 
> want it to hide the copy into the new slice. My 2 cents.
>  
> 
> 
>> On Oct 30, 2018, at 7:30 PM, Justin Israel > wrote:
>> 
>> 
>> 
>> On Wed, Oct 31, 2018 at 11:21 AM > wrote:
>> Hello, everyone.
>> Consider following code:
>> 
>> package main
>> 
>> import "fmt"
>> 
>> type implementation struct {
>> d []int
>> }
>> 
>> func (impl *implementation) getData() interface{} {
>> return impl.d
>> }
>> 
>> type phase struct{}
>> 
>> type data interface {
>> getData() interface{}
>> }
>> 
>> func MakeIntDataPhase() *phase {
>> return {}
>> }
>> 
>> func (p *phase) run(population []data) []data {
>> return nil
>> }
>> 
>> func main() {
>> var population []implementation
>> MyPhase := MakeIntDataPhase()
>> fmt.Println(MyPhase.run(population))
>> 
>> }
>> 
>> When running following code in playground I got following error: 
>> prog.go:30:25: cannot use population (type []implementation) as type []data 
>> in argument to MyPhase.run
>> If I understand correctly it is because slice of interface type cannot be 
>> converted by the compiler to concrete type.
>> 
>> What is correct way in golang to implement functionality that is presented 
>> in the example?
>> When method argument defined using a slice of some interface, how I can pass 
>> it a slice of a concrete type that implements the interface?
>> 
>> You would end up needing to just do   
>> 
>> func (p *phase) run(population {}interface) []data
>> 
>> and then type assert the {}interface into []implementation
>> There isn't a way to directly pass a slice of concrete type to a function 
>> that accepts a slice of interface, unless you first do this:
>> 
>> iface := make([]data, len(population))
>> for i, p := range population {
>> iface[i] = p
>> }
>> MyPhase.run(iface)
>> 
>> Justin
>> 
>> -- 
>> 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...@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.


[go-nuts] protobuf spec file browser

2018-10-31 Thread Tharaneedharan Vilwanathan
Hi All,

I am looking for a protobuf spec file browser much like Go source code
browser using IDE like Visual Studio Code (VSC) or a web browser. I tried
VSC but it only does syntax highlighting but it doesn't do things like "Go
to definition".

Any suggestions?

Regards
dharani

-- 
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] database for protobuf - profanedb or similar

2018-10-31 Thread Tharaneedharan Vilwanathan
Thank you all for the response. Let me play with the options.

Regards
dharani


>

-- 
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] Correct way to solve slice of interface type problem

2018-10-31 Thread jake6502
It is highly likely that when go2 comes out, with generics, it will be 
trivial to write a ToInterfaceSlice() function that takes a slice of any 
type T and returns a []interface{}. 

On Tuesday, October 30, 2018 at 8:35:39 PM UTC-4, Justin Israel wrote:
>
>
>
> On Wed, Oct 31, 2018 at 1:32 PM robert engels  > wrote:
>
>> I have argued for a runtime/built-in to do this - it is so common…. (if 
>> doing “kind of OO” in Go)
>>
>
> I would love to have the ability to do it with built-in support, but I 
> feel like it would go against the goals of not wanting to hide complexity. 
> It wouldn't be "free" to do it (as far as I know) and I doubt the Go 
> maintainers want it to hide the copy into the new slice. My 2 cents.
>  
>
>>
>>
>> On Oct 30, 2018, at 7:30 PM, Justin Israel > > wrote:
>>
>>
>>
>> On Wed, Oct 31, 2018 at 11:21 AM > 
>> wrote:
>>
>>> Hello, everyone.
>>> Consider following code:
>>>
>>> package main
>>> import "fmt"
>>>
>>> type implementation struct {
>>> d []int}
>>>
>>> func (impl *implementation) getData() interface{} {
>>> return impl.d}
>>>
>>> type phase struct{}
>>>
>>> type data interface {
>>> getData() interface{}}
>>>
>>> func MakeIntDataPhase() *phase {
>>> return {}}
>>>
>>> func (p *phase) run(population []data) []data {
>>> return nil}
>>>
>>> func main() {
>>> var population []implementation
>>> MyPhase := MakeIntDataPhase()
>>> fmt.Println(MyPhase.run(population))
>>> }
>>>
>>>
>>> When running following code in playground I got following error: 
>>> prog.go:30:25: cannot use population (type []implementation) as type []data 
>>> in argument to MyPhase.run
>>>
>>> If I understand correctly it is because slice of interface type cannot be 
>>> converted by the compiler to concrete type.
>>>
>>>
>>> What is correct way in golang to implement functionality that is presented 
>>> in the example?
>>>
>>> When method argument defined using a slice of some interface, how I can 
>>> pass it a slice of a concrete type that implements the interface?
>>>
>>>
>> You would end up needing to just do   
>>
>> func (p *phase) run(population {}interface) []data
>>
>> and then type assert the {}interface into []implementation
>> There isn't a way to directly pass a slice of concrete type to a function 
>> that accepts a slice of interface, unless you first do this:
>>
>> iface := make([]data, len(population))
>> for i, p := range population {
>> iface[i] = p
>> }
>> MyPhase.run(iface)
>>
>> Justin
>>
>>>
>>> -- 
>>> 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...@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: One-liner README instructions for GitHub cross compiled binary assets

2018-10-31 Thread komuW
TJ's https://github.com/apex/up uses 
https://github.com/goreleaser/godownloader  to generate `curl bash` style 
downloads. 

On Wednesday, 31 October 2018 00:28:17 UTC+3, Paul Jolly wrote:
>
> Hi - I'm hoping someone can point me towards a "best practice" example on 
> adding binary assets to GitHub releases of a program.
>
> Take https://github.com/myitcv/gobin/releases/tag/v0.0.2 as an example. I 
> have added cross compiled binaries as assets to the v0.0.2 release. 
>
> What I would now like to do is provide one-liner release instructions to 
> the README for various OS's.
>
> One issue with the current approach is that when any of those binaries are 
> downloaded the file is missing the execute permissions. That's easily 
> fixable with chmod Or alternatively, I could upload archives instead of 
> the binaries themselves... 
>
> Indeed I'm sure there are plenty of other approaches.
>
> So I'm looking for advice on best practice, best practice that leads to 
> the most sensible one-liner install instructions in READMEs.
>
> Any pointers much appreciated.
>
> Thanks,
>
>
> Paul
>

-- 
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] GopherCon Israel Call for Papers is Open

2018-10-31 Thread Miki Tebeka
Hello Gophers,

GopherCon Israel  CFP is open. Head over to 
https://www.papercall.io/cfps/1422/submissions/new and submit your talk.
If you're not sure, ping me and I'll convince you to submit :)

Please help us spread the word.
- https://www.gophercon.org.il/
- https://twitter.com/gopherconil
- https://www.facebook.com/GopherCon-Israel-436928696811831

Thanks,
Miki

-- 
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: Correct way to solve slice of interface type problem

2018-10-31 Thread Henry
Hi,

You would need to manually convert []implementation to []data. See 
https://play.golang.org/p/DdC8sEGi75-

On Wednesday, October 31, 2018 at 5:21:29 AM UTC+7, Yuri Shafet wrote:
>
> Hello, everyone.
> Consider following code:
>
> package main
> import "fmt"
>
> type implementation struct {
> d []int}
>
> func (impl *implementation) getData() interface{} {
> return impl.d}
>
> type phase struct{}
>
> type data interface {
> getData() interface{}}
>
> func MakeIntDataPhase() *phase {
> return {}}
>
> func (p *phase) run(population []data) []data {
> return nil}
>
> func main() {
> var population []implementation
> MyPhase := MakeIntDataPhase()
> fmt.Println(MyPhase.run(population))
> }
>
>
> When running following code in playground I got following error: 
> prog.go:30:25: cannot use population (type []implementation) as type []data 
> in argument to MyPhase.run
>
> If I understand correctly it is because slice of interface type cannot be 
> converted by the compiler to concrete type.
>
>
> What is correct way in golang to implement functionality that is presented in 
> the example?
>
> When method argument defined using a slice of some interface, how I can pass 
> it a slice of a concrete type that implements the interface?
>
>

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