From da201854e9f9f25bad1720d5368648d5bc49c480 Mon Sep 17 00:00:00 2001 From: Emile Date: Sun, 24 Mar 2019 14:51:50 +0100 Subject: committing untracked files --- http.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 http.go (limited to 'http.go') diff --git a/http.go b/http.go new file mode 100644 index 0000000..91c75e3 --- /dev/null +++ b/http.go @@ -0,0 +1,44 @@ +package main + +import ( + "fmt" + "log" + "net/http" +) + +func indexHandler(w http.ResponseWriter, r *http.Request) { + responseString := ` + + + Distributor Container + + +

Distributor

+

+ Distributor +

+ +` + _, _ = fmt.Fprintf(w, responseString) +} + +func distributorHandler(w http.ResponseWriter, r *http.Request) { + log.Println("The distributorHandler was accessed") + + // if the starIdBufferChannel is not filled yet, fill it + if len(idBufferChannel) == 0 { + log.Println("The idBufferChannel is empty, fetching new stars") + fillStarIdBufferChannel() + } + + // get a single id from the idBufferChannel + log.Println("Getting an id from the idBufferChannel") + id := <-idBufferChannel + log.Println("Done...") + + // return the id using the http.ResponseWriter w + _, _ = fmt.Fprintf(w, "%d", id) + + log.Printf("Done providing a starID (%d) from the StarBufferHandler", id) + +} -- cgit 1.4.1