Server-Client

Step by step Hello World

  1. Create main.go:
package main

import (
	"github.com/VoileLab/toolgui/toolgui/tgcomp"
	"github.com/VoileLab/toolgui/toolgui/tgexec"
	"github.com/VoileLab/toolgui/toolgui/tgframe"
)

func main() {
	app := tgframe.NewApp()
	app.AddPage("index", "Index", func(p *tgframe.Params) error {
		tgcomp.Text(p.Main, "Hello world")
		return nil
	})

	tgexec.NewWebExecutor(app).StartService(":3001")
}
  1. Create go.mod and download toolgui:
go mod init toolgui-helloworld
go mod tidy
  1. Run helloworld
go run main.go

Explain

  • Create a ToolGUI App: The App intance include the info that app needs.
app := tgframe.NewApp()
  • Register a page in App: Tell App instance, we will have a page in the App.
    • index is the name.
    • Index is the title.
app.AddPage("index", "Index", ...)
  • The Page Func: Draw a text component in the Main container.
func(p *tgframe.Params) error {
	tgcomp.Text(p.Main, "Hello world")
	return nil
}
  • WebExecuter: The App only includes the logic of app, but not includes GUI. The we executer provide web server GUI interface for App.
tgexec.NewWebExecutor(app).StartService(":3001")