Skip to content

Galactus-Player/roomservice

Repository files navigation

roomservice: a microservice for generating and assigning room codes

PkgGoDev

The roomservice microservice is used in the galactus video player to create random codes which users will join. This microservice creates random room codes, for example 1234, and that code will be shared with other users when they would like to join the same room. Once a user retrieves this code, they can use it to join a room and retrieve room information such as the videos currently in the queue, the information needed to join the room, and the people in the room.

Overview

This server was generated by the openapi-generator project. Clients for roomservice can be generated using api/openapi.yaml and an openapi compatible generator such as the openapi-generator-cli. There are a few endpoints which can be called from the server,server

Running the server

To run the server, follow these simple steps:

  1. docker stop postgres_host && docker run --name postgres_host --network pgnet -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres. To start the postgres server
  2. go run cmd/roomservice/main.go. To start room service

To run the server in a docker container first do step 1 from above and then

docker build --network=host -t openapi .

Once image is built use

docker run --rm --network pgnet -it openapi 

Using the golang client library to interact with roomservice

We have generated a client library so it is easy for golang applications to interact with roomservice. Once the server is started and running, the roomapi package can be used to get the proper types from the server call. Here is an example program which connects to a roomservice running on localhost:8080.

package main

import (
	"log"
	"context"
    "github.com/Galactus-Player/roomservice/roomapi"
)

const roomServiceHost string = "localhost:8080"

func main() {

	// create simple api configuration
	apiConfig := roomapi.NewConfiguration()
	apiConfig.Host = roomServiceHost

	// create first client with background context and call server
	apic := roomapi.NewAPIClient(apiConfig)
	background := context.Background()
	retRoom, _, err := apic.RoomApi.AddRoom(background)
	if err != nil {
		log.Fatalf("error adding room: %s\n", err)
		return
	}
	log.Printf("room id: %d, room id str: %s\n", retRoom.Id, retRoom.Code)
}

This example runs and is in cmd/exampleclient/. To run it, first run the server using the above commands. Then navigate to the root directory of the repository and run the following command:

go run cmd/exampleclient/main.go

The result should be something like:

rjected@nixos-dan-sff ~/P/roomservice (main)> go run cmd/exampleclient/main.go
2020/10/20 20:49:05 room id: 7261, room id str: 7261

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages