Skip to content

Commit

Permalink
ci: run go generate on CI (#27)
Browse files Browse the repository at this point in the history
* ci: run go generate on CI

* make the go generate output stable
  • Loading branch information
marten-seemann authored Feb 24, 2023
1 parent bce6420 commit 7b80196
Show file tree
Hide file tree
Showing 3 changed files with 93,036 additions and 78,794 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/go-check-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"gogenerate": true
}
14 changes: 13 additions & 1 deletion generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net"
"net/http"
"os"
"sort"
"strings"

u "github.com/ipfs/go-ipfs-util"
Expand Down Expand Up @@ -48,6 +49,10 @@ func main() {
writeMappingToFile(f, ipv6CidrToAsnMap, ipv6listName)
}

type listEntry struct {
cidr, asn string
}

func writeMappingToFile(f *os.File, m map[string]string, listName string) {
printf := func(s string, args ...interface{}) {
_, err := fmt.Fprintf(f, s, args...)
Expand All @@ -58,8 +63,15 @@ func writeMappingToFile(f *os.File, m map[string]string, listName string) {
printf("package %s\n\n", pkgName)
printf("// Code generated by generate/main.go DO NOT EDIT\n")
printf("var %s = [...]struct{ cidr, asn string }{", listName)
l := make([]listEntry, 0, len(m))
for k, v := range m {
printf("\n\t{\"%s\", \"%s\"},", k, v)
l = append(l, listEntry{cidr: k, asn: v})
}
sort.Slice(l, func(i, j int) bool {
return l[i].cidr < l[j].cidr
})
for _, e := range l {
printf("\n\t{\"%s\", \"%s\"},", e.cidr, e.asn)
}
printf("\n}\n")
}
Expand Down
Loading

0 comments on commit 7b80196

Please sign in to comment.