cache.go 459 B

12345678910111213141516171819202122232425262728
  1. package main
  2. import (
  3. "go/ast"
  4. "go/token"
  5. )
  6. var (
  7. _packageCache = make(map[string]*pkgC)
  8. )
  9. type pkgC struct {
  10. files []*ast.File
  11. fset *token.FileSet
  12. }
  13. func packageCache(dir string) (files []*ast.File, fset *token.FileSet, ok bool) {
  14. c, ok := _packageCache[dir]
  15. if ok {
  16. files = c.files
  17. fset = c.fset
  18. }
  19. return
  20. }
  21. func setPackageCache(dir string, fset *token.FileSet, files []*ast.File) {
  22. _packageCache[dir] = &pkgC{fset: fset, files: files}
  23. }