Commit 30fa85a
public/.keep
go.mod
@@ -1,3 +1,10 @@
module git.mokhan.ca/xlgmokha/oauth
go 1.18
+
+require (
+ github.com/davecgh/go-spew v1.1.0 // indirect
+ github.com/pmezard/go-difflib v1.0.0 // indirect
+ github.com/stretchr/testify v1.7.1 // indirect
+ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
+)
go.sum
@@ -0,0 +1,10 @@
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
+github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
main.go
@@ -0,0 +1,20 @@
+package main
+
+import (
+ "fmt"
+ "log"
+ "net/http"
+)
+
+func health(w http.ResponseWriter, req *http.Request) {
+ fmt.Fprintf(w, "OK")
+}
+
+func main() {
+ server := NewServer()
+
+ http.Handle("/", http.FileServer(http.Dir("public")))
+ http.HandleFunc("/api/", server.ServeHTTP)
+
+ log.Fatal(http.ListenAndServe(":8090", nil))
+}
server.go
@@ -0,0 +1,17 @@
+package main
+
+import (
+ "fmt"
+ "net/http"
+)
+
+type Server struct {
+}
+
+func NewServer() Server {
+ return Server{}
+}
+
+func (s Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ fmt.Fprintf(w, "OK")
+}
server_test.go
@@ -0,0 +1,22 @@
+package main
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestServer(t *testing.T) {
+ t.Run("GET /health", func(t *testing.T) {
+ response := httptest.NewRecorder()
+ request, _ := http.NewRequest("GET", "/health", nil)
+
+ server := NewServer()
+ server.ServeHTTP(response, request)
+
+ assert.Equal(t, http.StatusOK, response.Code)
+ assert.Equal(t, "OK", response.Body.String())
+ })
+}