main.go 1004 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package main
  2. import "fmt"
  3. func main() {
  4. // The UserDB would be run on the server
  5. // But since most/100% of this is examples, we'll setup one up
  6. db := &UserDB{}
  7. err := db.Open("test_users.db3")
  8. if err != nil {
  9. fmt.Println("Err:", err)
  10. return
  11. }
  12. defer db.Close()
  13. // Example query
  14. dummy, err := db.FindUser("Test Dummy")
  15. if err != nil {
  16. // Of course, we'd ask the user for their name and a password then use those
  17. // But for our Test Dummy let's just make a dumb and simple setup
  18. err = db.CreateUser("Test Dummy", "12345")
  19. if err != nil {
  20. fmt.Println("Err:", err)
  21. return
  22. }
  23. dummy, err = db.FindUser("Test Dummy")
  24. if err != nil {
  25. fmt.Println("Err:", err)
  26. return
  27. }
  28. }
  29. //fmt.Printf("%#v\r\n", dummy)
  30. // Example verification process
  31. // I'd also want to verify they aren't trying to login in 2+ places at once
  32. err = dummy.VerifyPassword("12345")
  33. if err != nil {
  34. fmt.Println("Wrong password?")
  35. } else {
  36. fmt.Printf("Yay, %s has logged in\r\n", dummy.Name)
  37. }
  38. }