Skip to content

Commit

Permalink
Merge pull request #27 from barakmich/master
Browse files Browse the repository at this point in the history
Fix the build story
  • Loading branch information
barakmich committed Jun 28, 2014
2 parents a63bce6 + 7a24e5e commit be116d7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .goxc.json
Original file line number Diff line number Diff line change
@@ -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"
}
31 changes: 4 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
47 changes: 43 additions & 4 deletions http/cayley_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
package http

import (
"flag"
"fmt"
"html/template"
"net/http"
"os"
"time"

"github.com/barakmich/glog"
Expand All @@ -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()
Expand Down Expand Up @@ -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)

Expand All @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion http/cayley_http_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
)

type DocRequestHandler struct {
assets string
}

func MarkdownWithCSS(input []byte, title string) []byte {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit be116d7

Please sign in to comment.