Пример #1
0
func main() {
	// This runs this binary as an Otto plugin. No other machinery is needed
	// to make the plugin work!
	plugin.Serve(&plugin.ServeOpts{
		AppFunc: AppFactory,
	})
}
Пример #2
0
func TestPluginProcess(*testing.T) {
	// Find where our arguments start based on "--"
	args := os.Args
	for len(args) > 0 {
		if args[0] == "--" {
			args = args[1:]
			break
		}

		args = args[1:]
	}
	if len(args) < 1 {
		return
	}
	if args[0] != TestPluginProcessMagicCookie {
		return
	}

	// We know we're in a requested plugin process, we want to completely
	// exit at the end of this so let's defer that.
	defer os.Exit(0)

	// Determine what plugin we're supposed to be serving
	var opts plugin.ServeOpts
	switch args[1] {
	case "empty":
		appImpl := &app.Mock{}
		opts.AppFunc = func() app.App {
			return appImpl
		}
	case "mock":
		appImpl := &app.Mock{
			MetaResult: testPluginMockMeta,
		}
		opts.AppFunc = func() app.App {
			return appImpl
		}
	default:
		fmt.Fprintf(os.Stderr, "Invalid plugin: %s\n", args[1])
		os.Exit(2)
	}

	// Serve the plugin!
	plugin.Serve(&opts)
}