@@ -0,0 +1,13 @@ | |||
package main | |||
import ( | |||
"io" | |||
"net/http" | |||
_ "git.thevis.us/skepto/env" | |||
_ "git.thevis.us/skepto/rex" | |||
) | |||
func Index(w http.ResponseWriter, r *http.Request) { | |||
io.WriteString(w, "pehpeh-api") | |||
} |
@@ -5,4 +5,6 @@ go 1.14 | |||
require ( | |||
git.thevis.us/skepto/env v0.0.0-20200712040037-f8a5c3d1b0fa | |||
git.thevis.us/skepto/rex v0.10.0 | |||
github.com/gorilla/mux v1.7.4 | |||
github.com/stretchr/testify v1.2.2 | |||
) |
@@ -1,19 +1,29 @@ | |||
package main | |||
import ( | |||
"io" | |||
"net/http" | |||
"git.thevis.us/skepto/env" | |||
"git.thevis.us/skepto/rex" | |||
) | |||
type Server interface { | |||
Run() | |||
Get(pattern string, handler interface{}) | |||
ServeHTTP(w http.ResponseWriter, r *http.Request) | |||
} | |||
func main() { | |||
srv := Configure() | |||
srv.Run() | |||
} | |||
func Configure() Server { | |||
env.Set("PORT", 7777) | |||
app := rex.New() | |||
app.Get("/", func(w http.ResponseWriter, r *http.Request) { | |||
io.WriteString(w, "pehpeh-api") | |||
}) | |||
app.Run() | |||
server := rex.New() | |||
server.Get("/", Index) | |||
return server | |||
} |
@@ -0,0 +1,18 @@ | |||
package main | |||
import ( | |||
"net/http" | |||
"net/http/httptest" | |||
"testing" | |||
"github.com/stretchr/testify/assert" | |||
) | |||
func TestConfigure(t *testing.T) { | |||
srv := Configure() | |||
request, _ := http.NewRequest("GET", "/", nil) | |||
response := httptest.NewRecorder() | |||
srv.ServeHTTP(response, request) | |||
assert.Equal(t, "pehpeh-api", response.Body.String(), "response body is expected") | |||
assert.Equal(t, 200, response.Code, "OK response is expected") | |||
} |