1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
// +build ignore
package main
import (
"fmt"
"strconv"
"strings"
"github.com/PuerkitoBio/goquery"
)
func main() {
doc, err := goquery.NewDocument("https://msdn.microsoft.com/en-us/library/cc704588.aspx")
if err != nil {
panic(err)
}
type entry struct {
key string
val string
str string
}
var entries []entry
doc.Find("table tr").Each(func(_ int, s *goquery.Selection) {
pairs := s.Find("td")
if pairs.Length() == 2 {
keyValuePair := pairs.Eq(0).Find("p")
key := keyValuePair.Eq(1).Text()
val := keyValuePair.Eq(0).Text()
str := strings.Replace(pairs.Eq(1).Find("p").Text(), "\n ", " ", -1)
entries = append(entries, entry{
key: key,
val: val,
str: str,
})
}
})
fmt.Println("package erref")
fmt.Println("type NtStatus uint32")
fmt.Println("func (e NtStatus) Error() string {")
fmt.Println("\treturn ntStatusStrings[e]")
fmt.Println("}")
fmt.Println("const (")
for _, e := range entries {
fmt.Printf("\t%s\tNtStatus\t=\t%s\n", e.key, e.val)
}
fmt.Println(")")
fmt.Println("var ntStatusStrings = map[NtStatus]string{")
m := make(map[string]bool)
for _, e := range entries {
if !m[e.val] {
fmt.Printf("\t%s:\t%s,\n", e.key, strconv.Quote(e.str))
}
m[e.val] = true
}
fmt.Println("}")
}
|