#463·jwt

jwt.TimeFunc override: thread-safety

Author: imyixiaoCreated Aug 20, 2025Updated Aug 27, 2026

this is more like a question instead of an issue:

  • context: we want to override jwt.TimeFunc to always read now from request header
func ApplyOverrideJWTTimeFunc(header http.Header) {
       jwt.TimeFunc = OverrideJWTTimeFunc(header)
}

func OverrideJWTTimeFunc(header http.Header) func() time.Time {
	return func() time.Time {
		return time.Unix(GetRequestTime(header), 0)
	}
}

// this func read time from request.header
func GetRequestTime(header http.Header)
  • concern: because this override jwt globally, will it be thread-safe or any unexpected risk when we deploy to production