memberlist

package
v0.0.0-...-f8f499d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2019 License: MIT Imports: 9 Imported by: 0

README

Cloud Functions As List Of Members Service

Using the Google Cloud Functions (Go 1.11.5 runtime), I have implemented a simple list of members service with Google Firestore.

After preparing the environment, we start setting some environment variables:

  • GCP_PROJECT=<project id>
  • GOOGLE_APPLICATION_CREDENTIALS=<json file>
  • GCP_REGION=<region>

We use Go modules for our dependencies, therefore, having the source files in place, we execute the following:

export GO111MODULE=on
go mod init && go mod vendor

Now, we can deploy our functions:

gcloud alpha functions deploy subscribe --region $GCP_REGION --entry-point Subscribe --runtime go111 --trigger-http
gcloud alpha functions deploy list --region $GCP_REGION --entry-point List --runtime go111 --trigger-http
gcloud alpha functions deploy unsubscribe --region $GCP_REGION --entry-point Unsubscribe --runtime go111 --trigger-http
gcloud alpha functions deploy reset --region $GCP_REGION --entry-point Reset --runtime go111 --trigger-http

Using the URL from the deployment, we test the functions:

curl <url>/subscribe <name> <ip> <port>
curl <url>/list
curl <url>/unsubscribe <id>
curl <url>/reset

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

func List(w http.ResponseWriter, r *http.Request)

List returns the list of members from Firestore

func Reset

func Reset(w http.ResponseWriter, r *http.Request)

Reset deletes all documents of the collection from Firestore

func Subscribe

func Subscribe(w http.ResponseWriter, r *http.Request)

Subscribe get information of the new member via http and stores it in Firestore

func Unsubscribe

func Unsubscribe(w http.ResponseWriter, r *http.Request)

Unsubscribe deletes the member specified by UUID in Firestore

Types

type IpAddress

type IpAddress struct {
	Name     string `firestore:"name,omitempty"`
	Ip       string `firestore:"ip,omitempty"`
	Port     string `firestore:"port,omitempty"`
	Protocol string `firestore:"protocol,omitempty"` // "tcp" or "udp"
}

IpAddress is the struct for the collection

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL