Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
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