github.com/clubpay/ronykit/kit@v0.14.4-0.20240515065620-d0dace45cbc7/stub/stubgen/options.go (about)

     1  package stubgen
     2  
     3  type Option func(*genConfig)
     4  
     5  type genConfig struct {
     6  	genFunc GenFunc
     7  	// stubName is name of the stub that will be generated.
     8  	stubName string
     9  	// pkgName is name of the package the is generated.
    10  	// It is useful in languages that need package name like go
    11  	pkgName string
    12  	// folderName is name of the folder that will be created and generated
    13  	// code will be placed in it.
    14  	folderName string
    15  	// outputDir is the directory where the generated code will be placed.
    16  	// final path will be outputDir/folderName
    17  	// default is current directory
    18  	outputDir     string
    19  	fileExtension string
    20  	tags          []string
    21  }
    22  
    23  var defaultConfig = genConfig{
    24  	genFunc:       GolangStub,
    25  	fileExtension: ".go",
    26  	outputDir:     ".", // current directory
    27  }
    28  
    29  func WithGenFunc(gf GenFunc, ext string) Option {
    30  	return func(c *genConfig) {
    31  		c.genFunc = gf
    32  		c.fileExtension = ext
    33  	}
    34  }
    35  
    36  func WithPkgName(name string) Option {
    37  	return func(c *genConfig) {
    38  		c.pkgName = name
    39  	}
    40  }
    41  
    42  func WithFolderName(name string) Option {
    43  	return func(c *genConfig) {
    44  		c.folderName = name
    45  	}
    46  }
    47  
    48  func WithOutputDir(dir string) Option {
    49  	return func(c *genConfig) {
    50  		c.outputDir = dir
    51  	}
    52  }
    53  
    54  func WithTags(tags ...string) Option {
    55  	return func(c *genConfig) {
    56  		c.tags = tags
    57  	}
    58  }
    59  
    60  func WithStubName(name string) Option {
    61  	return func(c *genConfig) {
    62  		c.stubName = name
    63  	}
    64  }