Pierwszy szkielet serwera

This commit is contained in:
Marcel Grześ 2018-11-18 08:52:24 +00:00
parent d7839aadba
commit 880b93b93f

31
index.go Normal file
View File

@ -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)
}