1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-30 10:10:44 +02:00

Document Gomu's generator package (#2262)

This commit is contained in:
Niek den Breeje 2021-09-10 19:48:09 +02:00 committed by GitHub
parent 5b8d22a463
commit ac21bb5b19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 5 deletions

View File

@ -7,6 +7,9 @@ import (
"text/template"
)
// Generator is the interface that generates project template files.
//
// Generate accepts a list of files and generates them based on their template.
type Generator interface {
Generate([]File) error
}
@ -15,8 +18,11 @@ type generator struct {
opts Options
}
// File represents a file to generate.
type File struct {
Path string
// Path specifies where the file will reside.
Path string
// Template is the template used to generate the file.
Template string
}

View File

@ -1,47 +1,62 @@
package generator
// Options represents the options for the generator.
type Options struct {
Service string
Vendor string
// Service is the name of the service the generator will generate files
// for.
Service string
// Vendor is the service vendor.
Vendor string
// Directory is the directory where the files will be generated to.
Directory string
Client bool
Jaeger bool
// Client determines whether or not the project is a client project.
Client bool
// Jaeger determines whether or not Jaeger integration is enabled.
Jaeger bool
// Jaeger determines whether or not Skaffold integration is enabled.
Skaffold bool
}
// Option manipulates the Options passed.
type Option func(o *Options)
// Service sets the service name.
func Service(s string) Option {
return func(o *Options) {
o.Service = s
}
}
// Vendor sets the service vendor.
func Vendor(v string) Option {
return func(o *Options) {
o.Vendor = v
}
}
// Directory sets the directory in which files are generated.
func Directory(d string) Option {
return func(o *Options) {
o.Directory = d
}
}
// Client sets whether or not the project is a client project.
func Client(c bool) Option {
return func(o *Options) {
o.Client = c
}
}
// Jaeger sets whether or not Jaeger integration is enabled.
func Jaeger(j bool) Option {
return func(o *Options) {
o.Jaeger = j
}
}
// Skaffold sets whether or not Skaffold integration is enabled.
func Skaffold(s bool) Option {
return func(o *Options) {
o.Skaffold = s