mirror of
https://github.com/go-micro/go-micro.git
synced 2025-01-17 17:44:30 +02:00
Make generator package a first class citizen (#2259)
There's really no point in having the `generator` be embedded in a `file` package so we remove the `file` package and make the `generator` package a first class citizen instead.
This commit is contained in:
parent
e23006b1a5
commit
5772697752
@ -7,9 +7,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/asim/go-micro/cmd/gomu/cmd"
|
||||
"github.com/asim/go-micro/cmd/gomu/file"
|
||||
"github.com/asim/go-micro/cmd/gomu/file/generator"
|
||||
tmpl "github.com/asim/go-micro/cmd/gomu/file/template"
|
||||
"github.com/asim/go-micro/cmd/gomu/generator"
|
||||
tmpl "github.com/asim/go-micro/cmd/gomu/generator/template"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@ -49,7 +48,7 @@ func Skaffold(ctx *cli.Context) error {
|
||||
generator.Skaffold(true),
|
||||
)
|
||||
|
||||
files := []file.File{
|
||||
files := []generator.File{
|
||||
{".dockerignore", tmpl.DockerIgnore},
|
||||
{"go.mod", tmpl.Module},
|
||||
{"plugins.go", tmpl.Plugins},
|
||||
|
@ -7,9 +7,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/asim/go-micro/cmd/gomu/cmd"
|
||||
"github.com/asim/go-micro/cmd/gomu/file"
|
||||
"github.com/asim/go-micro/cmd/gomu/file/generator"
|
||||
tmpl "github.com/asim/go-micro/cmd/gomu/file/template"
|
||||
"github.com/asim/go-micro/cmd/gomu/generator"
|
||||
tmpl "github.com/asim/go-micro/cmd/gomu/generator/template"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@ -100,7 +99,7 @@ func createProject(ctx *cli.Context, pt string) error {
|
||||
generator.Skaffold(ctx.Bool("skaffold")),
|
||||
)
|
||||
|
||||
files := []file.File{
|
||||
files := []generator.File{
|
||||
{".dockerignore", tmpl.DockerIgnore},
|
||||
{".gitignore", tmpl.GitIgnore},
|
||||
{"Dockerfile", tmpl.Dockerfile},
|
||||
@ -110,17 +109,17 @@ func createProject(ctx *cli.Context, pt string) error {
|
||||
|
||||
switch pt {
|
||||
case "client":
|
||||
files = append(files, []file.File{
|
||||
files = append(files, []generator.File{
|
||||
{"main.go", tmpl.MainCLT},
|
||||
}...)
|
||||
case "function":
|
||||
files = append(files, []file.File{
|
||||
files = append(files, []generator.File{
|
||||
{"handler/" + name + ".go", tmpl.HandlerFNC},
|
||||
{"main.go", tmpl.MainFNC},
|
||||
{"proto/" + name + ".proto", tmpl.ProtoFNC},
|
||||
}...)
|
||||
case "service":
|
||||
files = append(files, []file.File{
|
||||
files = append(files, []generator.File{
|
||||
{"handler/" + name + ".go", tmpl.HandlerSRV},
|
||||
{"main.go", tmpl.MainSRV},
|
||||
{"proto/" + name + ".proto", tmpl.ProtoSRV},
|
||||
@ -130,7 +129,7 @@ func createProject(ctx *cli.Context, pt string) error {
|
||||
}
|
||||
|
||||
if ctx.Bool("skaffold") {
|
||||
files = append(files, []file.File{
|
||||
files = append(files, []generator.File{
|
||||
{"plugins.go", tmpl.Plugins},
|
||||
{"resources/clusterrole.yaml", tmpl.KubernetesClusterRole},
|
||||
{"resources/configmap.yaml", tmpl.KubernetesEnv},
|
||||
|
@ -1,6 +0,0 @@
|
||||
package file
|
||||
|
||||
type File struct {
|
||||
Path string
|
||||
Template string
|
||||
}
|
@ -5,20 +5,23 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/asim/go-micro/cmd/gomu/file"
|
||||
)
|
||||
|
||||
type Generator interface {
|
||||
Generate([]file.File) error
|
||||
Generate([]File) error
|
||||
}
|
||||
|
||||
type generator struct {
|
||||
opts Options
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Path string
|
||||
Template string
|
||||
}
|
||||
|
||||
// Generate generates project template files.
|
||||
func (g *generator) Generate(files []file.File) error {
|
||||
func (g *generator) Generate(files []File) error {
|
||||
for _, file := range files {
|
||||
fp := filepath.Join(g.opts.Directory, file.Path)
|
||||
dir := filepath.Dir(fp)
|
Loading…
x
Reference in New Issue
Block a user