diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index d34daa0..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "go.buildFlags": ["-tags=linux"], -} \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 8efc85e..0000000 --- a/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -REPO_NAME=go-loader-test -REPO_LINK=https://git.aliberksandikci.com.tr/asandikci/${REPO_NAME} - -DATA_DIR=/etc/go-loader-test/ -LIB_DIR=/usr/share/go-loader-test/ -PLUGIN_DIR=${LIB_DIR}/plugins/ -TEMP_DIR=$(mktemp -d) -MAIN_DIR=${TEMP_DIR}/${REPO_NAME}/ - - -install: - sudo go build -o ${DESTDIR}/usr/bin/${REPO_NAME} ./cmd/go-loader-test/ - @sudo mkdir -p "${DESTDIR}/${LIB_DIR}" - @sudo mkdir -p "${DESTDIR}/${PLUGIN_DIR}" - - sudo go build -buildmode=plugin -o ${DESTDIR}/${PLUGIN_DIR}/tmptest.so ./plugins/tmptest - @sudo mkdir -p "${DESTDIR}/${DATA_DIR}" - -windows_install: - sudo env GOOS=windows GOARCH=amd64 go build -o ${DESTDIR}/usr/bin/${REPO_NAME} ./cmd/go-loader-test/ - @sudo mkdir -p "${DESTDIR}/${LIB_DIR}" - @sudo mkdir -p "${DESTDIR}/${PLUGIN_DIR}" - - sudo GOOS=windows GOARCH=amd64 go build -buildmode=plugin -o ${DESTDIR}/${PLUGIN_DIR}/tmptest.so ./plugins/tmptest - @sudo mkdir -p "${DESTDIR}/${DATA_DIR}" -uninstall: - @sudo rm -rf ${DESTDIR}/usr/bin/${REPO_NAME} diff --git a/README.md b/README.md index a8725e0..c24e2ec 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ -tests for https://github.com/pkujhd/goloader and https://github.com/eh-steve/goloader. -contains some parts from https://git.aliberksandikci.com.tr/Liderahenk/ahenk-go \ No newline at end of file +- test for plugin and goloader logics +- contains some parts from https://git.aliberksandikci.com.tr/Liderahenk/ahenk-go + +- official plugin logic: https://pkg.go.dev/plugin - [branch](https://git.aliberksandikci.com.tr/asandikci/go-loader-test/src/branch/original-plugin) +- goloader plugin logic: https://github.com/eh-steve/goloader - [branch](https://git.aliberksandikci.com.tr/asandikci/go-loader-test/src/branch/eh-steve/goloader) +- goloader plugin logic + [crosscompile](git.aliberksandikci.com.tr/asandikci/go-crosscompile) - [branch](https://git.aliberksandikci.com.tr/asandikci/go-loader-test/src/branch/eh-steve/goloader+crosscompile) + +- see [branches](https://git.aliberksandikci.com.tr/asandikci/go-loader-test/branches) for more diff --git a/cmd/go-loader-test/main.go b/cmd/go-loader-test/main.go deleted file mode 100644 index 905cc5e..0000000 --- a/cmd/go-loader-test/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "log" - "os" -) - -const ExecutablePath = "/usr/bin/go-loader-test" -const DataDir = "/etc/go-loader-test/" -const LogFile = DataDir + "go-loader-test" -const LibDir = "/usr/share/go-loader-test/" -const PluginDir = LibDir + "/plugins/" - -// Main Function that starts daemon and controls arguments -func main() { - if len(os.Args) == 2 && os.Args[1] == "tmptest" { - log.Print("TEMPORARY TEST STARTED, log files are NOT redirecting!") - PluginManager("tmptest") - } else { - panic("Please enter a valid option !") - } -} diff --git a/cmd/go-loader-test/plugin-manager.go b/cmd/go-loader-test/plugin-manager.go deleted file mode 100644 index 67491d6..0000000 --- a/cmd/go-loader-test/plugin-manager.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/eh-steve/goloader/jit" -) - -func PluginManager(params ...string) { - conf := jit.BuildConfig{ - KeepTempFiles: false, // Files are copied/written to a temp dir to ensure it is writable. This retains the temporary copies - ExtraBuildFlags: []string{"-x"}, // Flags passed to go build command - BuildEnv: []string{"GOOS=windows"}, // Env vars to set for go build toolchain - TmpDir: "/tmp/inner", // To control where temporary files are copied - DebugLog: true, // - } - - loadable, err := jit.BuildGoPackage(conf, "plugins/tmptest/") - if err != nil { - panic(err) - } - - module, err := loadable.Load() - // module.SymbolsByPkg is a map[string]map[string]interface{} of all packages and their exported functions and global vars - symbols := module.SymbolsByPkg[loadable.ImportPath] - if err != nil { - panic(err) - } - // defer func() { - // err = module.Unload() - // if err != nil { - // panic(err) - // } - // }() - switch f := symbols["MyFunc"].(type) { - case func([]byte) (interface{}, error): - result, err := f([]byte(`{"k":"v"}`)) - if err != nil { - panic(err) - } - fmt.Println(result) - default: - fmt.Println(f) - panic("Function signature was not what was expected") - } - - err = module.Unload() - if err != nil { - panic(err) - } -} diff --git a/cmd/go-loader-test/plugin-opener.go b/cmd/go-loader-test/plugin-opener.go deleted file mode 100644 index 7a88095..0000000 --- a/cmd/go-loader-test/plugin-opener.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "fmt" - "os" - "plugin" - - "git.aliberksandikci.com.tr/asandikci/go-loader-test/pkg/utils" -) - -func LoadPlugin(plugName string, chn chan interface{}) { - - plug, err := plugin.Open(PluginDir + plugName + ".so") - utils.Check(err) - - symPlug, err := plug.Lookup(utils.FirstUpperEN(plugName) + "Connect") - utils.Check(err) - - var plugOut interface{} - plugOut, ok := symPlug.(interface{}) - if !ok { - fmt.Println("unexpected type from module symbol") - os.Exit(1) - } - chn <- plugOut -} diff --git a/go.mod b/go.mod deleted file mode 100644 index 16ac1d6..0000000 --- a/go.mod +++ /dev/null @@ -1,10 +0,0 @@ -module git.aliberksandikci.com.tr/asandikci/go-loader-test - -go 1.21.0 - -require ( - github.com/eh-steve/goloader/jit v0.0.0-20230731163325-b789213e8550 - golang.org/x/text v0.12.0 -) - -require github.com/eh-steve/goloader v0.0.0-20230730231803-5c95d7a5f4e2 // indirect diff --git a/go.sum b/go.sum deleted file mode 100644 index 730d78c..0000000 --- a/go.sum +++ /dev/null @@ -1,6 +0,0 @@ -github.com/eh-steve/goloader v0.0.0-20230730231803-5c95d7a5f4e2 h1:0mZ2Y8x4dhPfm9eOlbzBx31YSLaECdPvKEBrL5Hc0YE= -github.com/eh-steve/goloader v0.0.0-20230730231803-5c95d7a5f4e2/go.mod h1:k7xs3CUwCvOU9aw851I6AEb6ZzZJ3nos5dZ6A/2ewM0= -github.com/eh-steve/goloader/jit v0.0.0-20230731163325-b789213e8550 h1:clY7T47fFZdFcILcu7uksS7FStRaKMssCYGW0l/AoMo= -github.com/eh-steve/goloader/jit v0.0.0-20230731163325-b789213e8550/go.mod h1:p18VKcPYO8oWGYcQt/K5EGIGqak0ZT5HwVirGpUGZBg= -golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= -golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= diff --git a/pkg/utils/main.go b/pkg/utils/main.go deleted file mode 100644 index 165e144..0000000 --- a/pkg/utils/main.go +++ /dev/null @@ -1,69 +0,0 @@ -package utils - -import ( - "log" - "os" - - "golang.org/x/text/cases" - "golang.org/x/text/language" -) - -func Byte2String(arr []int8) string { - b := make([]byte, len(arr)) - for i, v := range arr { - b[i] = byte(v) - } - return string(b) -} - -func Byte2MiB(b uint64) float64 { - return float64(float64(b) / (1024 * 1024)) -} - -func Byte2GiB(b uint64) float64 { - return float64(float64(b) / (1024 * 1024 * 1024)) -} - -func MB2GiB(b uint64) float64 { - return float64(float64(b*1000*1000) / (1024 * 1024 * 1024)) -} - -func CheckPath(path string) (bool, error) { - _, err := os.Stat(path) - if err == nil { - return true, nil - } - if os.IsNotExist(err) { - return false, nil - } - return false, err -} - -func CreatePath(path string) { - if flag, err := CheckPath(path); flag { - if err != nil { - log.Fatal(err) - } - } else if err := os.Mkdir(path, os.ModePerm); err != nil { - log.Fatal(err) - } -} - -func Check(err error) { - if err != nil { - panic(err) - } -} - -func OpenLogFile(path string) *os.File { - f, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) - if err != nil { - panic(err) - } - return f -} - -// Makes first character uppercase of given English string -func FirstUpperEN(str string) string { - return cases.Title(language.English).String(str) -} // TODO cases.NoLower vs cases.Compact ! diff --git a/plugins/tmptest/info.go b/plugins/tmptest/info.go deleted file mode 100644 index 305a2cb..0000000 --- a/plugins/tmptest/info.go +++ /dev/null @@ -1,11 +0,0 @@ -package mypackage - -func Info() map[string]interface{} { - return map[string]interface{}{ - "name": "tmptest", - "version": "1.0.2", - "support": "any", - "description": "Temporary testing", - "developer": "asandikci@aliberksandikci.com.tr", - } -} diff --git a/plugins/tmptest/main.go b/plugins/tmptest/main.go deleted file mode 100644 index fd55a51..0000000 --- a/plugins/tmptest/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package mypackage - -import "encoding/json" - -func MyFunc(input []byte) (interface{}, error) { - var output interface{} - err := json.Unmarshal(input, &output) - return output, err -}