golang 1.7之後引入了context.
首先看看context,下邊是golang sdk源代碼中context內容,可以發現他是一個接口,通過定義一種規範,來規定context操作方法.
// 上下文是一個接口.
// 這個接口中聲明瞭4個方法.
type Context interface {
// Deadline returns the time when work done on behalf of this context
// should be canceled. Deadline returns ok==false when no deadline is
// set. Successive calls to Deadline return the same results.
// 這個方法在timerCtx類中實現.
// 主要服務於定時類型的context服務.
// 通過設置截止時間戳,來規定context的有效期間.
// 只有通過WithDeadline或者WithTimeout才能操作Deadline.