<p dir="auto">by <strong>angrygoats</strong>:</p>
<pre class="notranslate">What steps will reproduce the problem?

Compile this program:
package sum

func sum(a []int) int
{   // returns an int
    s := 0;
    for i := 0; i &lt; len(a); i++ {
        s += a[i]
    }
    return s
}


(note brace at start of function definition is on new line)

What is the expected output? What do you see instead?

I'm not 100% sure, but I think this should compile. Instead I get:
sum.go:4: syntax error near int

What is your $GOOS?  $GOARCH?
linux 386

Which revision are you using?  (hg identify)
2701d4abb3f2

Please provide any additional information below.

I've run a bisection (with 'hg bisect') and the revision that seems to have 
caused the change in behaviour was:

The first bad revision is:
changeset:   4395:26b9258d76e4
user:        Russ Cox &lt;rsc@golang.org&gt;
date:        Fri Dec 11 15:59:41 2009 -0800
summary:     gc: semicolons</pre>
<h1 dir="auto">Solution (Note to Les Googlers)</h1>
<p dir="auto">My question was, as I misinterpreted the documentation.</p>
<ul dir="auto">
<li><code class="notranslate">GetCertificate == SNICallback</code></li>
<li>You cannot cast <code class="notranslate">net.Conn</code> to <code class="notranslate">http.Conn</code>, you can only cast <code class="notranslate">net.Listener</code> to <code class="notranslate">http.Listener</code>
<ul dir="auto">
<li>i.e. <code class="notranslate">server := &amp;http.Serve{}; server.Server(tlsListener)</code></li>
</ul>
</li>
</ul>
<p dir="auto">See examples at</p>
<ul dir="auto">
<li><a href="https://github.com/coolaj86/golang-https-example/tree/https-server">https://github.com/coolaj86/golang-https-example/tree/https-server</a></li>
<li><a href="https://github.com/coolaj86/golang-https-example">https://github.com/coolaj86/golang-https-example</a></li>
</ul>
<p dir="auto">The crux of the issue In 68 lines:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="package main

import (
    &quot;crypto/tls&quot;
    &quot;fmt&quot;
    &quot;net&quot;
    &quot;net/http&quot;
    &quot;os&quot;
    &quot;path/filepath&quot;
    &quot;strconv&quot;
    &quot;strings&quot;
)

type myHandler struct{}

func (m *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    fmt.Println(r.Host)
    fmt.Println(r.Method)
    fmt.Println(r.RequestURI)
    fmt.Println(r.URL) // also has many keys, such as Query
    for k, v := range r.Header {
        fmt.Println(k, v)
    }
    fmt.Println(r.Body)

    // End the request
    fmt.Fprintf(w, &quot;Hi there, %s %q? Wow!\n\nWith Love,\n\t%s&quot;, r.Method, r.URL.Path[1:], r.Host)
}

func main() {
    port := uint(8443)
    certsPath := &quot;/etc/letsencrypt/live&quot;
    defaultHost := &quot;localhost.daplie.com&quot;

    fmt.Printf(&quot;Loading Certificates %s/%s/{privkey.pem,fullchain.pem}\n&quot;, certsPath, defaultHost)

    privkeyPath := filepath.Join(certsPath, defaultHost, &quot;privkey.pem&quot;)
    certPath := filepath.Join(certsPath, defaultHost, &quot;fullchain.pem&quot;)
    cert, err := tls.LoadX509KeyPair(certPath, privkeyPath)
    if err != nil {
        fmt.Fprintf(os.Stderr, &quot;Couldn't load default certificates: %s\n&quot;, err)
        os.Exit(1)
    }

    addr := &quot;:&quot; + strconv.Itoa(int(port))

    conn, err := net.Listen(&quot;tcp&quot;, addr)
    if nil != err {
        fmt.Fprintf(os.Stderr, &quot;Couldn't bind to TCP socket %q: %s\n&quot;, addr, err)
        os.Exit(1)
    }

    tlsConfig := new(tls.Config)
    tlsConfig.Certificates = []tls.Certificate{cert}
    tlsConfig.GetCertificate = func(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) {
        return &amp;cert, nil
    }
    tlsListener := tls.NewListener(conn, tlsConfig)

    server := &amp;http.Server{
        Addr:    addr,
        Handler: &amp;myHandler{},
    }

    host := strings.ToLower(defaultHost)
    fmt.Printf(&quot;Listening on https://%s:%d\n&quot;, host, port)
    server.Serve(tlsListener)
}"><pre class="notranslate"><code class="notranslate">package main

import (
    "crypto/tls"
    "fmt"
    "net"
    "net/http"
    "os"
    "path/filepath"
    "strconv"
    "strings"
)

type myHandler struct{}

func (m *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    fmt.Println(r.Host)
    fmt.Println(r.Method)
    fmt.Println(r.RequestURI)
    fmt.Println(r.URL) // also has many keys, such as Query
    for k, v := range r.Header {
        fmt.Println(k, v)
    }
    fmt.Println(r.Body)

    // End the request
    fmt.Fprintf(w, "Hi there, %s %q? Wow!\n\nWith Love,\n\t%s", r.Method, r.URL.Path[1:], r.Host)
}

func main() {
    port := uint(8443)
    certsPath := "/etc/letsencrypt/live"
    defaultHost := "localhost.daplie.com"

    fmt.Printf("Loading Certificates %s/%s/{privkey.pem,fullchain.pem}\n", certsPath, defaultHost)

    privkeyPath := filepath.Join(certsPath, defaultHost, "privkey.pem")
    certPath := filepath.Join(certsPath, defaultHost, "fullchain.pem")
    cert, err := tls.LoadX509KeyPair(certPath, privkeyPath)
    if err != nil {
        fmt.Fprintf(os.Stderr, "Couldn't load default certificates: %s\n", err)
        os.Exit(1)
    }

    addr := ":" + strconv.Itoa(int(port))

    conn, err := net.Listen("tcp", addr)
    if nil != err {
        fmt.Fprintf(os.Stderr, "Couldn't bind to TCP socket %q: %s\n", addr, err)
        os.Exit(1)
    }

    tlsConfig := new(tls.Config)
    tlsConfig.Certificates = []tls.Certificate{cert}
    tlsConfig.GetCertificate = func(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) {
        return &amp;cert, nil
    }
    tlsListener := tls.NewListener(conn, tlsConfig)

    server := &amp;http.Server{
        Addr:    addr,
        Handler: &amp;myHandler{},
    }

    host := strings.ToLower(defaultHost)
    fmt.Printf("Listening on https://%s:%d\n", host, port)
    server.Serve(tlsListener)
}
</code></pre></div>
<h1 dir="auto">Original Question</h1>
<p dir="auto"><a href="https://LetsEncrypt.org's" rel="nofollow">https://LetsEncrypt.org's</a> release is just around the corner, but it's currently not possible to dynamically retrieve and renew certificates in go with an active http server.</p>
<p dir="auto">To do so requires fixing a tiny regression introduced sometime between the move from httputils and now. See <a href="https://golang.org/pkg/net/http/httputil/#ServerConn" rel="nofollow">https://golang.org/pkg/net/http/httputil/#ServerConn</a>.</p>
<p dir="auto">We need to re-expose http.NewConn and http.conn.Serve.<br>
See the diff: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/coolaj86/go/commit/1a30898568d34c8cbfee25edac386c1bdc05ea25/hovercard" href="https://github.com/coolaj86/go/commit/1a30898568d34c8cbfee25edac386c1bdc05ea25">coolaj86@<tt>1a30898</tt></a></p>
<p dir="auto">I've got a working demo of dynamically loading certificates with this change here:<br>
<a href="https://gist.github.com/coolaj86/16ed8fd810e19dec71be">https://gist.github.com/coolaj86/16ed8fd810e19dec71be</a></p>
<p dir="auto">I've already signed the CLA and with a little coaching I'm sure I could turn my example into an appropriate test case, but I'm way out of my league with the 37-page explanation of how to make a pull request...</p>
<p dir="auto">See also <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="94218092" data-permission-text="Title is private" data-url="https://github.com/golang/go/issues/11649" data-hovercard-type="pull_request" data-hovercard-url="/golang/go/pull/11649/hovercard" href="https://github.com/golang/go/pull/11649">#11649</a></p>