package main import ( "errors" "fmt" "os" "strings" ) func removeAdvFile(src string) error { index := strings.Index(src, "static/adv") if index == -1 { return errors.New("error src") } path := src[index:] return os.Remove(path) } func main() { err := removeAdvFile("https://wine.ifarmcloud.com/api/static/adv/20230925-test.jpg") fmt.Println(err) }