Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dearplain/goloader
load and run golang code at runtime. (WARNING: this repo has not been maintained for a long time, please take a look at https://github.com/pkujhd/goloader)
https://github.com/dearplain/goloader
dynamic go golang hot-reload plugin script
Last synced: 3 months ago
JSON representation
load and run golang code at runtime. (WARNING: this repo has not been maintained for a long time, please take a look at https://github.com/pkujhd/goloader)
- Host: GitHub
- URL: https://github.com/dearplain/goloader
- Owner: dearplain
- License: apache-2.0
- Created: 2018-02-28T16:07:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-15T08:30:38.000Z (almost 5 years ago)
- Last Synced: 2024-06-18T20:19:21.229Z (5 months ago)
- Topics: dynamic, go, golang, hot-reload, plugin, script
- Language: Go
- Homepage:
- Size: 49.8 KB
- Stars: 620
- Watchers: 34
- Forks: 64
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Goloader
[![Build Status](https://travis-ci.org/dearplain/goloader.svg?branch=master)](https://travis-ci.org/dearplain/goloader)
Goloader can load and run Golang code at runtime.
## How does it work?
Goloader works like a linker: it relocates the address of symbols in an object file, generates runnable code, and then reuses the runtime function and the type pointer of the loader.
Goloader provides some information to the runtime and gc of Go, which allows it to work correctly with them.
Please note that Goloader is not a scripting engine. It reads the output of Go compiler and makes them runnable. All features of Go are supported, and run just as fast and lightweight as native Go code.
## Comparison with plugin
Goloader reuses the Go runtime, which makes it much smaller. And code loaded by Goloader is unloadable.
Goloader is debuggable, and supports pprof tool(Yes, you can see code loaded by Goloader in pprof).
## Build
**Make sure you're using go >= 1.8.**
First, execute the following command, then do build and test. This is because Goloader relies on the internal package, which is forbidden by the Go compiler.
```
cp -r $GOROOT/src/cmd/internal $GOROOT/src/cmd/objfile
```## Examples
```
go build github.com/dearplain/goloader/examples/loadergo tool compile $GOPATH/src/github.com/dearplain/goloader/examples/schedule/schedule.go
./loader -o schedule.o -run main.main -times 10go tool compile $GOPATH/src/github.com/dearplain/goloader/examples/base/base.go
./loader -o base.o -run main.maingo tool compile $GOPATH/src/github.com/dearplain/goloader/examples/http/http.go
./loader -o http.o -run main.main#build multiple go files
go tool compile -I $GOPATH/pkg/darwin_amd64 1.go 2.go#build for arm32
GOOS=linux GOARCH=arm GOARM=5 go install fmt runtime sync net/http time
GOOS=linux GOARCH=arm GOARM=5 go build github.com/dearplain/goloader/examples/loader
GOOS=linux GOARCH=arm GOARM=5 go tool compile $GOPATH/src/github.com/dearplain/goloader/examples/base/base.go
#test on arm32 linux
./loader -o base.o -run main.main
```## Warning
This has currently only been tested and developed on Golang 1.8, 1.9, and 1.10 (x64/x86, darwin, linux, windows).
Be aware of Golang's internal structs change, especially the moduledata struct.