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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 142 var err error |
143 cwd, err := filepath.Abs(filepath.Dir(os.Args[0])) | 143 cwd, err := filepath.Abs(filepath.Dir(os.Args[0])) |
144 if err != nil { | 144 if err != nil { |
145 log.Fatal(err) | 145 log.Fatal(err) |
146 } | 146 } |
147 os.Chdir(cwd) | 147 os.Chdir(cwd) |
148 | 148 |
149 » codeTemplate, err = template.ParseFiles(filepath.Join(cwd, "templates/te
mplate.cpp")) | 149 » codeTemplate = template.Must(template.ParseFiles(filepath.Join(cwd, "tem
plates/template.cpp"))) |
150 » if err != nil { | 150 » gypTemplate = template.Must(template.ParseFiles(filepath.Join(cwd, "temp
lates/template.gyp"))) |
151 » » panic(err) | 151 » indexTemplate = htemplate.Must(htemplate.ParseFiles( |
152 » } | |
153 » gypTemplate, err = template.ParseFiles(filepath.Join(cwd, "templates/tem
plate.gyp")) | |
154 » if err != nil { | |
155 » » panic(err) | |
156 » } | |
157 » indexTemplate, err = htemplate.ParseFiles( | |
158 filepath.Join(cwd, "templates/index.html"), | 152 filepath.Join(cwd, "templates/index.html"), |
159 filepath.Join(cwd, "templates/titlebar.html"), | 153 filepath.Join(cwd, "templates/titlebar.html"), |
160 filepath.Join(cwd, "templates/sidebar.html"), | 154 filepath.Join(cwd, "templates/sidebar.html"), |
161 filepath.Join(cwd, "templates/content.html"), | 155 filepath.Join(cwd, "templates/content.html"), |
162 filepath.Join(cwd, "templates/headercommon.html"), | 156 filepath.Join(cwd, "templates/headercommon.html"), |
163 filepath.Join(cwd, "templates/footercommon.html"), | 157 filepath.Join(cwd, "templates/footercommon.html"), |
164 » ) | 158 » )) |
165 » if err != nil { | 159 » iframeTemplate = htemplate.Must(htemplate.ParseFiles( |
166 » » panic(err) | |
167 » } | |
168 » iframeTemplate, err = htemplate.ParseFiles( | |
169 filepath.Join(cwd, "templates/iframe.html"), | 160 filepath.Join(cwd, "templates/iframe.html"), |
170 filepath.Join(cwd, "templates/content.html"), | 161 filepath.Join(cwd, "templates/content.html"), |
171 filepath.Join(cwd, "templates/headercommon.html"), | 162 filepath.Join(cwd, "templates/headercommon.html"), |
172 filepath.Join(cwd, "templates/footercommon.html"), | 163 filepath.Join(cwd, "templates/footercommon.html"), |
173 » ) | 164 » )) |
174 » if err != nil { | 165 » recentTemplate = htemplate.Must(htemplate.ParseFiles( |
175 » » panic(err) | |
176 » } | |
177 » recentTemplate, err = htemplate.ParseFiles( | |
178 filepath.Join(cwd, "templates/recent.html"), | 166 filepath.Join(cwd, "templates/recent.html"), |
179 filepath.Join(cwd, "templates/titlebar.html"), | 167 filepath.Join(cwd, "templates/titlebar.html"), |
180 filepath.Join(cwd, "templates/sidebar.html"), | 168 filepath.Join(cwd, "templates/sidebar.html"), |
181 filepath.Join(cwd, "templates/headercommon.html"), | 169 filepath.Join(cwd, "templates/headercommon.html"), |
182 filepath.Join(cwd, "templates/footercommon.html"), | 170 filepath.Join(cwd, "templates/footercommon.html"), |
183 » ) | 171 » )) |
184 » if err != nil { | 172 » workspaceTemplate = htemplate.Must(htemplate.ParseFiles( |
185 » » panic(err) | |
186 » } | |
187 » workspaceTemplate, err = htemplate.ParseFiles( | |
188 filepath.Join(cwd, "templates/workspace.html"), | 173 filepath.Join(cwd, "templates/workspace.html"), |
189 filepath.Join(cwd, "templates/titlebar.html"), | 174 filepath.Join(cwd, "templates/titlebar.html"), |
190 filepath.Join(cwd, "templates/sidebar.html"), | 175 filepath.Join(cwd, "templates/sidebar.html"), |
191 filepath.Join(cwd, "templates/content.html"), | 176 filepath.Join(cwd, "templates/content.html"), |
192 filepath.Join(cwd, "templates/headercommon.html"), | 177 filepath.Join(cwd, "templates/headercommon.html"), |
193 filepath.Join(cwd, "templates/footercommon.html"), | 178 filepath.Join(cwd, "templates/footercommon.html"), |
194 » ) | 179 » )) |
195 » if err != nil { | |
196 » » panic(err) | |
197 » } | |
198 | 180 |
199 // The git command returns output of the format: | 181 // The git command returns output of the format: |
200 // | 182 // |
201 // f672cead70404080a991ebfb86c38316a4589b23 2014-04-27 19:21:51 +0000 | 183 // f672cead70404080a991ebfb86c38316a4589b23 2014-04-27 19:21:51 +0000 |
202 // | 184 // |
203 logOutput, err := doCmd(`git log --format=%H%x20%ai HEAD^..HEAD`) | 185 logOutput, err := doCmd(`git log --format=%H%x20%ai HEAD^..HEAD`) |
204 if err != nil { | 186 if err != nil { |
205 panic(err) | 187 panic(err) |
206 } | 188 } |
207 logInfo := strings.Split(logOutput, " ") | 189 logInfo := strings.Split(logOutput, " ") |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler)) | 885 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler)) |
904 | 886 |
905 // Resources are served directly | 887 // Resources are served directly |
906 // TODO add support for caching/etags/gzip | 888 // TODO add support for caching/etags/gzip |
907 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) | 889 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) |
908 | 890 |
909 // TODO Break out /c/ as it's own handler. | 891 // TODO Break out /c/ as it's own handler. |
910 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) | 892 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) |
911 log.Fatal(http.ListenAndServe(*port, nil)) | 893 log.Fatal(http.ListenAndServe(*port, nil)) |
912 } | 894 } |
OLD | NEW |