Skip to content

Instantly share code, notes, and snippets.

@ambakshi
Last active May 9, 2018 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ambakshi/fea96d26e84fa319133ef3c13596a7a2 to your computer and use it in GitHub Desktop.
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
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