Skip to content

Instantly share code, notes, and snippets.

@baruchlubinsky
Created March 18, 2015 10:06
Show Gist options
  • Save baruchlubinsky/6af8b79f5961c50e73e2 to your computer and use it in GitHub Desktop.
Save baruchlubinsky/6af8b79f5961c50e73e2 to your computer and use it in GitHub Desktop.
A webserver to redirect `go get` requests to a kilnhg (or any other) server.
// A server for responding to go get requests in order to redirect to an unsupported repo host.
package main
import (
"html/template"
"net/http"
"os"
"strings"
)
var responseTemplate *template.Template
// The URL where this server is located
var host string
// The URL to use for git clone
var remote string
var templateString = `<html>
<head>
<meta name='go-import' content='{{.Host}}/{{.Repo}} git {{.Remote}}/{{.Repo}}'>
</head>
<body>
Redirecting to {{.Remote}}/{{.Repo}}
</body>
</html>`
type templateData struct{
Host string
Remote string
Repo string
}
func handler(w http.ResponseWriter, r *http.Request) {
path := strings.Split(r.URL.Path[1:], "/")
data := templateData{
host,
remote,
path[0]
}
responseTemplate.Execute(w, data)
}
func main() {
port := ":9000"
responseTemplate = template.New("meta")
responseTemplate.Parse(templateString)
http.HandleFunc("/", handler)
http.ListenAndServe(port, nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment