Getting Plugged in with Go 1.8 Plugins @ GopherCon India
Go 1.8 will include a plugin package that allows you to define plugins that can be loaded at runtime. This talk will cover plugins in detail, discuss some use cases, and best practices for using the package.
2/25/2017 Go 1.8 Plugins http://localhost:3999/go-1.8-plugins.slide#1 3/20 Go 1.5 Go 1.5 introduced shared libraries using the -buildmode=shared option. // filename: calc.go package calc func Sum(x, y int) int { return x + y }
2/25/2017 Go 1.8 Plugins http://localhost:3999/go-1.8-plugins.slide#1 4/20 Go shared libraries First you need to build Go stdlib as a shared library $ go install -buildmode=shared -linkshared std Build the shared library calc$ go install -buildmode=shared -linkshared calc
2/25/2017 Go 1.8 Plugins http://localhost:3999/go-1.8-plugins.slide#1 6/20 Go shared libraries Good for distributing binary code as a re-usable library Still need to link at compile time
2/25/2017 Go 1.8 Plugins http://localhost:3999/go-1.8-plugins.slide#1 7/20 Go 1.8 New plugin package New -buildmode=plugin Load shared code at runtime!
2/25/2017 Go 1.8 Plugins http://localhost:3999/go-1.8-plugins.slide#1 9/20 Go Plugins Write a main package without main() func package main import "fmt" var V int func F() { fmt.Printf("Hello, number %d\n", V) }
2/25/2017 Go 1.8 Plugins http://localhost:3999/go-1.8-plugins.slide#1 14/20 Pros/Cons Pro: Easy loading at runtime Pro: Single process to maintain/monitor Con: Can't unload plugin, no hot reloading Con: It's new
2/25/2017 Go 1.8 Plugins http://localhost:3999/go-1.8-plugins.slide#1 18/20 Wrapping Up Moral of the Story: Testing is contribution! Provide ways for your users to extend Know the tradeoffs
2/25/2017 Go 1.8 Plugins http://localhost:3999/go-1.8-plugins.slide#1 19/20 Thank you Ian Lewis Gopher/Kubernaut@Google (mailto:Gopher/Kubernaut@Google) @IanMLewis (http://twitter.com/IanMLewis) [email protected] (mailto:[email protected])