Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
66 additions
and
19 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 |
---|---|---|
@@ -1 +1 @@ | ||
.otto | ||
.otto |
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,3 @@ | ||
default: | ||
(cd /opt/gopath && go install github.com/evillemez/grotto) | ||
|
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,18 @@ | ||
package handlers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
func Index(res http.ResponseWriter, req *http.Request) { | ||
fmt.Fprintf(res, "Index") | ||
} | ||
|
||
func Name(res http.ResponseWriter, req *http.Request) { | ||
fmt.Fprintf(res, "Name") | ||
} | ||
|
||
func Misc(res http.ResponseWriter, req *http.Request) { | ||
fmt.Fprintf(res, "Misc") | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
package main | ||
|
||
import "github.com/evillemez/grotto/hello" | ||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
func main() { | ||
foo() | ||
|
||
hello.SayHello() | ||
fmt.Println("Starting...") | ||
log.Fatal(http.ListenAndServe("127.0.0.1:8080", NewRouter())) | ||
fmt.Println("Exited.") | ||
} |
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,36 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"github.com/gorilla/mux" | ||
"github.com/evillemez/grotto/handlers" | ||
) | ||
|
||
type Route struct { | ||
Name string | ||
Method string | ||
Pattern string | ||
HandlerFunc http.HandlerFunc | ||
} | ||
|
||
type Routes []Route | ||
|
||
var routes = Routes { | ||
Route {"Index", "GET", "/", handlers.Index}, | ||
Route {"Name", "GET", "/name/{name}", handlers.Name}, | ||
Route {"Misc", "GET", "/misc", handlers.Misc}, | ||
} | ||
|
||
func NewRouter() *mux.Router { | ||
router := mux.NewRouter().StrictSlash(true) | ||
|
||
for _, route := range routes { | ||
router. | ||
Methods(route.Method). | ||
Path(route.Pattern). | ||
Name(route.Name). | ||
Handler(route.HandlerFunc) | ||
} | ||
|
||
return router | ||
} |