Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ce30572957 | |||
| af2b6544c8 |
@@ -26,7 +26,7 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
http.HandleFunc("/", wepb2jpgHandler)
|
http.HandleFunc("/", webp2jpgHandler)
|
||||||
err = http.ListenAndServe(":9999", nil)
|
err = http.ListenAndServe(":9999", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -59,7 +59,7 @@ func hitCache(md5Path string, writer http.ResponseWriter) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func wepb2jpg(path string, md5Path string, writer http.ResponseWriter) {
|
func webp2jpg(path string, md5Path string, writer http.ResponseWriter) {
|
||||||
startTime := time.Now().UnixNano()
|
startTime := time.Now().UnixNano()
|
||||||
|
|
||||||
resp, getErr := http.Get(path)
|
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)
|
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")) {
|
if !(strings.HasPrefix(request.URL.RawQuery, "http") && strings.HasSuffix(request.URL.RawQuery, ".webp")) {
|
||||||
writer.WriteHeader(404)
|
writer.WriteHeader(404)
|
||||||
return
|
return
|
||||||
@@ -110,5 +110,6 @@ func wepb2jpgHandler(writer http.ResponseWriter, request *http.Request) {
|
|||||||
if hitCache(md5Path, writer) {
|
if hitCache(md5Path, writer) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
wepb2jpg(request.URL.RawQuery, md5Path, writer)
|
|
||||||
|
webp2jpg(request.URL.RawQuery, md5Path, writer)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user