CDN model
This commit is contained in:
@@ -34,10 +34,10 @@ func main() {
|
|||||||
var mysqlConnection models.MysqlConnection
|
var mysqlConnection models.MysqlConnection
|
||||||
mysqlConnection.Init()
|
mysqlConnection.Init()
|
||||||
|
|
||||||
// URL 格式: /img/{type}/{id}.{format}?width=320&height=320&fit=cover
|
// URL 格式: /img/{type}-{id}.{format}?width=320&height=320&fit=cover
|
||||||
http.HandleFunc("/img/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/img/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Println(r.Method, r.URL.Path)
|
log.Println(r.Method, r.URL.Path)
|
||||||
reg := regexp.MustCompile(`^/img/([0-9a-zA-Z]+)/([0-9a-zA-Z]+).(jpg|jpeg|png|webp)$`)
|
reg := regexp.MustCompile(`^/img/([0-9a-zA-Z]+)-([0-9a-zA-Z]+).(jpg|jpeg|png|webp)$`)
|
||||||
matches := reg.FindStringSubmatch(r.URL.Path)
|
matches := reg.FindStringSubmatch(r.URL.Path)
|
||||||
if len(matches) != 4 {
|
if len(matches) != 4 {
|
||||||
log.Println("URL 格式错误", matches)
|
log.Println("URL 格式错误", matches)
|
||||||
@@ -70,7 +70,7 @@ func main() {
|
|||||||
log.Println(r.Method, r.URL.Path)
|
log.Println(r.Method, r.URL.Path)
|
||||||
reg := regexp.MustCompile(`^/webp/([0-9a-zA-Z]+)-([0-9a-zA-Z]+)-([0-9a-zA-Z]+)-([0-9]+)-([0-9]+)-([a-zA-Z]+).(jpg|jpeg|png|webp)$`)
|
reg := regexp.MustCompile(`^/webp/([0-9a-zA-Z]+)-([0-9a-zA-Z]+)-([0-9a-zA-Z]+)-([0-9]+)-([0-9]+)-([a-zA-Z]+).(jpg|jpeg|png|webp)$`)
|
||||||
matches := reg.FindStringSubmatch(r.URL.Path)
|
matches := reg.FindStringSubmatch(r.URL.Path)
|
||||||
if len(matches) != 4 {
|
if len(matches) != 8 {
|
||||||
log.Println("URL 格式错误", matches)
|
log.Println("URL 格式错误", matches)
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user