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 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 return | 930 return |
931 } | 931 } |
932 | 932 |
933 png, err := ioutil.ReadFile("../../../inout/" + hash + ".png") | 933 png, err := ioutil.ReadFile("../../../inout/" + hash + ".png") |
934 if err != nil { | 934 if err != nil { |
935 reportTryError(w, r, err, "Failed to open the generated
PNG.", hash) | 935 reportTryError(w, r, err, "Failed to open the generated
PNG.", hash) |
936 return | 936 return |
937 } | 937 } |
938 | 938 |
939 m := response{ | 939 m := response{ |
940 » » » Message: message, | 940 » » » Img: base64.StdEncoding.EncodeToString([]byte(png)), |
941 » » » Img: base64.StdEncoding.EncodeToString([]byte(png)), | 941 » » » Hash: hash, |
942 » » » Hash: hash, | |
943 } | 942 } |
944 resp, err := json.Marshal(m) | 943 resp, err := json.Marshal(m) |
945 if err != nil { | 944 if err != nil { |
946 reportTryError(w, r, err, "Failed to serialize a respons
e.", hash) | 945 reportTryError(w, r, err, "Failed to serialize a respons
e.", hash) |
947 return | 946 return |
948 } | 947 } |
949 w.Header().Set("Content-Type", "application/json") | 948 w.Header().Set("Content-Type", "application/json") |
950 w.Write(resp) | 949 w.Write(resp) |
951 } | 950 } |
952 } | 951 } |
953 | 952 |
954 func main() { | 953 func main() { |
955 flag.Parse() | 954 flag.Parse() |
956 http.HandleFunc("/i/", autogzip.HandleFunc(imageHandler)) | 955 http.HandleFunc("/i/", autogzip.HandleFunc(imageHandler)) |
957 http.HandleFunc("/w/", autogzip.HandleFunc(workspaceHandler)) | 956 http.HandleFunc("/w/", autogzip.HandleFunc(workspaceHandler)) |
958 http.HandleFunc("/recent/", autogzip.HandleFunc(recentHandler)) | 957 http.HandleFunc("/recent/", autogzip.HandleFunc(recentHandler)) |
959 http.HandleFunc("/iframe/", autogzip.HandleFunc(iframeHandler)) | 958 http.HandleFunc("/iframe/", autogzip.HandleFunc(iframeHandler)) |
960 http.HandleFunc("/json/", autogzip.HandleFunc(tryInfoHandler)) | 959 http.HandleFunc("/json/", autogzip.HandleFunc(tryInfoHandler)) |
961 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler)) | 960 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler)) |
962 | 961 |
963 // Resources are served directly | 962 // Resources are served directly |
964 // TODO add support for caching/etags/gzip | 963 // TODO add support for caching/etags/gzip |
965 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) | 964 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) |
966 | 965 |
967 // TODO Break out /c/ as it's own handler. | 966 // TODO Break out /c/ as it's own handler. |
968 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) | 967 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) |
969 glog.Fatal(http.ListenAndServe(*port, nil)) | 968 glog.Fatal(http.ListenAndServe(*port, nil)) |
970 } | 969 } |
OLD | NEW |