github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/brutecheck/mapcheck.go (about)

     1  package main
     2  
     3  type MapCheck struct{}
     4  
     5  func (MapCheck) Generate(p Printer, keywords []string) {
     6  	minlen, _ := keywordBounds(keywords)
     7  	if minlen < 2 {
     8  		return
     9  	}
    10  
    11  	p.F("var __mapcheck = map[string]struct{}{\n")
    12  	for _, keyword := range keywords {
    13  		p.F("%q: struct{}{},\n", keyword)
    14  	}
    15  	p.F("}\n")
    16  
    17  	p.FuncName("MapCheck")
    18  	p.F("func MapCheck(name string) bool {\n")
    19  	p.F("_, ok := __mapcheck[name]\n")
    20  	p.F("return ok\n")
    21  
    22  	p.F("}\n\n")
    23  }