1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package main
- import "fmt"
- func main() {
- // The UserDB would be run on the server
- // But since most/100% of this is examples, we'll setup one up
- db := &UserDB{}
- err := db.Open("test_users.db3")
- if err != nil {
- fmt.Println("Err:", err)
- return
- }
- defer db.Close()
- // Example query
- dummy, err := db.FindUser("Test Dummy")
- if err != nil {
- // Of course, we'd ask the user for their name and a password then use those
- // But for our Test Dummy let's just make a dumb and simple setup
- err = db.CreateUser("Test Dummy", "12345")
- if err != nil {
- fmt.Println("Err:", err)
- return
- }
- dummy, err = db.FindUser("Test Dummy")
- if err != nil {
- fmt.Println("Err:", err)
- return
- }
- }
- //fmt.Printf("%#v\r\n", dummy)
- // Example verification process
- // I'd also want to verify they aren't trying to login in 2+ places at once
- err = dummy.VerifyPassword("12345")
- if err != nil {
- fmt.Println("Wrong password?")
- } else {
- fmt.Printf("Yay, %s has logged in\r\n", dummy.Name)
- }
- }
|