A test project for experimenting the connection between a Go standard WASM module > Custom Load Balancer > Layer8 Slaves + DB > Content Server
- Go 1.11 or higher
- PostgreSQL 9.6 or higher
Note: Make sure to rungo mod tidy
before running the project for the first time and make a .env file with the following variables (You can change the values if you want and use your own local DB Name and Password):
LOAD_BALANCER_PORT=8000
LAYER8_SLAVE_ONE_PORT=8001
LAYER8_SLAVE_TWO_PORT=8002
LAYER8_SLAVE_THREE_PORT=8003
WASM_SERVER_PORT=9000
LAYER8_MASTER_PORT=9001
CONTENT_SERVER_PORT=9002
DB_USER=postgres
DB_PASS=
DB_NAME=
DB_HOST=localhost
DB_PORT=5432
SSL_MODE=disable
JWT_SECRET=secret
Open multiple terminals (7) and run the following commands in each:
make wasm
Note: For installing a specific version of go i.e., go 1.20.7, use the commands:
$ go install golang.org/dl/go1.20.7@latest
$ go1.20.7 download
$ go1.20.7 version
make load-balancer
make layer8-slave-one
make layer8-slave-two
make layer8-slave-three
make content-server
make layer8-master
Note: The make wasm
command will generate the WASM module and run a File Server on specified Port. The make load-balancer
will start a custom Load Balancer, that will serve as a proxy between WASM Module and Layer8 Slaves and distribute incoming requests equally. The make layer8-slave-one
& make layer8-slave-two
& make layer8-slave-three
will start 3 Layer8 Slaves, that have same functionality, but different ports. The make content-server
will start a Content Server, from which Layer8 Slaves will get the content and send it to the WASM module and the make layer8-master
will start a Layer8 Master, from where the Slaves will get the Secret Key for JWT.
Note: For first time running, you need to create a database and a table. You can do that with the following SQL Query:
CREATE TABLE IF NOT EXISTS public.users
(
id SERIAL PRIMARY KEY NOT NULL,
username character varying UNIQUE NOT NULL,
password character varying NOT NULL,
salt character varying(255),
public_key character varying(255)
);
Go to http://localhost:9000
and try Login and Register. The WASM module will send the request to the Layer8 server and the Layer8 server will send the request to the DB and return the response to the WASM module.