Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bits for CF #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions day02-net-http-html/.godir
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wiki
5 changes: 5 additions & 0 deletions day02-net-http-html/Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions day02-net-http-html/Godeps/Readme

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions day02-net-http-html/Godeps/_workspace/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions day02-net-http-html/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: wiki
5 changes: 5 additions & 0 deletions day02-net-http-html/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
applications:
- name: gunjan-wiki
disk: 256M
memory: 128M
14 changes: 12 additions & 2 deletions day02-net-http-html/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import (
"io/ioutil"
"net/http"
"regexp"
"os"
"log"
)

const lenPath = len("/view/")
const (
DEFAULT_PORT = "9000"
)
var templates = template.Must(template.ParseFiles("edit.html", "view.html"))
var titleValidator = regexp.MustCompile("^[a-zA-Z0-9]+$")

Expand Down Expand Up @@ -70,15 +75,20 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
}

func main() {
var port string
if port = os.Getenv("PORT"); len(port) == 0 {
log.Printf("Warning, PORT not set. Defaulting to %+vn", DEFAULT_PORT)
port = DEFAULT_PORT
}
http.HandleFunc("/view/", makeHandler(viewHandler))
http.HandleFunc("/edit/", makeHandler(editHandler))
http.HandleFunc("/save/", makeHandler(saveHandler))
http.ListenAndServe(":8080", nil)
http.ListenAndServe(":" + port, nil)
}

func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
err := templates.ExecuteTemplate(w, tmpl + ".html", p)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}