Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
Added Google-App-Engine support to sample-seed-site
Browse files Browse the repository at this point in the history
  • Loading branch information
metaleap committed Jun 4, 2013
1 parent 6836aaa commit 5cb58e0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
8 changes: 8 additions & 0 deletions go-leansite-example/appengine/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
application: helloworld
version: 1
runtime: go
api_version: go1

handlers:
- url: /.*
script: _go_app
18 changes: 18 additions & 0 deletions go-leansite-example/appengine/appengine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package appengine

import (
"net/http"
"os"
"path/filepath"

leansite "github.com/metaleap/go-leansite"
)

func init() {
cwd, err := os.Getwd()
if err != nil {
panic(err)
}
leansite.Init(filepath.Dir(cwd))
http.Handle("/", leansite.Router)
}
3 changes: 2 additions & 1 deletion go-leansite-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
dirPath := *flag.String("dir", ugo.GopathSrcGithub("metaleap", "go-leansite", "go-leansite-example"), "Root directory path containing the static, contents, templates etc. folders.")
log.Fatal(leansite.ListenAndServe(dirPath))
leansite.Init(dirPath)
log.Fatal(leansite.ListenAndServe(":8008"))
}
6 changes: 3 additions & 3 deletions go-leansite-example/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="#">go:LeanSite</a>
<a class="brand" href="/">go:LeanSite</a>
<div class="nav-collapse collapse">
<ul class="nav">
{{$pc := .}}
{{range $navItem := .TopNav}}
<li class="{{$navItem.CssClass}} {{if ($navItem.IsActive $pc)}}active{{end}}" title="{{$navItem.Desc}}">
<li class="{{ $navItem.CssClass }} {{ if $navItem.IsActive $pc }}active{{ end }}" title="{{$navItem.Desc}}">
<a href="/{{$navItem.Href}}">{{$navItem.Caption}}</a>
</li>
{{end}}
<li class="pull-right"><a href="mailto:philipp.schumann@gmail.com">Contact</a></li>
<li class="pull-right"><a href="javascript:alert('Your mailto: link here...');">Contact</a></li>
</ul>
</div>
</div>
Expand Down
18 changes: 11 additions & 7 deletions leansite.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
var (
DirPath string
DirWatch *uio.Watcher
Router *mux.Router
SiteData struct {
TopNav NavItems
Blogs map[string]BlogNav
Expand All @@ -31,14 +32,12 @@ func dir(names ...string) string {
return filepath.Join(append([]string{DirPath}, names...)...)
}

func ListenAndServe(dirPath string) (err error) {
func Init(dirPath string) (err error) {
SiteData.Blogs = map[string]BlogNav{}
SiteData.pageTemplates = map[string]*template.Template{}
DirPath = dirPath
if DirWatch, err = uio.NewWatcher(); err != nil {
return
} else {
defer DirWatch.Close()
}

// Load and watch templates
Expand All @@ -60,11 +59,16 @@ func ListenAndServe(dirPath string) (err error) {

// Listen and serve
fileServer = http.FileServer(http.Dir(dir("static")))
r := mux.NewRouter()
r.PathPrefix("/").HandlerFunc(serveTemplatedContent)
Router = mux.NewRouter()
Router.PathPrefix("/").HandlerFunc(serveTemplatedContent)
return
}

func ListenAndServe(addr string) (err error) {
defer DirWatch.Close()
s := &http.Server{
Addr: ":8080",
Handler: r,
Addr: addr,
Handler: Router,
// http://stackoverflow.com/questions/10971800/golang-http-server-leaving-open-goroutines
ReadTimeout: 2 * time.Minute,
}
Expand Down

0 comments on commit 5cb58e0

Please sign in to comment.