github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/gen/codegen/gen_files.go (about)

     1  package codegen
     2  
     3  import (
     4  	"path/filepath"
     5  	"strings"
     6  )
     7  
     8  func IsGoFile(filename string) bool {
     9  	return filepath.Ext(filename) == ".go"
    10  }
    11  
    12  func IsGoTestFile(filename string) bool {
    13  	return strings.HasSuffix(filepath.Base(filename), "_test.go")
    14  }
    15  
    16  func GenerateFileSuffix(fn string) string {
    17  	dir, base, ext := filepath.Dir(fn), filepath.Base(fn), filepath.Ext(fn)
    18  	if IsGoFile(fn) && IsGoTestFile(fn) {
    19  		base = strings.Replace(base, "_test.go", "__generated_test.go", -1)
    20  	} else {
    21  		base = strings.Replace(base, ext, "__generated"+ext, -1)
    22  	}
    23  	return filepath.Join(dir, base)
    24  }