Skip to content

Commit

Permalink
Make cosgo install-able.
Browse files Browse the repository at this point in the history
Since cosgo can be installed system-wide, look for templates in /usr/local/share

	./templates/
	/usr/local/share/cosgo/templates/
  • Loading branch information
aerth committed Apr 30, 2016
1 parent 8188686 commit a95f598
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
NAME=cosgo
VERSION=0.6
RELEASE:=v${VERSION}.$(shell git rev-parse --verify --short HEAD)
PREFIX=/usr/local/bin
PREFIX=/usr/local
all:
set -e
go fmt
go vet
go build -v -o ${NAME}-${RELEASE} && echo Built ${NAME}-${RELEASE}

install:
mv ${NAME}-${RELEASE} ${PREFIX}/${NAME}
mv ${NAME}-${RELEASE} ${PREFIX}/bin/${NAME}
set noclobber on
mkdir -p ${PREFIX}/share/${NAME}/
cp -R templates ${PREFIX}/share/${NAME}/templates
cp -R static ${PREFIX}/share/${NAME}/static

deps:
go get -v -d .
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ firefox http:https://127.0.0.1:8080 # Check it out.
```

or


```
git clone https://github.com/aerth/cosgo.git
cd cosgo
make deps
make
sudo make install # installs to /usr/local/bin/cosgo
```

-------

## Theme
Expand Down
17 changes: 13 additions & 4 deletions boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,24 @@ func quickSelfTest() (err error) {
}
}

cosgo.Templates = "./templates"
// Main template. Replace with your own, but keep the {{.Tags}} in it.
_, err = template.New("Index").ParseFiles("./templates/index.html")
_, err = template.New("Index").ParseFiles(cosgo.Templates + "index.html")
if err != nil {
log.Println("Fatal: Template Error:", err)
log.Fatal("Fatal: Template Error\n\n\t\tHint: Copy ./templates and ./static from $GOPATH/src/github.com/aerth/cosgo/ to the location you are running cosgo from.")
_, err2 := template.New("Index").ParseFiles("/usr/local/share/cosgo/templates/index.html")
if err2 != nil {
log.Println("Fatal: Template Error:", err2)
log.Fatal("Fatal: Template Error\n\n\t\tHint: Copy ./templates and ./static from $GOPATH/src/github.com/aerth/cosgo/ to the location you are running cosgo from.")
} else {
cosgo.Templates = "/usr/local/share/cosgo/templates/"
}

} else {
cosgo.Templates = "./templates/"
}

// Make sure Error pages template is present
_, err = template.New("Error").ParseFiles("./templates/error.html")
_, err = template.New("Error").ParseFiles(cosgo.Templates + "error.html")
if err != nil {
log.Println("Fatal: Template Error:", err)
log.Fatal("Fatal: Template Error\nHint: Copy ./templates and ./static from $GOPATH/src/github.com/aerth/cosgo/ to the location you are running cosgo from.")
Expand Down
6 changes: 3 additions & 3 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func homeHandler(w http.ResponseWriter, r *http.Request) {
nowtime := thyme.Format("Mon Jan 2 15:04:05 2006")
uptime := time.Since(cosgo.Boottime).String()

t, templateerr := template.New("Index").ParseFiles("./templates/index.html")
t, templateerr := template.New("Index").ParseFiles(cosgo.Templates + "index.html")
if !*form {
t, templateerr = template.New("Index").ParseFiles("./templates/index.html")
t, templateerr = template.New("Index").ParseFiles(cosgo.Templates + "index.html")
}
if templateerr != nil {
// Do Something
Expand Down Expand Up @@ -119,7 +119,7 @@ func customErrorHandler(w http.ResponseWriter, r *http.Request) {
domain := getDomain(r)
lol := p.Sanitize(r.URL.Path[1:])
log.Printf("404 on %s/%s", lol, domain)
t, err := template.New("Error").ParseFiles("./templates/error.html")
t, err := template.New("Error").ParseFiles(cosgo.Templates + "error.html")
if err == nil {
data := map[string]interface{}{
"err": "404",
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ var (

// Cosgo - This changes every [cosgoRefresh] minutes
type Cosgo struct {
PostKey string
Boottime time.Time
PostKey string
Boottime time.Time
Templates string // Directory where templates are located. Defaults to ./templates and falls back to /usr/local/share/cosgo/templates
}

var cosgo = new(Cosgo)
Expand Down

0 comments on commit a95f598

Please sign in to comment.