OLD | NEW |
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "bytes" | 4 "bytes" |
5 "crypto/md5" | 5 "crypto/md5" |
6 "database/sql" | 6 "database/sql" |
7 "encoding/base64" | 7 "encoding/base64" |
8 "encoding/binary" | 8 "encoding/binary" |
9 "encoding/json" | 9 "encoding/json" |
10 "flag" | 10 "flag" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 ret = append(ret, fmt.Sprintf("#line %d", i+1)) | 132 ret = append(ret, fmt.Sprintf("#line %d", i+1)) |
133 ret = append(ret, line) | 133 ret = append(ret, line) |
134 } | 134 } |
135 return strings.Join(ret, "\n") | 135 return strings.Join(ret, "\n") |
136 } | 136 } |
137 | 137 |
138 func init() { | 138 func init() { |
139 rand.Seed(time.Now().UnixNano()) | 139 rand.Seed(time.Now().UnixNano()) |
140 | 140 |
141 // Change the current working directory to the directory of the executab
le. | 141 // Change the current working directory to the directory of the executab
le. |
142 var err error | |
143 cwd, err := filepath.Abs(filepath.Dir(os.Args[0])) | 142 cwd, err := filepath.Abs(filepath.Dir(os.Args[0])) |
144 if err != nil { | 143 if err != nil { |
145 log.Fatal(err) | 144 log.Fatal(err) |
146 } | 145 } |
147 » os.Chdir(cwd) | 146 » if err := os.Chdir(cwd); err != nil { |
| 147 » » log.Fatal(err) |
| 148 » } |
148 | 149 |
149 codeTemplate = template.Must(template.ParseFiles(filepath.Join(cwd, "tem
plates/template.cpp"))) | 150 codeTemplate = template.Must(template.ParseFiles(filepath.Join(cwd, "tem
plates/template.cpp"))) |
150 gypTemplate = template.Must(template.ParseFiles(filepath.Join(cwd, "temp
lates/template.gyp"))) | 151 gypTemplate = template.Must(template.ParseFiles(filepath.Join(cwd, "temp
lates/template.gyp"))) |
151 indexTemplate = htemplate.Must(htemplate.ParseFiles( | 152 indexTemplate = htemplate.Must(htemplate.ParseFiles( |
152 filepath.Join(cwd, "templates/index.html"), | 153 filepath.Join(cwd, "templates/index.html"), |
153 filepath.Join(cwd, "templates/titlebar.html"), | 154 filepath.Join(cwd, "templates/titlebar.html"), |
154 filepath.Join(cwd, "templates/sidebar.html"), | 155 filepath.Join(cwd, "templates/sidebar.html"), |
155 filepath.Join(cwd, "templates/content.html"), | 156 filepath.Join(cwd, "templates/content.html"), |
156 filepath.Join(cwd, "templates/headercommon.html"), | 157 filepath.Join(cwd, "templates/headercommon.html"), |
157 filepath.Join(cwd, "templates/footercommon.html"), | 158 filepath.Join(cwd, "templates/footercommon.html"), |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler)) | 903 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler)) |
903 | 904 |
904 // Resources are served directly | 905 // Resources are served directly |
905 // TODO add support for caching/etags/gzip | 906 // TODO add support for caching/etags/gzip |
906 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) | 907 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) |
907 | 908 |
908 // TODO Break out /c/ as it's own handler. | 909 // TODO Break out /c/ as it's own handler. |
909 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) | 910 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) |
910 log.Fatal(http.ListenAndServe(*port, nil)) | 911 log.Fatal(http.ListenAndServe(*port, nil)) |
911 } | 912 } |
OLD | NEW |