reflection work so far...
This commit is contained in:
57
internal/constmap/main.go
Normal file
57
internal/constmap/main.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
`bytes`
|
||||
`fmt`
|
||||
`go/ast`
|
||||
`go/parser`
|
||||
`go/token`
|
||||
`log`
|
||||
`os`
|
||||
|
||||
`r00t2.io/sysutils/paths`
|
||||
)
|
||||
|
||||
/*
|
||||
DO NOT RUN THIS ANYWHERE BUT FROM WHERE <r00t2.io/cryptparse>/consts.go IS LOCATED.
|
||||
*/
|
||||
|
||||
// I *cannot believe* a library does not exist that will do this for me.
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
var tfs *token.FileSet
|
||||
var af *ast.File
|
||||
var foundParams []*ParamConst
|
||||
var paramConsts []*ParamConst
|
||||
var buf *bytes.Buffer = new(bytes.Buffer)
|
||||
|
||||
if err = paths.RealPath(&constsPath); err != nil {
|
||||
return
|
||||
}
|
||||
if err = paths.RealPath(&outPath); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
tfs = token.NewFileSet()
|
||||
|
||||
if af, err = parser.ParseFile(tfs, constsPath, nil, parser.AllErrors|parser.ParseComments); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
for _, d := range af.Decls {
|
||||
if foundParams = getValueSpec(d); foundParams == nil {
|
||||
continue
|
||||
}
|
||||
paramConsts = append(paramConsts, foundParams...)
|
||||
}
|
||||
|
||||
if err = tpl.Execute(buf, paramConsts); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
if err = os.WriteFile(outPath, buf.Bytes(), 0644); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
fmt.Printf("++ Generated %s ++\n", outPath)
|
||||
}
|
||||
Reference in New Issue
Block a user