-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rudimentary backend and frontend services
- Loading branch information
0 parents
commit 83d133c
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |