diff options
author | Emile <hanemile@protonmail.com> | 2019-03-24 14:51:50 +0100 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-03-24 14:51:50 +0100 |
commit | da201854e9f9f25bad1720d5368648d5bc49c480 (patch) | |
tree | da81375a4a47e35feaedb31b91b181f2a45ae1fc /http.go | |
parent | fd94a3102282effc9fbed8075063b97fe2c11ab6 (diff) |
Diffstat (limited to 'http.go')
-rw-r--r-- | http.go | 44 |
1 files changed, 44 insertions, 0 deletions
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 := ` +<html> + <head> + <title>Distributor Container</title> + </head> + <body> + <h1>Distributor</h1> + <p> + <a href="/distributor">Distributor</a> + </p> + </body> +</html>` + _, _ = 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) + +} |