From 880b93b93f0eb46b1cff3f83455be45b62b90fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Grze=C5=9B?= Date: Sun, 18 Nov 2018 08:52:24 +0000 Subject: [PATCH] Pierwszy szkielet serwera --- index.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 index.go diff --git a/index.go b/index.go new file mode 100644 index 0000000..eb48e4d --- /dev/null +++ b/index.go @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "html" + "log" + "net/http" + + "github.com/gorilla/mux" +) + +func main() { + + muxRouter := mux.NewRouter().StrictSlash(true) + muxRouter.HandleFunc("/", index) + muxRouter.HandleFunc("/getfromdb", getAll) + muxRouter.HandleFunc("/getfromdb/{primaryKey}", getIndex) + log.Fatal(http.ListenAndServe(":8080", muxRouter)) +} + +func index(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) +} +func getAll(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Tutaj dostaniesz wyniki z bazy danych") +} +func getIndex(w http.ResponseWriter, r *http.Request) { + args := mux.Vars(r) + pk := args["primaryKey"] + fmt.Fprintf(w, "Tutaj bedzie wynik dla PK = %s", pk) +}