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

Commit

Permalink
feat: add gorpc
Browse files Browse the repository at this point in the history
  • Loading branch information
saitho committed Sep 26, 2021
1 parent b205ed3 commit b22f153
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/getstackhead/pluginlib

go 1.17

require github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
require (
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
github.com/valyala/gorpc v0.0.0-20160519171614-908281bef774
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM=
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII=
github.com/valyala/gorpc v0.0.0-20160519171614-908281bef774 h1:SUHFQHAaySqF0YHCmmm0EIFooFZpDPpi5KTom7YJ07c=
github.com/valyala/gorpc v0.0.0-20160519171614-908281bef774/go.mod h1:8uNqM1i7pr0jO7gdvbNCgsSa8Ki2vMh7JCQxO9BlF90=
8 changes: 4 additions & 4 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ type PackageName struct {
ApkPackageName string
}

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

func UninstallPackage(packageName PackageName) <-chan error {
return StackHeadMain.Execute(IntCmdUninstallPkgApk, packageName.ApkPackageName)
func UninstallPackage(packageName PackageName) error {
return ExecCmd(IntCmdUninstallPkgApk, packageName.ApkPackageName)
}
14 changes: 10 additions & 4 deletions stackhead.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package pluginlib

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

const (
IntCmdInstallPkgApk string = "stackhead:install:package:apk"
IntCmdUninstallPkgApk string = "stackhead:uninstall:package:apk"
)

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

0 comments on commit b22f153

Please sign in to comment.