Compare commits
2 Commits
776a6062db
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| ce30572957 | |||
| af2b6544c8 |
@@ -26,7 +26,7 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
http.HandleFunc("/", wepb2jpgHandler)
|
||||
http.HandleFunc("/", webp2jpgHandler)
|
||||
err = http.ListenAndServe(":9999", nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -59,7 +59,7 @@ func hitCache(md5Path string, writer http.ResponseWriter) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func wepb2jpg(path string, md5Path string, writer http.ResponseWriter) {
|
||||
func webp2jpg(path string, md5Path string, writer http.ResponseWriter) {
|
||||
startTime := time.Now().UnixNano()
|
||||
|
||||
resp, getErr := http.Get(path)
|
||||
@@ -98,7 +98,7 @@ func wepb2jpg(path string, md5Path string, writer http.ResponseWriter) {
|
||||
fmt.Printf("编码耗时:%dms\n", (endTime-startTime)/1e6)
|
||||
}
|
||||
|
||||
func wepb2jpgHandler(writer http.ResponseWriter, request *http.Request) {
|
||||
func webp2jpgHandler(writer http.ResponseWriter, request *http.Request) {
|
||||
if !(strings.HasPrefix(request.URL.RawQuery, "http") && strings.HasSuffix(request.URL.RawQuery, ".webp")) {
|
||||
writer.WriteHeader(404)
|
||||
return
|
||||
@@ -110,5 +110,6 @@ func wepb2jpgHandler(writer http.ResponseWriter, request *http.Request) {
|
||||
if hitCache(md5Path, writer) {
|
||||
return
|
||||
}
|
||||
wepb2jpg(request.URL.RawQuery, md5Path, writer)
|
||||
|
||||
webp2jpg(request.URL.RawQuery, md5Path, writer)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user