Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
jzero gen
go get github.com/jzero-io/jzero@${{ github.sha }}
go mod tidy
jzero new helloworld --serverless
jzero new helloworld --serverless --mono
cd plugins/helloworld
jzero add api helloworld
jzero gen
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
jzero gen
go get github.com/jzero-io/jzero@${{ github.sha }}
go mod tidy
jzero new helloworld --frame gateway --serverless
jzero new helloworld --frame gateway --serverless --mono
cd plugins/helloworld
jzero add proto helloworld
jzero gen
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
jzero add proto user
go get github.com/jzero-io/jzero@${{ github.sha }}
go mod tidy
jzero new helloworld --frame rpc --serverless
jzero new helloworld --frame rpc --serverless --mono
cd plugins/helloworld
jzero add proto helloworld
jzero gen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,43 @@ func Run() error {
return err
}
for _, p := range plugins {
if !strings.HasPrefix(p.Path, "./") {
p.Path = "./" + p.Path
}
if err = work.DropUse(p.Path); err != nil {
return err
if !p.Mono {
if !strings.HasPrefix(p.Path, "./") {
p.Path = "./" + p.Path
}
if err = work.DropUse(p.Path); err != nil {
return err
}
}
}
for _, p := range plugins {
if !strings.HasPrefix(p.Path, "./") {
p.Path = "./" + p.Path
}
if err = work.AddUse(p.Path, ""); err != nil {
return err
if !p.Mono {
if !strings.HasPrefix(p.Path, "./") {
p.Path = "./" + p.Path
}
if err = work.AddUse(p.Path, ""); err != nil {
return err
}
}
}
if err = os.WriteFile("go.work", modfile.Format(work.Syntax), 0o644); err != nil {
return err
}
} else {
initArgs := []string{"work", "init", "."}
var pluginArgs []string
for _, p := range plugins {
initArgs = append(initArgs, p.Path)
if !p.Mono {
pluginArgs = append(pluginArgs, p.Path)
}
}
ec := exec.Command("go", initArgs...)
ec.Dir = wd
output, err := ec.CombinedOutput()
if err != nil {
return errors.Wrapf(err, "go work init meet error %s", string(output))
if len(pluginArgs) > 0 {
ec := exec.Command("go", append(initArgs, pluginArgs...)...)
ec.Dir = wd
output, err := ec.CombinedOutput()
if err != nil {
return errors.Wrapf(err, "go work init meet error %s", string(output))
}
}
}

Expand All @@ -69,11 +78,15 @@ func Run() error {
return err
}
for i := 0; i < len(plugins); i++ {
pluginGoMod, err := mod.GetGoMod(filepath.Join(wd, plugins[i].Path))
if err != nil {
return err
if !plugins[i].Mono {
pluginGoMod, err := mod.GetGoMod(filepath.Join(wd, plugins[i].Path))
if err != nil {
return err
}
plugins[i].Module = pluginGoMod.Path
} else {
plugins[i].Module = filepath.ToSlash(filepath.Join(goMod.Path, "plugins", plugins[i].Name))
}
plugins[i].Module = pluginGoMod.Path
}

frameType, err := desc.GetFrameType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ func Run() error {
return err
}
for _, p := range deletePlugins {
if !strings.HasPrefix(p.Path, "./") {
p.Path = "./" + p.Path
}
if err = work.DropUse(p.Path); err != nil {
return err
if !p.Mono {
if !strings.HasPrefix(p.Path, "./") {
p.Path = "./" + p.Path
}
if err = work.DropUse(p.Path); err != nil {
return err
}
}
}
if err = os.WriteFile("go.work", modfile.Format(work.Syntax), 0o644); err != nil {
Expand All @@ -73,11 +75,15 @@ func Run() error {
}

for i := 0; i < len(remainingPlugins); i++ {
pluginGoMod, err := mod.GetGoMod(filepath.Join(wd, remainingPlugins[i].Path))
if err != nil {
return err
if !plugins[i].Mono {
pluginGoMod, err := mod.GetGoMod(filepath.Join(wd, remainingPlugins[i].Path))
if err != nil {
return err
}
remainingPlugins[i].Module = pluginGoMod.Path
} else {
remainingPlugins[i].Module = filepath.ToSlash(filepath.Join(goMod.Path, "plugins", remainingPlugins[i].Name))
}
remainingPlugins[i].Module = pluginGoMod.Path
}

frameType, err := desc.GetFrameType()
Expand Down
9 changes: 9 additions & 0 deletions cmd/jzero/internal/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package plugin
import (
"os"
"path/filepath"

"github.com/jzero-io/jzero/cmd/jzero/internal/pkg/filex"
)

type Plugin struct {
Name string
Path string
Module string
Mono bool
}

func GetPlugins() ([]Plugin, error) {
Expand All @@ -22,11 +25,17 @@ func GetPlugins() ([]Plugin, error) {
plugins = append(plugins, Plugin{
Name: p.Name(),
Path: filepath.ToSlash(filepath.Join("plugins", p.Name())),
Mono: func() bool {
return !filex.FileExists(filepath.Join("plugins", p.Name(), "go.mod"))
}(),
})
} else if p.Type() == os.ModeSymlink {
plugins = append(plugins, Plugin{
Name: p.Name(),
Path: filepath.ToSlash(filepath.Join("plugins", p.Name())),
Mono: func() bool {
return !filex.FileExists(filepath.Join("plugins", p.Name(), "go.mod"))
}(),
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions docs/src/guide/serverless.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ jzero 支持插件化机制, 可以方便的进行插件的安装和卸载操作
```shell
# api 项目插件
jzero new your_plugin --frame api --serverless
# api 项目插件 mono
jzero new your_plugin --frame api --serverless --mono

# rpc 项目插件
jzero new your_plugin --frame rpc --serverless
# rpc 项目插件 mono
jzero new your_plugin --frame rpc --serverless --mono

# gateway 项目插件
jzero new your_plugin --frame gateway --serverless
# gateway 项目插件 mono
jzero new your_plugin --frame gateway --serverless --mono
```

## 编译项目
Expand Down
Loading