Skip to content

Commit

Permalink
Add rudimentary backend and frontend services
Browse files Browse the repository at this point in the history
  • Loading branch information
joakiboxxx committed Oct 11, 2018
0 parents commit 83d133c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
15 changes: 15 additions & 0 deletions back/back.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"fmt"
"log"
"net/http"
)

func main() {
http.HandleFunc("/ok", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "ok")
})

log.Fatal(http.ListenAndServe(":8080", nil))
}
33 changes: 33 additions & 0 deletions front/front.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"fmt"
"io/ioutil"
"log"
"net/http"
)

func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if isbackendok() {
fmt.Fprintln(w, "Backend is OK.")
} else {
fmt.Fprintln(w, "Backend is NOT OK.")
}
})

log.Fatal(http.ListenAndServe(":8000", nil))
}

func isbackendok() bool {
r, err := http.Get("http://localhost:8080/ok")
if err == nil && r.StatusCode == 200 {
data, err := ioutil.ReadAll(r.Body)
r.Body.Close()
if err == nil && string(data) == "ok" {
return true
}
return false
}
return false
}

0 comments on commit 83d133c

Please sign in to comment.