Skip to content

Commit fe9e612

Browse files
committed
initial commit
0 parents commit fe9e612

File tree

6 files changed

+126
-0
lines changed

6 files changed

+126
-0
lines changed

app.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
application: regexplanet-go
2+
version: 1
3+
runtime: go
4+
api_version: 3
5+
6+
handlers:
7+
- url: /favicon.ico
8+
static_files: favicon.ico
9+
upload: favicon.ico
10+
11+
- url: /robots.txt
12+
static_files: robots.txt
13+
upload: robots.txt
14+
15+
- url: /.*
16+
script: _go_app

deploy.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/usr/local/google_appengine/appcfg.py update .
2+

favicon.ico

9.11 KB
Binary file not shown.

robots.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# just a backend for the main RegexPlanet.com site: go there to index stuff!
3+
#
4+
User-agent: *
5+
Disallow: /

run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
/usr/local/google_appengine/dev_appserver.py --port=8081 .

src/regexplanet.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package regexplanet
2+
3+
import (
4+
"fmt"
5+
"http"
6+
"json"
7+
"os"
8+
"runtime"
9+
"time"
10+
)
11+
12+
func init() {
13+
http.HandleFunc("/", root_handler)
14+
http.HandleFunc("/status.json", status_handler)
15+
http.HandleFunc("/test.json", test_handler)
16+
}
17+
18+
func root_handler(w http.ResponseWriter, r *http.Request) {
19+
fmt.Fprint(w, "Hello, RegexPlanet!")
20+
}
21+
22+
type Status struct {
23+
Success bool
24+
Hostname string
25+
Getwd string
26+
TempDir string
27+
Envs []string
28+
Version string
29+
Seconds int64
30+
}
31+
32+
func status_handler(w http.ResponseWriter, r *http.Request) {
33+
var err os.Error
34+
status := Status{}
35+
36+
status.Getwd, err = os.Getwd()
37+
if err != nil {
38+
status.Getwd = "ERROR!"
39+
}
40+
41+
status.Hostname, err = os.Hostname()
42+
if err != nil {
43+
status.Hostname = "ERROR"
44+
}
45+
46+
status.TempDir = os.TempDir()
47+
status.Envs = os.Envs
48+
status.Version = runtime.Version()
49+
status.Seconds = time.Seconds()
50+
status.Success = true
51+
52+
var b []byte
53+
b, err = json.Marshal(status)
54+
if err != nil {
55+
return
56+
}
57+
58+
if b[2] == 'S' {// HACK: it doesn't get much hackier than this, but json.Marshal doesn't marshal lower-case members. Is there a way around this?
59+
b[2] = 's'
60+
}
61+
62+
w.Header().Set("Content-Type", "text/plain; charset=utf8")
63+
w.Write(b)
64+
}
65+
66+
type TestResult struct {
67+
Success bool
68+
Html string
69+
}
70+
71+
func test_handler(w http.ResponseWriter, r *http.Request) {
72+
73+
w.Header().Set("Content-Type", "text/plain; charset=utf8")
74+
w.Header().Set("Access-Control-Allow-Origin", "*")
75+
w.Header().Set("Access-Control-Allow-Methods", "POST, GET")
76+
w.Header().Set("Access-Control-Max-Age", "604800") // 1 week
77+
78+
retVal := TestResult{}
79+
80+
retVal.Success = true
81+
retVal.Html = "<div class=\"alert alert-warning\">Actually, it is a lot less than beta: the real code isn't even written yet!</div>"
82+
83+
var err os.Error
84+
var b []byte
85+
b, err = json.Marshal(retVal)
86+
if err != nil {
87+
fmt.Fprint(w, "{\"success\":false,\"html\":\"<p>json.Marshal failed</p>\"}")
88+
return
89+
}
90+
91+
if b[2] == 'S' {// HACK: it doesn't get much hackier than this, but json.Marshal doesn't marshal lower-case members. Is there a way around this?
92+
b[2] = 's'
93+
}
94+
95+
if b[17] == 'H' {
96+
b[17] = 'h'
97+
}
98+
99+
w.Write(b)
100+
}

0 commit comments

Comments
 (0)