package main
import (
"fmt"
"html/template"
"log"
"net/http"
//"strings"
)
func opisStołówkaZPM(w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles("StronaGlowna.tmpl")
t.Execute(w, nil)
//r.ParseForm()
//fmt.Println(r.Form)
//fmt.Println("path", r.URL.Path)
//fmt.Println("scheme", r.URL.Scheme)
//fmt.Println(r.Form["url_long"])
//for k, v := range r.Form {
// fmt.Println("key:", k)
// fmt.Println("val:", strings.Join(v, ""))
//}
}
func panel(w http.ResponseWriter, r *http.Request) {
fmt.Println("method:", r.Method)
t, _ := template.ParseFiles("panel.gtpl")
t.Execute(w, nil)
}
func login(w http.ResponseWriter, r *http.Request) {
fmt.Println("method:", r.Method)
if r.Method == "GET" {
t, _ := template.ParseFiles("login.gtpl")
t.Execute(w, nil)
} else {
r.ParseForm()
fmt.Println("username:", r.Form["username"])
fmt.Println("password:", r.Form["password"])
}
//if r.Method == "POST" {
// t, _ := template.ParseFiles("panel.gtpl")
// t.Execute(w, nil)
//}
username := r.Form["username"]
password := r.Form["password"]
zaloguj := "Wpisane wartości:"
if r.Method == "POST" {
if zaloguj != "" {
fmt.Fprintln(w, zaloguj)
fmt.Fprintln(w, username)
fmt.Fprintln(w, password)
}
}
}
func main() {
http.HandleFunc("/", opisStołówkaZPM)
http.HandleFunc("/login", login)
http.HandleFunc("/panel", panel)
err := http.ListenAndServe(":9197", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}