Skip to content

Latest commit

 

History

History

01-hello-world

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Hello World Example

Tags: Models

Description

Simple service serving a message to the world.

Prerequisite

  • Download and install Go
  • Install NATS Server and Resgate (done with 3 docker commands).

Install and run

git clone https://github.com/jirenius/go-res
cd go-res/examples/01-hello-world
go run .

Things to try out

Access API through HTTP

  • Open the browser and go to:
    http://localhost:8080/api/example/model
    

Access API through WebSocket

  • Open Chrome and go to resgate.io - resource viewer.
  • Type in the resource ID below, and click View:
    example.model
    

    Note

    Chrome allows websites to connect to localhost, while other browsers may give a security error.

Real time update on static resource

  • Stop the project, and change the "Hello, World!" message in main.go.
  • Restart the project and observe how the message is updated in the viewer (see above).

Get resource with ResClient

  • In the resgate.io - resource viewer, open the DevTools console (Ctrl+Shift+J).
  • Type the following command, and press Enter:
    client.get("example.model").then(m => console.log(m.message));

    Note

    The resource viewer app stores the ResClient instance in the global client variable, for easy access.