RUI library
The RUI (Remote User Interface) library is designed to create web applications in the go language.
The peculiarity of the library is that all data processing is carried out on the server,and the browser is used as a thin client. WebSocket is used for client-server communication.
Hello world
type helloWorldSession struct { } func (content *helloWorldSession) CreateRootView(session rui.Session) rui.View { return rui.NewTextView(session, rui.Params { rui.Text : "Hello world!!!", }) } func createHelloWorldSession(session rui.Session) rui.SessionContent { return new(helloWorldSession) } func main() { rui.StartApp("localhost:8000", createHelloWorldSession, rui.AppParams{ Title: "Hello world", Icon: "icon.svg", }) }
In the main function, the StartApp function is called. It creates a rui app and runs its main loop.The StartApp function has 3 parameters:1) IP address where the application will be available (in our example it is "localhost:8000")2) The function creates a structure that implements the SessionContent interface3) Additional optional parameters (in our example, this is the title and the icon file name)
The SessionContent interface is declared as:
type SessionContent interface { CreateRootView(session rui.Session) rui.View }
A new instance of the helloWorldSession structure is created for each new session,
The CreateRootView function of the SessionContent interface creates a root element.When the user accesses the application by typing the address "localhost: 8000" in the browser, a new session is created.A new instance of the helloWorldSession structure is created for it, and at the end the CreateRootView function is called.The createRootView function returns a representation of a text that is created using the NewTextView function.
If you want the application to be visible outside your computer, then change the address in the Start function:
rui.StartApp(rui.GetLocalIP() + ":80", ...