You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
260 B

package gormExample
import (
"context"
"fmt"
"log"
)
func ContextTimeoutCancel(ctx context.Context) {
// 传递Context执行
var cs []Content
if err := DB.WithContext(ctx).Limit(5).Find(&cs).Error; err != nil {
log.Fatalln(err)
}
fmt.Println(cs)
}