Last active
May 9, 2018 14:16
-
-
Save ambakshi/fea96d26e84fa319133ef3c13596a7a2 to your computer and use it in GitHub Desktop.
Simple store_id_program for squid. Build it, put it into /usr/lib64/squid/, and add "store_id_program /usr/lib64/squid/storeid_rpmdeb" to your squid.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
"regexp" | |
"strings" | |
) | |
func main() { | |
reader := bufio.NewReader(os.Stdin) | |
// re := regexp.MustCompile(`[^/]+\.(rpm|deb)`) | |
allre := []*regexp.Regexp{ | |
regexp.MustCompile(`[^/]+\.(rpm|deb)`), | |
regexp.MustCompile(`repodata/[0-9a-f]{40,64}-(filelists|primary|other|prestodelta)\.(xml|sqlite)\.(xz|gz|bz2)`), | |
} | |
for true { | |
line, err := reader.ReadString('\n') | |
if err != nil { | |
break | |
} | |
parts := strings.Split(line, " ") | |
url := strings.TrimSuffix(strings.TrimSpace(parts[0]), "?") | |
result := url | |
for _, re := range allre { | |
filename := re.FindString(url) | |
if len(filename) > 0 { | |
result = filename | |
break | |
} | |
} | |
fmt.Printf("OK store-id=%v\n", result) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment