Merge pull request #27 from barakmich/master

Fix the build story
This commit is contained in:
Barak Michener 2014-06-27 19:38:13 -07:00
commit be116d7ba8
4 changed files with 55 additions and 32 deletions

6
.goxc.json Normal file
View file

@ -0,0 +1,6 @@
{
"Arch": "amd64 386",
"Os": "linux darwin windows",
"ResourcesInclude": "README.md,static,templates,LICENSE,AUTHORS,CONTRIBUTORS,docs,cayley.cfg.example,30kmoviedata.nt.gz,testdata.nt",
"ConfigVersion": "0.9"
}

View file

@ -28,36 +28,13 @@ Rough performance testing shows that, on consumer hardware and an average disk,
\* Note that while it's not exactly Gremlin, it certainly takes inspiration from that API. For this flavor, [see the documentation](docs/GremlinAPI.md).
## Building
Make sure you have the right packages installed. Mostly, this is just Go as a dependency, and different ways of pulling packages.
## Getting Started
### Linux
**Ubuntu / Debian**
Grab the latest [release binary](http://github.com/google/cayley/releases) and extract it wherever you like.
`sudo apt-get install golang git bzr mercurial make`
If you prefer to build from source, see the documentation on the wiki at [How to start hacking on Cayley](https://github.com/google/cayley/wiki/How-to-start-hacking-on-Cayley)
**RHEL / Fedora**
`sudo yum install golang git bzr mercurial make gcc`
**OS X**
[Homebrew](http://brew.sh) is the preferred method.
`brew install bazaar mercurial git go`
**Clone and build**
Now you can clone the repository and build the project.
```bash
go get github.com/google/cayley/cmd/cayley
```
And the `cayley` binary will be built and ready.
Give it a quick test with:
`cd` to the directory and give it a quick test with:
```
./cayley repl --dbpath=testdata.nt
```

View file

@ -15,9 +15,11 @@
package http
import (
"flag"
"fmt"
"html/template"
"net/http"
"os"
"time"
"github.com/barakmich/glog"
@ -29,6 +31,39 @@ import (
type ResponseHandler func(http.ResponseWriter, *http.Request, httprouter.Params) int
var assetsPath = flag.String("assets", "", "Explicit path to the HTTP assets.")
var assetsDirs = []string{"templates", "static", "docs"}
func hasAssets(path string) bool {
for _, dir := range assetsDirs {
if _, err := os.Stat(fmt.Sprint(path, "/", dir)); os.IsNotExist(err) {
return false
}
}
return true
}
func findAssetsPath() string {
if *assetsPath != "" {
if hasAssets(*assetsPath) {
return *assetsPath
} else {
glog.Fatalln("Cannot find assets at", *assetsPath, ".")
}
}
if hasAssets(".") {
return "."
}
gopathPath := os.ExpandEnv("$GOPATH/src/github.com/google/cayley")
if hasAssets(gopathPath) {
return gopathPath
}
glog.Fatalln("Cannot find assets in any of the default search paths. Please run in the same directory, in a Go workspace, or set --assets .")
return ""
}
func LogRequest(handler ResponseHandler) httprouter.Handle {
return func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
start := time.Now()
@ -86,10 +121,14 @@ func (api *Api) ApiV1(r *httprouter.Router) {
func SetupRoutes(ts graph.TripleStore, cfg *config.CayleyConfig) {
r := httprouter.New()
var templates = template.Must(template.ParseGlob("templates/*.tmpl"))
templates.ParseGlob("templates/*.html")
assets := findAssetsPath()
if glog.V(2) {
glog.V(2).Infoln("Found assets at", assets)
}
var templates = template.Must(template.ParseGlob(fmt.Sprint(assets, "/templates/*.tmpl")))
templates.ParseGlob(fmt.Sprint(assets, "/templates/*.html"))
root := &TemplateRequestHandler{templates: templates}
docs := &DocRequestHandler{}
docs := &DocRequestHandler{assets: assets}
api := &Api{config: cfg, ts: ts}
api.ApiV1(r)
@ -98,7 +137,7 @@ func SetupRoutes(ts graph.TripleStore, cfg *config.CayleyConfig) {
r.GET("/docs/:docpage", docs.ServeHTTP)
r.GET("/ui/:ui_type", root.ServeHTTP)
r.GET("/", root.ServeHTTP)
http.Handle("/static/", http.StripPrefix("/static", http.FileServer(http.Dir("static/"))))
http.Handle("/static/", http.StripPrefix("/static", http.FileServer(http.Dir(fmt.Sprint(assets, "/static/")))))
http.Handle("/", r)
}

View file

@ -25,6 +25,7 @@ import (
)
type DocRequestHandler struct {
assets string
}
func MarkdownWithCSS(input []byte, title string) []byte {
@ -56,7 +57,7 @@ func (h *DocRequestHandler) ServeHTTP(w http.ResponseWriter, r *http.Request, pa
if docpage == "" {
docpage = "Index"
}
file, err := os.Open(fmt.Sprintf("docs/%s.md", docpage))
file, err := os.Open(fmt.Sprintf("%s/docs/%s.md", h.assets, docpage))
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return