All Projects → edwingeng → hotswap

edwingeng / hotswap

Licence: BSD-3-Clause License
Hotswap provides a solution for reloading your go code without restarting your server, interrupting or blocking any ongoing procedure.

Programming Languages

go
31211 projects - #10 most used programming language
Smarty
1635 projects
shell
77523 projects

Projects that are alternatives of or similar to hotswap

minimal-hapi-react-webpack
Minimal Hapi + React + Webpack + HMR (hot module reloading) Sandbox
Stars: ✭ 55 (-22.54%)
Mutual labels:  hot-reload
tomaat
🍅 Slack integrated pomodoro timer... with Electron + ClojureScript!
Stars: ✭ 61 (-14.08%)
Mutual labels:  hot-reload
LightCycle
React + Redux + TypeScript + Webpack + HotReload Boilerplate
Stars: ✭ 16 (-77.46%)
Mutual labels:  hot-reload
liteflow
Small but powerful rules engine,轻量强大优雅的规则引擎
Stars: ✭ 1,119 (+1476.06%)
Mutual labels:  hot-reload
active reloader rb
Rails gem that reloads browser as soon as any file is changed
Stars: ✭ 11 (-84.51%)
Mutual labels:  hot-reload
arel
Lightweight browser hot reload for Python ASGI web apps
Stars: ✭ 69 (-2.82%)
Mutual labels:  hot-reload
halogen-parcel-hot-reload-demo
An example of one way you could use hot reloading with Halogen.
Stars: ✭ 17 (-76.06%)
Mutual labels:  hot-reload
react-ssr-spa
Server side rendered single page app using reactjs official libraries.
Stars: ✭ 30 (-57.75%)
Mutual labels:  hot-reload
flhooks
React like Hooks implementation for Flutter.
Stars: ✭ 38 (-46.48%)
Mutual labels:  hot-reload
amd-cmd-hot-update-hmr
esl-hot-update: Hot update esl modules(AMD、CMD) when modifed. JS, LESS, tpl, component is all supported!
Stars: ✭ 25 (-64.79%)
Mutual labels:  hot-reload
flutterOnExistApp
现有iOS工程中引入flutter, 支持插件扩展(见multiflutter分支) 解决官方内存泄漏问题,master分支最新的engine修复版
Stars: ✭ 62 (-12.68%)
Mutual labels:  hot-reload
systemjs-tools
(dev)tools for working with SystemJS
Stars: ✭ 41 (-42.25%)
Mutual labels:  hot-reload
molecule
⚛️ –  – ⚛️ Boilerplate for cross platform web/native react apps with electron.
Stars: ✭ 95 (+33.8%)
Mutual labels:  hot-reload
easywebpack-vue
Vue Webpack Building Solution, Support Vue Server Side Render (SSR), Client Side Render (CSR) Building
Stars: ✭ 29 (-59.15%)
Mutual labels:  hot-reload
keyswitch-kicad-library
Footprints for popular keyboard switches
Stars: ✭ 163 (+129.58%)
Mutual labels:  hotswap
idle
Idle is an asynchronous and hot-reloadable C++ dynamic component framework
Stars: ✭ 169 (+138.03%)
Mutual labels:  hot-reload
PureScript
A C# hot reload framework for Unity3D, based on Mono's MONO_AOT_MODE_INTERP mode.
Stars: ✭ 258 (+263.38%)
Mutual labels:  hot-reload
flutter dynamic
The flutter_dynamic is a library that create flutter application dynamic.
Stars: ✭ 66 (-7.04%)
Mutual labels:  hot-reload
React-bookstore
Bookstore using google-book Apis made with reactjs🔥🚀
Stars: ✭ 14 (-80.28%)
Mutual labels:  hot-reload
rbfx
Game engine with (optional) C# support and WYSIWYG editor.
Stars: ✭ 511 (+619.72%)
Mutual labels:  hot-reload

Banner

简体中文版

Hotswap provides a solution for reloading your go code without restarting your server, interrupting or blocking any ongoing procedure. Hotswap is built upon the plugin mechanism.

Major Features

  • Reload your code like a breeze
  • Run different versions of a plugin in complete isolation
  • Invoke an in-plugin function from its host program with Plugin.InvokeFunc()
  • Expose in-plugin data and functions with PluginManager.Vault.DataBag and/or PluginManager.Vault.Extension
  • Handle asynchronous jobs using the latest code with live function, live type, and live data
  • Link plugins statically for easy debugging
  • Expose functions to other plugins with Export()
  • Depend on other plugins with Import()

Getting Started

go install github.com/edwingeng/hotswap/cli/hotswap

Build a Plugin from Source Code

Usage:
  hotswap build [flags] <pluginDir> <outputDir> -- [buildFlags]

Examples:
hotswap build plugin/foo bin
hotswap build -v plugin/foo bin -- -race
hotswap build --staticLinking plugin/foo pluginHost

Flags:
      --debug               enable the debug mode
      --exclude string      go-regexp matching files to exclude from included
      --goBuild             if --goBuild=false, skip the go build procedure (default true)
  -h, --help                help for build
      --include string      go-regexp matching files to include in addition to .go files
      --leaveTemps          do not delete temporary files
      --prefixLive string   the case-insensitive name prefix of live functions/types (default "live_")
      --staticLinking       generate code for static linking instead of building a plugin
  -v, --verbose             enable the verbose mode

Demos

You can find these examples under the demo directory. To have a direct experience, start a server with run.sh and reload its plugin(s) with reload.sh.

  1. hello demonstrates the basic usage, including how to organize host and plugin, how to build them, how to load plugin on server startup, how to use InvokeEach, and how to reload.
  2. extension shows how to define a custom extension and how to use PluginManager.Vault.Extension. A small hint: WithExtensionNewer()
  3. livex is somewhat complex. It shows how to work with live function, live type, and live data.
  4. slink is an example of plugin static-linking, with which debugging a plugin with a debugger (delve) under MacOS and Windows becomes possible.
  5. trine is the last example. It demonstrates the plugin dependency mechanism.

Required Functions

A plugin must have the following functions defined in its root package.

// OnLoad gets called after all plugins are successfully loaded and all dependencies are
// properly initialized.
func OnLoad(data interface{}) error {
    return nil
}

// OnInit gets called after the execution of all OnLoad functions.
func OnInit(sharedVault *vault.Vault) error {
    return nil
}

// OnFree gets called at some time after a reload.
func OnFree() {
}

// Export returns an object to be exported to other plugins.
func Export() interface{} {
    return nil
}

// Import returns an object indicating the dependencies of the plugin.
func Import() interface{} {
    return nil
}

// InvokeFunc invokes the specified function.
func InvokeFunc(name string, params ...interface{}) (interface{}, error) {
    return nil, nil
}

// Reloadable indicates whether the plugin is reloadable.
func Reloadable() bool {
    return true
}

Order of Execution during Plugin Reload

1. Reloadable
2. Export
3. Import
4. OnLoad
5. OnInit

Attentions

  • Build your host program with the environmental variable CGO_ENABLED=1 and the -trimpath flag.
  • Do not define any global variable in a reloadable plugin unless it can be discarded at any time or it actually never changes.
  • Do not create any long-running goroutine in a plugin.
  • The same type in different versions of a plugin are actually not the same at runtime. Use live function, live type, and live data to avoid the trap.
  • The code of your host program should never import any package of any plugin and the code of a plugin should never import any package of other plugins.
  • Old versions won't be removed from the memory due to the limitation of golang plugin. However, Hotswap offers you a chance, the OnFree function, to clear caches.
  • It is required to manage your code with git.
  • It is highly recommended to keep the code of your host program and all its plugins in a same repository.

Live Things

  • live function is a type of function whose name is prefixed with live_ (case-insensitive). Live functions are automatically collected and stored in PluginManager.Vault.LiveFuncs. For example:
func live_Foo(jobData live.Data) error {
      return nil
}
  • live type is a type of struct whose name is prefixed with live_ (case-insensitive). Live types are automatically collected and stored in PluginManager.Vault.LiveTypes. For example:
type Live_Bar struct {
      N int
}
  • live data is a type guardian. Convert your data into a live data object when scheduling an asynchronous job and restore your data from the live data object when handling the job.
  • See the demo livex for details.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].