Guest User

Untitled

a guest
Jun 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "context"
  5. "database/sql"
  6. "log"
  7. "time"
  8.  
  9. _ "github.com/jinzhu/gorm/dialects/sqlite"
  10. )
  11.  
  12. func main() {
  13. db, err := sql.Open("sqlite3", "/tmp/gorm.db")
  14. if err != nil {
  15. log.Panic(err)
  16. }
  17. ctx := context.Background()
  18. ctx, cancel := context.WithTimeout(ctx, time.Microsecond*10)
  19. defer cancel()
  20. res := db.QueryRowContext(ctx, "select id from orders")
  21. id := -1
  22. if err := res.Scan(&id); err != nil {
  23. log.Panic(err)
  24. }
  25. log.Print(id)
  26. }
  27.  
  28. 2018/06/18 19:19:03 interrupted
  29. panic: interrupted
  30.  
  31. goroutine 1 [running]:
  32. log.Panic(0xc420053f48, 0x1, 0x1)
  33. /usr/local/Cellar/go/1.10.1/libexec/src/log/log.go:326 +0xc0
  34. main.main()
  35. /tmp/main.go:23 +0x226
  36. exit status 2
Add Comment
Please, Sign In to add comment