Skip to content

Instantly share code, notes, and snippets.

@Kamandlou
Created May 10, 2023 09:09
Show Gist options
  • Save Kamandlou/8bbbc74f17ba90873a8cfed2741d84a0 to your computer and use it in GitHub Desktop.
Save Kamandlou/8bbbc74f17ba90873a8cfed2741d84a0 to your computer and use it in GitHub Desktop.
Set timeout for sql query in GORM
// It will cancel at one second
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
db.WithContext(ctx).Find(&User)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment