This commit is contained in:
2022-02-23 11:37:34 +08:00
parent 4b6d62d02b
commit 808b315360

12
main.go
View File

@@ -21,10 +21,8 @@ const (
func checkUrl(u string) bool { func checkUrl(u string) bool {
for _, exp := range []string{exp1, exp2, exp3, exp4, exp5, exp6} { for _, exp := range []string{exp1, exp2, exp3, exp4, exp5, exp6} {
if ok, e := regexp.MatchString(exp, u); ok { if ok, _ := regexp.MatchString(exp, u); ok {
return true return true
} else if e != nil {
fmt.Println(e)
} }
} }
return false return false
@@ -50,15 +48,15 @@ func fetchHandler(w http.ResponseWriter, r *http.Request) {
match6, _ := regexp.MatchString(exp6, u.String()) match6, _ := regexp.MatchString(exp6, u.String())
if match1 || match5 || match6 || match3 || match4 { if match1 || match5 || match6 || match3 || match4 {
httpHandler(w, r, path) httpHandler(w, r, u.String())
return return
} else if match2 { } else if match2 {
path = strings.ReplaceAll(u.Path, "/blob/", "/raw/") u.Path = strings.ReplaceAll(u.Path, "/blob/", "/raw/")
httpHandler(w, r, path) httpHandler(w, r, u.String())
return return
} }
http.Error(w, fmt.Sprintf("%s is not support", path), http.StatusOK) http.Error(w, fmt.Sprintf("%s is not support", u.String()), http.StatusOK)
} }
func httpHandler(w http.ResponseWriter, r *http.Request, pathname string) { func httpHandler(w http.ResponseWriter, r *http.Request, pathname string) {