-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46dc54b
commit decb9aa
Showing
37 changed files
with
2,940 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
syntax = "v1" | ||
|
||
service PowerX { | ||
@doc "健康检查接口" | ||
@handler HealthCheck | ||
get /health (HealthCheckRequest) returns (HealthCheckReply) | ||
} | ||
|
||
type HealthCheckRequest {} | ||
|
||
type HealthCheckReply {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
syntax = "v1" | ||
|
||
service PowerX { | ||
@doc "插件接口" | ||
@handler RegisterPlugin | ||
post /plugin/v1/plugins (RegisterPluginRequest) returns (RegisterPluginReply) | ||
|
||
@doc "插件列表拉取" | ||
@handler ListPlugin | ||
get /plugin/v1/plugins (ListPluginRequest) returns (ListPluginReply) | ||
|
||
@doc "插件路由拉取" | ||
@handler ListPluginFrontendRoutes | ||
get /plugin/v1/frontend-routes returns (ListPluginFrontendRoutesReply) | ||
} | ||
|
||
type ( | ||
Route struct { | ||
Method string `json:"method"` | ||
Path string `json:"path"` | ||
} | ||
|
||
RegisterPluginRequest { | ||
Name string `json:"name"` | ||
Routes []Route `json:"routes"` | ||
Addr string `json:"addr"` | ||
} | ||
|
||
RegisterPluginReply { | ||
Name string `json:"name"` | ||
etc map[string]interface{} `json:"etc"` | ||
} | ||
) | ||
|
||
type ( | ||
PluginWebRouteMeta { | ||
Locale string `json:"locale"` | ||
Icon string `json:"icon"` | ||
RequestAuth bool `json:"requestAuth"` | ||
} | ||
|
||
PluginWebRoutes struct { | ||
Name string `json:"name"` | ||
Path string `json:"path"` | ||
Meta PluginWebRouteMeta `json:"meta"` | ||
Children []PluginWebRoutes `json:"children"` | ||
} | ||
|
||
ListPluginRequest { | ||
// Scope ['routes'] | ||
Socpe []string `form:"scope"` | ||
} | ||
|
||
PluginWebInfo struct { | ||
Name string `json:"name"` | ||
Desc string `json:"desc"` | ||
Verison string `json:"version"` | ||
IsEnabled bool `json:"isEnabled"` | ||
Routes []Route `json:"routes"` | ||
} | ||
|
||
ListPluginReply { | ||
Plugins []PluginWebInfo `json:"plugins"` | ||
} | ||
) | ||
|
||
type ( | ||
ListPluginFrontendRoutesReply { | ||
Routes []PluginWebRoutes `json:"routes"` | ||
} | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package main | ||
|
||
import ( | ||
"PowerX/cmd/devctl/plugin" | ||
"PowerX/pkg/pluginx" | ||
"fmt" | ||
"github.com/urfave/cli/v2" | ||
"github.com/zeromicro/go-zero/tools/goctl/api/parser" | ||
"log" | ||
"os" | ||
) | ||
|
||
func main() { | ||
app := &cli.App{ | ||
Name: "powerd", | ||
Usage: "Manage plugins for PowerXDashboard", | ||
Commands: []*cli.Command{ | ||
{ | ||
Name: "plugin", | ||
Usage: "plugin usage", | ||
Subcommands: []*cli.Command{ | ||
{ | ||
Name: "build", | ||
Usage: "build plugin frontend", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{Name: "dir", Aliases: []string{"d"}, Value: "./plugins", Usage: "file dir"}, | ||
&cli.StringFlag{Name: "api", Aliases: []string{"a"}, Value: "/api/plugin", Usage: "api base url"}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
loader := pluginx.NewLoader(c.String("dir"), &pluginx.BuildLoaderConfig{ | ||
MainAPIEndpoint: c.String("api"), | ||
}) | ||
err := loader.CheckEnvDependency() | ||
if err != nil { | ||
return err | ||
} | ||
err = loader.UnArchives() | ||
if err != nil { | ||
return err | ||
} | ||
err = loader.BuildPluginFrontend(pluginx.BuildPluginFrontendOptions{ | ||
ReDownload: true, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "gen-client-api", | ||
Usage: "generate client api", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{Name: "dir", Aliases: []string{"d"}, Value: "./plugin-client", Usage: "target dir"}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
filePath := "api/powerx.api" | ||
api, err := parser.Parse(filePath) | ||
if err != nil { | ||
fmt.Println("Error parsing .api file:", err) | ||
return err | ||
} | ||
|
||
err = plugin.GenerateClientCode(api, c.String("dir")) | ||
if err != nil { | ||
fmt.Println("Error generating client code:", err) | ||
return err | ||
} | ||
return nil | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := app.Run(os.Args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package {{.PackageName}} | ||
|
||
import ( | ||
{{if .HasTypesImport}}"{{.TypesImportPath}}"{{end}} | ||
"context" | ||
{{if .HasFmtImport}}"fmt"{{end}} | ||
{{if .HasNetHttpImport}}"net/http"{{end}} | ||
) | ||
|
||
type {{.GroupName}} struct { | ||
*PowerX | ||
} | ||
|
||
{{range .Routes}} | ||
func (c *{{$.GroupName}}) {{.Handler}}(ctx context.Context, {{if ne .RequestTypeName ""}}req *powerxtypes.{{.RequestTypeName}}{{end}}) (*powerxtypes.{{.ResponseTypeName}}, error) { | ||
res := &powerxtypes.{{.ResponseTypeName}}{} | ||
err := c.H.Df().Method(http.Method{{CapFirst .Method}}). | ||
WithContext(ctx). | ||
Uri({{FormatPath .Path .Handler $.PathParamsMap}}). | ||
{{if and (ne (ToUpper .Method) "GET") (ne .RequestTypeName "")}}Json(req).{{else if and (eq (ToUpper .Method) "GET") (ne .RequestTypeName "")}}BindQuery(req).{{end}} | ||
Result(res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return res, nil | ||
} | ||
{{end}} |
Oops, something went wrong.