zaliczeniePP/main.go
2018-12-28 22:10:55 +01:00

69 lines
1.5 KiB
Go

package main
import (
"database/sql"
"fmt"
"html/template"
"log"
"net/http"
_ "github.com/mattn/go-sqlite3"
)
func opisStołówkaZPM(w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles("StronaGlowna.gtpl")
t.Execute(w, nil)
}
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) {
//Here:
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 len(r.Form["username"][0]) == 0 {
// goto Here
//}
//if len(r.Form["password"][0]) == 0 {
// goto Here
//}
}
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 init() {
sql.Register("sqlite3", &SQLiteDriver{})
}
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)
}
db, err := sql.Open("sqlite3", "./stolowka.db")
checkErr(err)
}