[go-nuts] What's the -buildid for?

2016-12-18 Thread scauyjf
When I run go build -x, I find that there is -buildid flag in the compile 
and link command. What is it for?

-- 
You received this message because you are subscribed 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: Assign a new value to an already initiated variable in template

2016-12-18 Thread Aliaksandr Valialkin
FYI, complex logic may be easily implemented with alternative template engines 
like https://github.com/valyala/quicktemplate .

-- 
You received this message because you are subscribed 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: howto: compile template against well-known structure ?

2016-12-18 Thread Aliaksandr Valialkin
Take a look at https://github.com/valyala/quicktemplate . Though it is 
incompatible with template/html sytax, it provides static template compilation, 
high performance and go-like syntax.

-- 
You received this message because you are subscribed 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] Timing works fine against a single host, but when probing hosts concurrently the timing is wrong

2016-12-18 Thread ltjbour
Bsically I'm writing an application that traceroutes a given set of hosts 
concurrently. I got the logic pretty much done but I'm having a slight 
problem with the timings. I am measuring the round-trip-times (rtt) of each 
packet with classic method of defining a `begin := time.Now()` variable 
just before sending the payloads, and then defining the `rtt := 
time.Since(begin)` variable right after receiving a response. The problem 
is that when I do this for multiple hosts, most of the timings start 
appearing in microseconds, as if the concurrent goroutines were triggering 
some sort of bug in the timing mechanism. When I probe a single host, I get 
the correct times so that's how I know that the logic and placement of each 
of these `begin` and `rtt` declarations is fine.

Here is an example ready to be compiled and run, showcasing the issue. See 
the outputs I get at the end:

package main

import (
   "golang.org/x/net/ipv4"
   "net"
   "log"
   "fmt"
   "golang.org/x/net/icmp"
   "time"
   "os"
   "strings"
   "sync"
)

func main() {
   fmt.Println("Probing 1 host \n\n")
   getRoutes("www.google.com")
   fmt.Println("Probing 2 hosts \n\n")
   getRoutes("www.facebook.com", "www.twitter.com")
   fmt.Println("Probing 3 hosts \n\n")
   getRoutes("www.google.com", "www.facebook.com", "www.twitter.com")
}

func getRoutes(hosts ...string) {
   ch := make(chan string, len(hosts))
   var wg sync.WaitGroup
   wg.Add(len(hosts))
   for _, host := range hosts {
  host := host
  //time.Sleep(1000*time.Millisecond)
  go func() { defer wg.Done(); trace(host, ch) }()
   }
   go func() { wg.Wait(); close(ch) }()
   for i := range ch {
  fmt.Println(i)
   }
}

func trace(host string, ch chan string) {
   // Tracing an IP packet route
   output := []string{}
   ips, err := net.LookupIP(host)
   if err != nil {
  log.Fatal(err)
   }
   var dst net.IPAddr
   for _, ip := range ips {
  if ip.To4() != nil {
 dst.IP = ip
 output = append(output, fmt.Sprintf("\n\nUsing %v for 
tracing an IP packet route to %s\n\n", dst.IP, host))
 break
  }
   }
   if dst.IP == nil {
  log.Fatal("no A record found")
   }

   c, err := net.ListenPacket("ip4:1", "0.0.0.0") // ICMP for IPv4
   if err != nil {
  log.Fatal(err)
   }
   defer c.Close()
   p := ipv4.NewPacketConn(c)

   id := os.Getpid()

   if err := p.SetControlMessage(ipv4.FlagTTL | ipv4.FlagSrc | ipv4.FlagDst 
| ipv4.FlagInterface, true); err != nil {
  log.Fatal(err)
   }
   wm := icmp.Message{
  Type: ipv4.ICMPTypeEcho, Code: 0,
  Body: {
 ID:   id & 0x,
 Data: []byte(host),
  },
   }

   rb := make([]byte, 1500)

   Query:

   for i := 1; i <= 64; i++ {
  // up to 64 hops
  wm.Body.(*icmp.Echo).Seq = i
  wb, err := wm.Marshal(nil)
  if err != nil {
 log.Fatal(err)
  }
  if err := p.SetTTL(i); err != nil {
 log.Fatal(err)
  }


  begin := time.Now()
  if _, err := p.WriteTo(wb, nil, ); err != nil {
 log.Fatal(err)
  }
  if err := p.SetReadDeadline(time.Now().Add(3 * time.Second)); err 
!= nil {
 log.Fatal(err)
  }

  n, cm, peer, err := p.ReadFrom(rb)
  if err != nil {
 if err, ok := err.(net.Error); ok && err.Timeout() {
fmt.Printf("%v\t*\n", i)
continue
 }
 log.Fatal(err)
  }

  rm, err := icmp.ParseMessage(1, rb[:n])
  if err != nil {
 log.Fatal(err)
  }

  rtt := time.Since(begin)

  mb, _ := rm.Body.Marshal(1)
  switch rm.Type {
  case ipv4.ICMPTypeTimeExceeded:
 if strings.Contains(string(mb), host) {
names, _ := net.LookupAddr(peer.String())
stats := fmt.Sprintf("%d\t%v %+v %v\n\t%+v\n", i, 
peer, names, rtt, cm)
output = append(output, stats)
continue
 }
  case ipv4.ICMPTypeEchoReply:
 if strings.Contains(string(mb), host) {
names, _ := net.LookupAddr(peer.String())
stats := fmt.Sprintf("%d\t%v %+v %v\n\t%+v\n", i, 
peer, names, rtt, cm)
output = append(output, stats)

Re: [go-nuts] x/crypto/ssh server question

2016-12-18 Thread Mark Adams
Hi Andrew!

Take a quick look at the signature for ServerConfig.PublicKeyCallback
:

PublicKeyCallback func(conn ConnMetadata, key PublicKey) (*Permissions,
> error)


As you already know, PublicKeyCallback allows you to indicate whether or
not user authentication is successful by returning an error value. The
other return argument, a pointer to a Permissions struct, actually
addresses your use case. The Permissions
 struct has
CriticalOptions and Extensions properties which are both map[string]string
and can be used to store arbitrary key-value pairs that are looked up
during PublicKeyCallback. Traditionally, PublicKeyCallback would be used to
lookup the key in an authorized_keys file for the user where it could
potentially parse out other configuration values such as force-command or
permit-X11-forwarding to modify how the application behaves when the user
uses that specific key which would then be stored in the Permissions
struct. In the same way, we can use the Permissions struct to pass
arbitrary values based on a database lookup (or other mechanism) from the
authentication phase to the application code. Once PublicKeyCallback
successfully completes, the Permissions struct is made available as a
property of the ServerConn
 struct returned by
ssh.NewServerConn() for your application code to use.

In your case, you could potentially perform your database lookup of the key
during the PublicKeyCallback and store the resulting data (i.e. account_id,
permission level, etc.) in the Permissions.Extensions map and reference
those values via ServerConn.Permissions.Extensions in your application code.

I hope that helps!

Mark


On Sun, Dec 18, 2016 at 5:22 AM  wrote:

> I am trying to get access to get public key that was used to authenticate
> an ssh connection (https://godoc.org/golang.org/x/crypto/ssh#ConnMetadata)
> inside the PublicKeyCallback while handling a channel request. I want to be
> able to accept the connection with any public key, but then control some
> application level permissions based on this key later. Is this possible?
> Currently it seems the only information you can access is the User name.
>
> I'm trying to create an auth system similar to github's ssh auth.  I want
> to allow anyone to ssh as a user like g...@github.com then do a database
> lookup on the key that was used to auth later when it tries to access
> something it might not have permission for. With the current API it seems
> like its only possible to enable or disable permissions based on the
> username, and not the key used.
>
> Thanks for any help
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed 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] Channels of multiple values

2016-12-18 Thread slav . isv
I know this is an old post, just thought to share possible work around. 
Idea is basically return a func that will return multiple values. I'm not 
sure how much performance overhead this will create and it's a little bit 
ugly, but works as intended.

func f(c chan func() (int, string)) {
c <- (func() (int, string) { return 0, "s" })
}

func main() {
c := make(chan func() (int, string))
go f(c)
y, z := (<-c)()
fmt.Println(y)
fmt.Println(z)
}

On Wednesday, October 3, 2012 at 6:04:15 AM UTC-4, Larry Clapp wrote:
>
> Well, true, but it doesn't really illustrate the manual destructuring you 
> have to do in real usage.  That's a nice trick, though, I'd forgotten about 
> that.
>
> -- Larry
>
>
> On Wednesday, October 3, 2012 12:32:35 AM UTC-4, Glenn Brown wrote:
>>
>> Larry, your example can be simplified as 
>> http://play.golang.org/p/COL68pDwOE : 
>>
>> package main 
>>
>> import "fmt" 
>>
>> type Tuple []interface{} 
>>
>> func main() { 
>> c := make(chan Tuple, 1) 
>> c <- Tuple{1, 2, "three"} 
>> fmt.Println(<-c...) 
>>
>> c <- Tuple{4, "five", 6, 7.0} 
>> fmt.Println(<-c...) 
>> } 
>>
>> --Glenn 
>>
>> On Oct 1, 2012, at 11:36 AM, Larry Clapp  wrote: 
>>
>> > Sorry to reply to myself, but I also thought of this: 
>> http://play.golang.org/p/n9iYer0glo 
>> > 
>> > type Tuple []interface{} 
>> > 
>> > func main() { 
>> > c := make(chan Tuple, 1) 
>> > c <- Tuple{1, 2, "three"} 
>> > a := <-c 
>> > i1 := a[0].(int) 
>> > i2 := a[1].(int) 
>> > s3 := a[2].(string) 
>> > fmt.Println(i1, i2, s3) 
>> > 
>> > c <- Tuple{4, "five", 6, 7.0} 
>> > a = <-c 
>> > i4 := a[0].(int) 
>> > s5 := a[1].(string) 
>> > i6 := a[2].(int) 
>> > f7 := a[3].(float64) 
>> > fmt.Println(i4, s5, i6, f7) 
>> > } 
>>
>>
>>
>>
>>

-- 
You received this message because you are subscribed 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: Assign a new value to an already initiated variable in template

2016-12-18 Thread ldeng via golang-nuts
encountered same problem, as it seems still an open issue, cannot change 
value of an existing variable inside of loop/if in template 
https://github.com/golang/go/issues/10608
...

  {{$deprecated := false}}  {{range $depre_audit := $depre_audits}} 
 {{if eq $audit_name $depre_audit}}  {{$deprecated := true}}   --> this 
line doesn't work beyond end  {{$audit_name}} - deprecated  {{end}}  
{{end}}  {{if not $deprecated}}  {{$audit_name}}  {{end}}





On Thursday, October 10, 2013 at 8:54:31 PM UTC+11, Accipiter Nisus wrote:
>
> Hi,
>
> What are the reasons why it is not possible to assign a new value to an 
> already initiated variable in the text/template package?
>
> Example where it is needed:
>
> Let's say I have a list of people (json):
>
> [
> {"name": "ANisus", "sex":"M"},
> {"name": "Sofia", "sex":"F"},
> {"name": "Anna", "sex":"F"}
> ]
>
> Using the template package, I want to have this output:
>
> Females:
>> Sofia
>> Anna
>
>
> But the header "Females:" should only show in case there are actually any 
> person with sex set to F.
> If I could reassign a value, I would do the following:
>
> {{$hasFemales := 0}}
> {{range .}}{{if eq .sex "F"}}{{$hasFemales = 1}}{{end}}{{end}}
> {{if $hasFemale}}Female:{{end}}
>
> Example: http://play.golang.org/p/T-Ekx7n9YQ
>
> /ANisus
>
>

-- 
You received this message because you are subscribed 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] Packaging Test Utilities in a Project

2016-12-18 Thread Marian Kopriva
What Dave suggested should work, in your example package1, package2, 
package3 and package4 should be able to import testhelpers with `import 
"project/internal/testhelpers"`

On Sunday, December 18, 2016 at 2:48:41 PM UTC+1, Henry wrote:
>
> Where do you put this internal package in relation to the rest of the 
> packages? Is it something like this:
>
> project/
>package1/
>package2/
>package3/package4/
>internal/testhelpers/
>
> I thought internal package would only be visible to its immediate parent? 
> I want it to be usable across the packages. 
>
> 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] package containing standard CA roots?

2016-12-18 Thread Konstantin Khomoutov
On Sat, 17 Dec 2016 10:41:33 -0800 (PST)
Rick  wrote:

> Alpine is a lightweight option with official Docker images. You can
> install the CERTS using the Alpine package manager:
> 
> # apk --no-cache add ca-certificates && update-ca-certificates

All-in-all, Alex appears to had created the package he wanted [1] :-)
It was announced over there on Reddit [2].

1. https://github.com/alexflint/stdroots
2. 
https://www.reddit.com/r/golang/comments/5j4go8/stdroots_standard_ca_roots_embedded_in_a_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] gomobile: support/v7/app vs app

2016-12-18 Thread andrey mirtchovski
The main activity in the reverse example uses a
support/v7/app.AppCompatActivity (as it should), however if I want to add
an app.Service service to the android app gomobile encounters duplicate
import errors:

   gomobile_bind/go_appmain.go:20: app redeclared as imported package name

If I attempt to resolve this by renaming v7/app gomobile still complains:

   gomobile_bind/go_appmain.go:31: undefined:
"Java/android/support/v7/app".Service

(I suspect it doesn't propagate the rename, but I have not yet looked at
the generated code).

Essentially I have two files (activity.go and service.go) which each import
something called "app", one from android.support.v7.app, the other from
android.app... I can successfully refactor the service into a separate
package but then I'm only allowed to use one package name in the manifest
and I don't see how I can reference the second package by name.

http://schemas.android.com/apk/res/android;
package="go.app" >
   

   




-- 
You received this message because you are subscribed 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: write barrier and C types

2016-12-18 Thread Tamás Gulácsi

2016. december 18., vasárnap 20:13:39 UTC+1 időpontban Florian Uekermann a 
következőt írta:
>
> Well, I am pretty sure I was wrong about something. Turning of the garbage 
> collector results in no error. Any smart ideas for debugging this?
>
> As I know, that means that indeed your analysis is correct: the Go garbage 
collector follows pointers, and 0x12 seems to be a non-pointer.
Somehow converting that to uintptr may help, but you're right: the best 
would be to change it on the C side.

-- 
You received this message because you are subscribed 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: gomobile: Intent.setClassName(String, String) called from Go?

2016-12-18 Thread andrey mirtchovski
Nevermind, found the missing piece with a bit more documentation-reading:

SetClassName_Ljava_lang_String_2Ljava_lang_String_2

-- 
You received this message because you are subscribed 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] Download all dependencies using go get ./...

2016-12-18 Thread Peng Wang
I have a project that using golang.org/x/crypto/ssh, when I try to build 
it, i usually do a go get ./... command(since it's easy to remember for 
every project and shorter than go get golang.org/x/crypto/ssh), but then it 
reports cannot find package "golang.org/x/net/context/ctxhttp".
It seems it's a dependency of the crypto/ssh package(I'm not sure), so I 
have to do another go get ./..., and now it reports cannot find package 
"golang.org/x/text/encoding"...
So what's the right way to do it conventionlly?

-- 
You received this message because you are subscribed 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: Intent.setClassName(String, String) called from Go?

2016-12-18 Thread andrey mirtchovski
I'm trying to create a long-running service from Go by calling
startService with an intent. I can't see how to create an intent with
a Class from Go, so I want to do the second best thing, use
setClassName*:

intent := Intent.New()
intent.SetClassName("package", "service")
context.StartService(intent)

unfortunately setClassName is overloaded and I can't figure out what
the JNI mangled name I should use is. I think I'm close with
SetClassName_Ljava_lang_String_Ljava_lang_String_2 but so far no
cigar.

--
https://developer.android.com/reference/android/content/Intent.html#setClassName(java.lang.String,
java.lang.String)

-- 
You received this message because you are subscribed 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] Packaging Test Utilities in a Project

2016-12-18 Thread Henry
The problem with putting my test utilities under  a single file, lets say 
util_test.go, is that the utilities are not usable across different packages 
within the same project. As far as I know, you cannot import test packages (eg. 
mypackage_test).

-- 
You received this message because you are subscribed 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: programming embedded systems with Go

2016-12-18 Thread Manlio Perillo
Il giorno domenica 18 dicembre 2016 23:14:24 UTC+1, Manlio Perillo ha 
scritto:
>
> I would like to start playing with some cheap boards with Linux or OpenWRT.
> With the recent support for mips32, what are the current available choices 
> that are able to run a Go program without problems?
>
> Currently the Go wiki has only a page about ARM support.
>
>
One additional question: what is the mips32 hardware used by the builder in 
the build farm?
What about adding hardware details on http://farmer.golang.org/builders ?


Thanks  Manlio

-- 
You received this message because you are subscribed 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] programming embedded systems with Go

2016-12-18 Thread Manlio Perillo
I would like to start playing with some cheap boards with Linux or OpenWRT.
With the recent support for mips32, what are the current available choices 
that are able to run a Go program without problems?

Currently the Go wiki has only a page about ARM support.


Thanks  Manlio

-- 
You received this message because you are subscribed 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] Packaging Test Utilities in a Project

2016-12-18 Thread Mark Mandel
Any reason not to have a `utils_test.go` file - and puts your utilities in
there? Seems like the simplest solution.

Then they only get included for your tests.

Using /internal for testing tools feels a bit strange to me IMHO.

Mark

On 18 December 2016 at 11:13, Matt Harden  wrote:

> An import of a path containing the element “internal” is disallowed if the
> importing code is outside the tree rooted at the parent of the “internal”
> directory.
>
> Note the use of the word "tree" in that sentence, as opposed to
> "directory".
>
> On Sun, Dec 18, 2016 at 5:48 AM Henry  wrote:
>
>> Where do you put this internal package in relation to the rest of the
>> packages? Is it something like this:
>>
>> project/
>>package1/
>>package2/
>>package3/package4/
>>internal/testhelpers/
>>
>> I thought internal package would only be visible to its immediate parent?
>> I want it to be usable across the packages.
>>
>> 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.
>



-- 
T: http://www.twitter.com/neurotic
W: www.compoundtheory.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] package containing standard CA roots?

2016-12-18 Thread Lars Seipel
On Thu, Dec 15, 2016 at 04:35:09PM +, Alex Flint wrote:
> Does anyone know of a golang package that embeds (go-bindata or similar) a
> reasonable standard set of CA roots?

No, but the common approach is to rely on the root CA set maintained by
Mozilla.

This should correspond to the latest Firefox release:
https://hg.mozilla.org/releases/mozilla-release/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt

You might want to check with your trusted distribution packager for some
scripts to convert this into a format that's nicer to work with.

See e.g. certdata2pem.py from Fedora or MAca-bundle.pl.in from
FreeBSD ports.

https://src.fedoraproject.org/cgit/rpms/ca-certificates.git/tree/
https://svnweb.freebsd.org/ports/head/security/ca_root_nss/files/

Or just use the ones from the binary packages and put them in the
appropriate places within the file system so that the standard library
will pick them up.

Of course, the usual things apply, like that you if you ship it
you're responsible for maintaining it, too. Regularly syncing with
Mozilla upstream should be enough in this case.

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


[go-nuts] Re: write barrier and C types

2016-12-18 Thread 'Florian Uekermann' via golang-nuts
Well, I am pretty sure I was wrong about something. Turning of the garbage 
collector results in no error. Any smart ideas for debugging this?

On Sunday, December 18, 2016 at 4:20:25 PM UTC+1, Florian Uekermann wrote:
>
> I may be misdiagnosing the problem, but I think go is doing a problematic 
> check of the value of C pointer types pointers.
>
> The following runtime error is reproducible, but does not always happen in 
> a program:
>
> runtime: writebarrierptr *0xc420326a90 = 0x12 
> fatal error: bad pointer in write barrier
>
> The stack trace indicates that the offending line is the last one in the 
> following snippet:
>
> var bi C.VkRenderPassBeginInfo
> bi.sType = C.VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
> bi.renderPass = renderpass
>
> I checked the address of the .renderPass field and it is indeed 0xc420326a90 
> and the value
> of renderpass is 18. As you may have recognized by now, I am using the vulkan 
> C bindings.
> The .renderPass field has type C.VkRenderPass. A quick look at vulkan.h 
> yields the following:
>
> #if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || 
> defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || 
> defined(__aarch64__) || defined(__powerpc64__)
> #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct 
> object##_T *object;
> #else
> #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t 
> object;
> #endif
> ...
>
> VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkRenderPass)
>
>
> So it seems to me that Vulkan uses a pointer type  on 64bit archs to 
> store a (potentially non-pointer) handle.
> Given that structs with these handles are very common, the workaround of 
> allocating the bi variable on the C heap
> is a lot of unnecessary work and a bit of a performance issue.
>
> I am not quite sure what a writebarrier is in this context, so I am not 
> sure if deactivating this check creates more issue (GC)?
>
> Can someone give some insight into what the long-term options are for go 
> with respect to 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] Packaging Test Utilities in a Project

2016-12-18 Thread Matt Harden
An import of a path containing the element “internal” is disallowed if the
importing code is outside the tree rooted at the parent of the “internal”
directory.

Note the use of the word "tree" in that sentence, as opposed to "directory".

On Sun, Dec 18, 2016 at 5:48 AM Henry  wrote:

> Where do you put this internal package in relation to the rest of the
> packages? Is it something like this:
>
> project/
>package1/
>package2/
>package3/package4/
>internal/testhelpers/
>
> I thought internal package would only be visible to its immediate parent?
> I want it to be usable across the packages.
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [go-nuts] Golang for ARM

2016-12-18 Thread Paulo Coutinho
But i set it, You can see on dockerfile.

ENV GO_VERSION=1.7.4
ENV INSTALLED_GOLANG=1.6
ENV GOROOT_BOOTSTRAP=/usr/lib/go-${INSTALLED_GOLANG}
ENV GOOS=android
ENV GOARCH=arm
ENV GOARM=7
ENV CGO_ENABLED=1





Em 18 de dez de 2016 7:25 AM, "Will Newton" 
escreveu:

> On Sun, Dec 18, 2016 at 4:09 AM, Paulo Coutinho 
> wrote:
> > Hi,
> >
> > Im making a free repository to show how to compile Golang for ARM v7
> > (Android).
> >
> > Link:
> > https://github.com/prsolucoes/golang-for-arm
> >
> > Error:
> > arm-linux-androideabi-gcc: error: unrecognized command line option '-m64'
>
> This suggests you're passing an x86_64 flag to an ARM compiler, for
> example, CC is set but GOARCH is not.
>

-- 
You received this message because you are subscribed 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] CFG for a Go program

2016-12-18 Thread 'Alan Donovan' via golang-nuts
On 17 December 2016 at 23:54,  wrote:

> For each instruction in any BasicBlock I want to know the type of
> instruction, the variables used in that instruction. [...]  Just one line
> of the program corresponds to multiple instructions. Is there some
> documentation as to how these instructions are constructed for a line of
> code so that I can decode these instructions for any general program’s SSA.
>

The SSA package defines a minimal instruction set sufficient to express the
semantics of any Go program. It simplifies the program in certain ways,
such as:
- replacing many local variable defs and uses by direct graph edges
- reducing structured control flow with unstructured jumps
- expanding out the effects of "embedding" on field and method selections
- simplifying variadic calls with explicit slice operations
- defining closures for function literals with free variables.
However, it does not "lower" the core data types of Go (slices, channels,
etc) to simpler ones, so the sequence of SSA instructions generated for any
source construct should be quite intuitive.

For examples of how to use the SSA form, take a look at the go/pointer
package that lives alongside go/ssa.  It processes all the instructions
within each function to build and then solve an interprocedural system of
constraints:

  https://github.com/golang/tools/blob/master/go/pointer/gen.go#L934

Alternatively, look at the core function of the interpreter used for
testing the SSA construction algorithm.  It visits each instruction in turn
and simulates its dynamic semantics:

  https://github.com/golang/tools/blob/master/go/ssa/interp/interp.go#L192



Also, I want to know the variables which are shared bw any goroutines or
> not.
>

To answer this question precisely you need an "escape analysis", such
J.D.Choi et al.'s "Escape Analysis for Java" which classifies each variable
into one of three kinds: local variables, heap variables local to a single
thread, and shared variables.

Building an escape analysis is a significant undertaking---similar to and
about as complex as the analysis done by the go/pointer package.  You can
answer this question simply but very conservatively by assuming that all
heap variables (Alloc{Heap:true}) are shared by multiple goroutines.



> All the instructions where one particular variable is being defined or
> used.
>

Each local ssa.Value (such as an add instruction, BinaryOp{Op: ADD}) has a
set of edges (Referrers) to each place it is used.
For all other values (e.g. globals) you need to do a pass over the whole
program to find all references.


I need these infos because my aim is to implement the CSSA based SAT
> encoding for a program as mentioned on page 7 of this paper (
> https://goo.gl/pdXuoe).
>

That paper describes a hybrid static/dynamic analysis, which means it needs
to relate facts about a particular concrete execution of a program with
facts about a static abstraction of the same program.  You will find it
easier to implement if you use as much common infrastructure as possible
for the two analysis, which means using the gc compiler's SSA
representation instead of the one in golang.org/x/tools/go/ssa.

I don't wish to discourage you, but if this is your aim, I must warn you
that basic usage of the go/ssa package is like walking from the parking lot
to the trailhead, and you still have mountains to climb.

-- 
You received this message because you are subscribed 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: write barrier and C types

2016-12-18 Thread 'Florian Uekermann' via golang-nuts
I forgot to ask another question.
If solving this is not practical in go, should I bring this up with the 
Vulkan people?
I don't really understand why they don't use uint64_t regardless of 
architecture.

-- 
You received this message because you are subscribed 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] write barrier and C types

2016-12-18 Thread 'Florian Uekermann' via golang-nuts
I may be misdiagnosing the problem, but I think go is doing a problematic 
check of the value of C pointer types pointers.

The following runtime error is reproducible, but does not always happen in 
a program:

runtime: writebarrierptr *0xc420326a90 = 0x12 
fatal error: bad pointer in write barrier

The stack trace indicates that the offending line is the last one in the 
following snippet:

var bi C.VkRenderPassBeginInfo
bi.sType = C.VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
bi.renderPass = renderpass

I checked the address of the .renderPass field and it is indeed 0xc420326a90 
and the value
of renderpass is 18. As you may have recognized by now, I am using the vulkan 
C bindings.
The .renderPass field has type C.VkRenderPass. A quick look at vulkan.h 
yields the following:

#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || 
defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) 
|| defined(__powerpc64__)
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct 
object##_T *object;
#else
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t 
object;
#endif
...

VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkRenderPass)


So it seems to me that Vulkan uses a pointer type  on 64bit archs to store 
a (potentially non-pointer) handle.
Given that structs with these handles are very common, the workaround of 
allocating the bi variable on the C heap
is a lot of unnecessary work and a bit of a performance issue.

I am not quite sure what a writebarrier is in this context, so I am not 
sure if deactivating this check creates more issue (GC)?

Can someone give some insight into what the long-term options are for go 
with respect to 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] Re: howto: compile template against well-known structure ?

2016-12-18 Thread mhhcbon
static escaping == great idea, but performance are strongly impacted.

As i worried about, the problem i m figuring now is that html package does 
not expose enough of its implementation.
for example most escape functions are private,
https://golang.org/src/html/template/escape.go#L48

But from what i try to do, it resumes to a func call, i don t have to re 
implement the context identifier, as its already done by the 
template.escape method (once the template is executed).

Anyway, i ll do some copy paste for instance, lets see, plenty of cases to 
manage before it can get useful.

-- 
You received this message because you are subscribed 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] Packaging Test Utilities in a Project

2016-12-18 Thread Henry
Where do you put this internal package in relation to the rest of the packages? 
Is it something like this:

project/
   package1/
   package2/
   package3/package4/
   internal/testhelpers/

I thought internal package would only be visible to its immediate parent? I 
want it to be usable across the packages. 

Thanks.

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


[go-nuts] Re: howto: compile template against well-known structure ?

2016-12-18 Thread Egon
On Sunday, 18 December 2016 11:16:23 UTC+2, mhh...@gmail.com wrote:
>
> Thanks a lot! I ve been playing a bit with it, for some simple cases it 
> worked great.
>
> Though, i looked into the html/template, am i correct to understand that 
> the html security layer consist of adding new cmds (of escaping) 
> on the relevant nodes ?
> https://golang.org/src/html/template/escape.go#L221
>
> Its all private, so i m bit concerned about how i m going to manage that.
>

Yeah, there are a lot of different rules for escaping -- you can take a 
look at 
https://rawgit.com/mikesamuel/sanitized-jquery-templates/trunk/safetemplate.html
 
for more information on sanitization.

But essentially, yes, to be fully compliant, you would need to reimplement 
the html/template package.

+ Egon

-- 
You received this message because you are subscribed 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 server question

2016-12-18 Thread andrewchamberss
I am trying to get access to get public key that was used to authenticate 
an ssh connection (https://godoc.org/golang.org/x/crypto/ssh#ConnMetadata) 
inside the PublicKeyCallback while handling a channel request. I want to be 
able to accept the connection with any public key, but then control some 
application level permissions based on this key later. Is this possible?  
Currently it seems the only information you can access is the User name. 

I'm trying to create an auth system similar to github's ssh auth.  I want 
to allow anyone to ssh as a user like g...@github.com then do a database 
lookup on the key that was used to auth later when it tries to access 
something it might not have permission for. With the current API it seems 
like its only possible to enable or disable permissions based on the 
username, and not the key used.

Thanks for any help

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


Re: [go-nuts] Packaging Test Utilities in a Project

2016-12-18 Thread Dave Cheney
Like Nigel suggested

project/
  internal/
 testhelper



On Sunday, 18 December 2016 21:45:25 UTC+11, Henry wrote:
>
> No. I meant something like this:
>
> project/
> -- package1
> -- package2
> -- package3
>
> Now there is a reusable test utility that is used by the tests in 
> package1, package2, and package3. So the question is where do I put the 
> test utility without exposing them as a part of the project's API? I don't 
> want the test utility to get compiled into the final binary as it is 
> supposed to be part of the test.
>
> On Sunday, December 18, 2016 at 5:30:20 PM UTC+7, Nigel Tao wrote:
>
>> On Sun, Dec 18, 2016 at 1:51 PM, Henry  wrote: 
>> > I have reusable test utilities in a project. They are used by various 
>> > packages in the project for testing purposes, and at the same time I 
>> don't 
>> > want to expose these utilities as public APIs. Since it is impossible 
>> to 
>> > import another test package in Go, I wonder what would be the best way 
>> to 
>> > package these utilities. 
>>
>> It sounds like you want an internal package. See 
>> https://golang.org/s/go14internal 
>>
>

-- 
You received this message because you are subscribed 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] Packaging Test Utilities in a Project

2016-12-18 Thread Henry
No. I meant something like this:

project/
-- package1
-- package2
-- package3

Now there is a reusable test utility that is used by the tests in package1, 
package2, and package3. So the question is where do I put the test utility 
without exposing them as a part of the project's API? I don't want the test 
utility to get compiled into the final binary as it is supposed to be part 
of the test.

On Sunday, December 18, 2016 at 5:30:20 PM UTC+7, Nigel Tao wrote:

> On Sun, Dec 18, 2016 at 1:51 PM, Henry  > wrote: 
> > I have reusable test utilities in a project. They are used by various 
> > packages in the project for testing purposes, and at the same time I 
> don't 
> > want to expose these utilities as public APIs. Since it is impossible to 
> > import another test package in Go, I wonder what would be the best way 
> to 
> > package these utilities. 
>
> It sounds like you want an internal package. See 
> https://golang.org/s/go14internal 
>

-- 
You received this message because you are subscribed 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] Packaging Test Utilities in a Project

2016-12-18 Thread Nigel Tao
On Sun, Dec 18, 2016 at 1:51 PM, Henry  wrote:
> I have reusable test utilities in a project. They are used by various
> packages in the project for testing purposes, and at the same time I don't
> want to expose these utilities as public APIs. Since it is impossible to
> import another test package in Go, I wonder what would be the best way to
> package these utilities.

It sounds like you want an internal package. See
https://golang.org/s/go14internal

-- 
You received this message because you are subscribed 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.