| 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 func LineNumbers(c string) string { | 132 func LineNumbers(c string) string { |
| 133 lines := strings.Split(c, "\n") | 133 lines := strings.Split(c, "\n") |
| 134 ret := []string{} | 134 ret := []string{} |
| 135 for i, line := range lines { | 135 for i, line := range lines { |
| 136 ret = append(ret, fmt.Sprintf("#line %d", i+1)) | 136 ret = append(ret, fmt.Sprintf("#line %d", i+1)) |
| 137 ret = append(ret, line) | 137 ret = append(ret, line) |
| 138 } | 138 } |
| 139 return strings.Join(ret, "\n") | 139 return strings.Join(ret, "\n") |
| 140 } | 140 } |
| 141 | 141 |
| 142 func init() { | 142 func Init() { |
| 143 rand.Seed(time.Now().UnixNano()) | 143 rand.Seed(time.Now().UnixNano()) |
| 144 | 144 |
| 145 // Change the current working directory to the directory of the executab
le. | 145 // Change the current working directory to the directory of the executab
le. |
| 146 cwd, err := filepath.Abs(filepath.Dir(os.Args[0])) | 146 cwd, err := filepath.Abs(filepath.Dir(os.Args[0])) |
| 147 if err != nil { | 147 if err != nil { |
| 148 glog.Fatal(err) | 148 glog.Fatal(err) |
| 149 } | 149 } |
| 150 if err := os.Chdir(cwd); err != nil { | 150 if err := os.Chdir(cwd); err != nil { |
| 151 glog.Fatal(err) | 151 glog.Fatal(err) |
| 152 } | 152 } |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 reportTryError(w, r, err, "Failed to serialize a respons
e.", hash) | 945 reportTryError(w, r, err, "Failed to serialize a respons
e.", hash) |
| 946 return | 946 return |
| 947 } | 947 } |
| 948 w.Header().Set("Content-Type", "application/json") | 948 w.Header().Set("Content-Type", "application/json") |
| 949 w.Write(resp) | 949 w.Write(resp) |
| 950 } | 950 } |
| 951 } | 951 } |
| 952 | 952 |
| 953 func main() { | 953 func main() { |
| 954 flag.Parse() | 954 flag.Parse() |
| 955 Init() |
| 955 http.HandleFunc("/i/", autogzip.HandleFunc(imageHandler)) | 956 http.HandleFunc("/i/", autogzip.HandleFunc(imageHandler)) |
| 956 http.HandleFunc("/w/", autogzip.HandleFunc(workspaceHandler)) | 957 http.HandleFunc("/w/", autogzip.HandleFunc(workspaceHandler)) |
| 957 http.HandleFunc("/recent/", autogzip.HandleFunc(recentHandler)) | 958 http.HandleFunc("/recent/", autogzip.HandleFunc(recentHandler)) |
| 958 http.HandleFunc("/iframe/", autogzip.HandleFunc(iframeHandler)) | 959 http.HandleFunc("/iframe/", autogzip.HandleFunc(iframeHandler)) |
| 959 http.HandleFunc("/json/", autogzip.HandleFunc(tryInfoHandler)) | 960 http.HandleFunc("/json/", autogzip.HandleFunc(tryInfoHandler)) |
| 960 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler)) | 961 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler)) |
| 961 | 962 |
| 962 // Resources are served directly | 963 // Resources are served directly |
| 963 // TODO add support for caching/etags/gzip | 964 // TODO add support for caching/etags/gzip |
| 964 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) | 965 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) |
| 965 | 966 |
| 966 // TODO Break out /c/ as it's own handler. | 967 // TODO Break out /c/ as it's own handler. |
| 967 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) | 968 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) |
| 968 glog.Fatal(http.ListenAndServe(*port, nil)) | 969 glog.Fatal(http.ListenAndServe(*port, nil)) |
| 969 } | 970 } |
| OLD | NEW |