In go, Manually Invoke an http.FileServer and/or What is an http Handler
<p>I'm an experienced programmer, but new to go.  Apologies in advance if this is an obvious question or well tread path.  I'm still getting my bearings in the language and its semantics. </p>

<p>I'm trying to create a web server in go that</p>

<ol>
<li>Examines the HTTP request</li>
<li>Based on the results of the request, serves a <strong>specific</strong> static folder</li>
</ol>

<p>i.e., something where the simplified pseudo code looks like</p>

<pre><code>import (
    "io"
    "net/http"
    "fmt"
    "strings"
    "encoding/base64"
)

func examineRequest(request *http.Request) {
    //looks at request header
    if(request headers have one thing){
        return "foo"
    }
    return "bar"
}

func processRequest(responseWriter http.ResponseWriter, request *http.Request) {
    folderToServe = examineRequest(request);
    if folderToServe == "bar" {
        //serve static files from the ./static/bar folder

        //go freaks out if I try these
        //http.Handle("/", http.FileServer(http.Dir("./static/bar")))      
        //http.FileServer(http.Dir("./static/bar")()

    }
    else if folderToServer == "foo" {
        //serve static files from the ./static/foo folder

        //go freaks out if I try these
        //http.Handle("/", http.FileServer(http.Dir("./static/foo")))      
        //http.FileServer(http.Dir("./static/foo")()
    }
}

func main(){
    http.HandleFunc("/", processRequest)  
    //http.Handle("/", http.FileServer(http.Dir("./static")))      
}
</code></pre>

<p>Experienced go programmers may have already spotted the problem.  I'm performing my examination in processRequest, and because of that, its too late to to call Handle -- however, you can't register more than one handle for the same path in go, and nested handle calls freak go out.</p>

<p>I though the handler might be similar to an anonymous function in other languages and tried call it -- but go did like that either.</p>

<p>So -- is there a way to manually invoke the handler returned from the call to <code>http.FileServer(http.Dir("./static"))</code>?  </p>

<p>Is that even the right question to be asking here?</p>

<p>What exactly is a handler in the context of the http module?</p>