Update main.go

This commit is contained in:
s441433 2018-12-29 00:08:27 +01:00
parent 181a0c7a91
commit e5d902f5ae

41
main.go
View File

@ -10,9 +10,34 @@ import (
_ "github.com/mattn/go-sqlite3"
)
//***************************************************************************
//funkcje sterujące
//***************************************************************************
func opisStołówkaZPM(w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles("StronaGlowna.gtpl")
t.Execute(w, nil)
db, err := sql.Open("sqlite3", "stolowkaZPM.db")
checkErr(err)
// query
rows, err := db.Query("SELECT * FROM users")
checkErr(err)
var IDusers int64
var Username string
var Password string
var PIN int
for rows.Next() {
err = rows.Scan(&IDusers, &Username, &Password, &PIN)
checkErr(err)
fmt.Printf("%d, %s, %s, %d \n ", IDusers, Username, Password, PIN)
fmt.Fprintln("w \n", Username)
}
rows.Close()
db.Close()
}
func panel(w http.ResponseWriter, r *http.Request) {
@ -50,10 +75,19 @@ func login(w http.ResponseWriter, r *http.Request) {
}
}
func init() {
sql.Register("sqlite3", &SQLiteDriver{})
//***************************************************************************
//Bazy danych SQlite
//***************************************************************************
func checkErr(err error) {
if err != nil {
fmt.Println("Błąd")
}
}
//***************************************************************************
//funkcja główna
//***************************************************************************
func main() {
http.HandleFunc("/", opisStołówkaZPM)
http.HandleFunc("/login", login)
@ -62,7 +96,4 @@ func main() {
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
db, err := sql.Open("sqlite3", "./stolowka.db")
checkErr(err)
}