예제 #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)))

}