示例#1
0
func main() {
	plugins.RegisterRuntime(ottojs.GetRuntime())
	plugins.LoadString("happy", string(happy_js()), ottojs.GetRuntime())

	plugins.ExtensionPoint(&ProgramObserverExt)

	for _, observer := range ProgramObserverExt.Plugins() {
		observer.ProgramStarted()
	}

	fmt.Println("Hello World")

	for _, observer := range ProgramObserverExt.Plugins() {
		observer.ProgramEnded()
	}
}
示例#2
0
func main() {
	plugins.RegisterRuntime(ottojs.GetRuntime())
	plugins.LoadFromPath()

	plugins.ExtensionPoint(&ListProviderExt)

	fmt.Println("Here is a list, produced by plugins:")

	for _, provider := range ListProviderExt.Plugins() {
		for _, item := range provider.GetItems() {
			fmt.Println(" * " + item.(string))
		}
	}

}
示例#3
0
func main() {
	plugins.RegisterRuntime(ottojs.GetRuntime())
	plugins.LoadFromPath()

	plugins.ExtensionPoint(&TextFilterExt)

	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		line := scanner.Text()
		for _, filter := range TextFilterExt.Plugins() {
			line = filter.Filter(line)
		}
		fmt.Println(line)
	}

}
示例#4
0
func main() {
	plugins.RegisterRuntime(ottojs.GetRuntime())
	plugins.ExtensionPoint(&ProgramObserverExt)

	plugins.StaticPlugin(&MyStaticPlugin{}, []string{
		"ProgramObserver",
	})

	for _, observer := range ProgramObserverExt.Plugins() {
		observer.ProgramStarted()
	}

	fmt.Println("Hello World")

	for _, observer := range ProgramObserverExt.Plugins() {
		observer.ProgramEnded()
	}
}
示例#5
0
func main() {
	plugins.RegisterRuntime(ottojs.GetRuntime())
	plugins.LoadFromPath()
	plugins.SetGlobals(map[string]interface{}{
		"Foo.Bar.Baz": "Hello world",
		"Foo.Log": func(text string, n int) {
			fmt.Println(text)
			fmt.Println(n)
		},
		"Foo.Bar.Qux": 42,
	})

	plugins.ExtensionPoint(&GlobalsUserExt)

	for _, obj := range GlobalsUserExt.Plugins() {
		obj.UseGlobals()
	}

}
示例#6
0
func main() {
	plugins.RegisterRuntime(ottojs.GetRuntime())
	plugins.LoadFromPath()
	plugins.ExtensionPoint(&OutputRendererExt)

	flag.Parse()

	if flag.Arg(0) == "" {
		fmt.Println("usage: matching <pattern>\n")
		os.Exit(1)
	}

	for _, renderer := range OutputRendererExt.Plugins() {
		if renderer.Match(flag.Arg(0)) {
			fmt.Println(renderer.Output())
			return
		}
	}

}
示例#7
0
func main() {
	plugins.RegisterRuntime(ottojs.GetRuntime())
	plugins.LoadFromPath()

	plugins.ExtensionPoint(&PluggableBackendExt)

	flag.Parse()

	if flag.Arg(0) == "" {
		fmt.Println("usage: backends <backend> <arg1> <arg2>\n")
		fmt.Println("available backends:")
		for _, backend := range PluggableBackendExt.Plugins() {
			fmt.Println("  " + backend.Name())
		}
		fmt.Println("")
		os.Exit(1)
	}

	backend := PluggableBackendExt.Plugin(flag.Arg(0))
	fmt.Println(backend.Process(flag.Arg(1), flag.Arg(2)))

}