Skip to content
This repository was archived by the owner on May 14, 2022. It is now read-only.

Commit b22f153

Browse files
committed
feat: add gorpc
1 parent b205ed3 commit b22f153

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

go.mod

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module github.com/getstackhead/pluginlib
22

33
go 1.17
44

5-
require github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
5+
require (
6+
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
7+
github.com/valyala/gorpc v0.0.0-20160519171614-908281bef774
8+
)

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM=
22
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII=
3+
github.com/valyala/gorpc v0.0.0-20160519171614-908281bef774 h1:SUHFQHAaySqF0YHCmmm0EIFooFZpDPpi5KTom7YJ07c=
4+
github.com/valyala/gorpc v0.0.0-20160519171614-908281bef774/go.mod h1:8uNqM1i7pr0jO7gdvbNCgsSa8Ki2vMh7JCQxO9BlF90=

install.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ type PackageName struct {
44
ApkPackageName string
55
}
66

7-
func InstallPackage(packageName PackageName) <-chan error {
8-
return StackHeadMain.Execute(IntCmdInstallPkgApk, packageName.ApkPackageName)
7+
func InstallPackage(packageName PackageName) error {
8+
return ExecCmd(IntCmdInstallPkgApk, packageName.ApkPackageName)
99
}
1010

11-
func UninstallPackage(packageName PackageName) <-chan error {
12-
return StackHeadMain.Execute(IntCmdUninstallPkgApk, packageName.ApkPackageName)
11+
func UninstallPackage(packageName PackageName) error {
12+
return ExecCmd(IntCmdUninstallPkgApk, packageName.ApkPackageName)
1313
}

stackhead.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package pluginlib
22

3-
type IStackHeadMain interface {
4-
Execute(command string, args ...interface{}) <-chan error
5-
}
3+
import "github.com/valyala/gorpc"
64

75
const (
86
IntCmdInstallPkgApk string = "stackhead:install:package:apk"
97
IntCmdUninstallPkgApk string = "stackhead:uninstall:package:apk"
108
)
119

12-
var StackHeadMain IStackHeadMain = nil
10+
func ExecCmd(command string, args ...interface{}) error {
11+
c := &gorpc.Client{Addr: "localhost:1412"}
12+
c.Start()
13+
defer c.Stop()
14+
// All client methods issuing RPCs are thread-safe and goroutine-safe,
15+
// i.e. it is safe to call them from multiple concurrently running goroutines.
16+
_, err := c.Call(command, args...)
17+
return err
18+
}

0 commit comments

Comments
 (0)