From b39e15dde5ec7b96c15da9faf4ab5892501c1aae Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 23 Mar 2013 11:28:53 +0100 Subject: Imported Upstream version 1.1~hg20130323 --- doc/go_faq.html | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) (limited to 'doc/go_faq.html') diff --git a/doc/go_faq.html b/doc/go_faq.html index 5c68aa7e5..3e742d9f7 100644 --- a/doc/go_faq.html +++ b/doc/go_faq.html @@ -949,6 +949,38 @@ combined with the Go project's mostly linear, non-branching use of version control, a switch to git doesn't seem worthwhile.

+

+Why does "go get" use HTTPS when cloning a repository?

+ +

+Companies often permit outgoing traffic only on the standard TCP ports 80 (HTTP) +and 443 (HTTPS), blocking outgoing traffic on other ports, including TCP port 9418 +(git) and TCP port 22 (SSH). +When using HTTPS instead of HTTP, git enforces certificate validation by +default, providing protection against man-in-the-middle, eavesdropping and tampering attacks. +The go get command therefore uses HTTPS for safety. +

+ +

+If you use git and prefer to push changes through SSH using your existing key +it's easy to work around this. For GitHub, try one of these solutions: +

+ +

Pointers and Allocation

@@ -974,6 +1006,57 @@ struct. If the interface value holds a pointer, copying the interface value makes a copy of the pointer, but again not the data it points to.

+

+When should I use a pointer to an interface?

+ +

+Almost never. Pointers to interface values arise only in rare, tricky situations involving +disguising an interface value's type for delayed evaluation. +

+ +

+It is however a common mistake to pass a pointer to an interface value +to a function expecting an interface. The compiler will complain about this +error but the situation can still be confusing, because sometimes a +pointer +is necessary to satisfy an interface. +The insight is that although a pointer to a concrete type can satisfy +an interface, with one exception a pointer to an interface can never satisfy a interface. +

+ +

+Consider the variable declaration, +

+ +
+var w io.Writer
+
+ +

+The printing function fmt.Fprintf takes as its first argument +a value that satisfies io.Writer—something that implements +the canonical Write method. Thus we can write +

+ +
+fmt.Fprintf(w, "hello, world\n")
+
+ +

+If however we pass the address of w, the program will not compile. +

+ +
+fmt.Fprintf(&w, "hello, world\n") // Compile-time error.
+
+ +

+The one exception is that any value, even a pointer to an interface, can be assigned to +a variable of empty interface type (interface{}). +Even so, it's almost certainly a mistake if the value is a pointer to an interface; +the result can be confusing. +

+

Should I define methods on values or pointers?

@@ -1407,7 +1490,7 @@ test cases. The standard Go library is full of illustrative examples, such as in What compiler technology is used to build the compilers?

-Gccgo has a C++ front-end with a recursive descent parser coupled to the +Gccgo has a front end written in C++, with a recursive descent parser coupled to the standard GCC back end. Gc is written in C using yacc/bison for the parser. Although it's a new program, it fits in the Plan 9 C compiler suite -- cgit v1.2.3