Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

automatically determine webdir based on import path #6

Merged
merged 1 commit into from

2 participants

@ebfe

No description provided.

@paulsamways paulsamways merged commit 0a05e28 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 22, 2012
  1. @ebfe
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 1 deletion.
  1. +14 −1 http.go
View
15 http.go
@@ -1,6 +1,8 @@
package main
import (
+ "path/filepath"
+ "go/build"
"encoding/json"
"fmt"
"log"
@@ -10,8 +12,19 @@ import (
"time"
)
+const importpath = "github.com/PaulSamways/gopkgsearch"
+
+func webdir() string {
+ pkg, err := build.Import(importpath, "", build.FindOnly)
+ if err != nil {
+ log.Printf("Couldn't determine web directory: %s", err)
+ return "./web"
+ }
+ return filepath.Join(pkg.Dir, "web")
+}
+
func listen() {
- http.Handle("/", http.FileServer(http.Dir("./web")))
+ http.Handle("/", http.FileServer(http.Dir(webdir())))
http.HandleFunc("/query", query)
err := http.ListenAndServe(*addr, nil)
Something went wrong with that request. Please try again.