本文整理汇总了Golang中Time.Time.Unix方法的典型用法代码示例。如果您正苦于以下问题:Golang Time.Unix方法的具体用法?Golang Time.Unix怎么用?Golang Time.Unix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Time.Time
的用法示例。
在下文中一共展示了Time.Unix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: send
// sends a packet to the sentry server with a given timestamp
func (client Client) send(packet []byte, timestamp time.Time) (err error) {
apiURL := *client.URL
apiURL.Path = path.Join(apiURL.Path, "/api/"+client.Project+"/store")
apiURL.Path += "/"
location := apiURL.String()
buf := bytes.NewBuffer(packet)
req, err := http.NewRequest("POST", location, buf)
if err != nil {
return err
}
authHeader := fmt.Sprintf(xSentryAuthTemplate, timestamp.Unix(), client.PublicKey)
req.Header.Add("X-Sentry-Auth", authHeader)
req.Header.Add("Content-Type", "application/octet-stream")
req.Header.Add("Connection", "close")
req.Header.Add("Accept-Encoding", "identity")
resp, err := client.httpClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
switch resp.StatusCode {
case 200:
return nil
default:
return errors.New(resp.Status)
}
}
示例2: mockLoginTokenWithoutID
func mockLoginTokenWithoutID(expires time.Time, auth_key []byte) (string, error) {
token := jwt.New(jwt.SigningMethodHS256)
// Set some claims
token.Claims["exp"] = expires.Unix()
// Sign and get the complete encoded token as a string
return token.SignedString(auth_key)
}
示例3: timeToWindowsFileTime
func timeToWindowsFileTime(t time.Time) []byte {
var ll int64
ll = (int64(t.Unix()) * int64(10000000)) + int64(116444736000000000)
buffer := bytes.NewBuffer(make([]byte, 0, 8))
binary.Write(buffer, binary.LittleEndian, ll)
return buffer.Bytes()
}
示例4: RangeTimeFormat
// RangeTimeFormat checks if value with given format is in given range inclusively,
// and returns default value if it's not.
func (k *Key) RangeTimeFormat(format string, defaultVal, min, max time.Time) time.Time {
val := k.MustTimeFormat(format)
if val.Unix() < min.Unix() || val.Unix() > max.Unix() {
return defaultVal
}
return val
}
示例5: SignedURLWithMethod
// SignedURLWithMethod returns a signed URL that allows anyone holding the URL
// to either retrieve the object at path or make a HEAD request against it. The signature is valid until expires.
func (b *Bucket) SignedURLWithMethod(method, path string, expires time.Time, params url.Values, headers http.Header) string {
var uv = url.Values{}
if params != nil {
uv = params
}
if b.S3.Signature == aws.V2Signature {
uv.Set("Expires", strconv.FormatInt(expires.Unix(), 10))
} else {
uv.Set("X-Amz-Expires", strconv.FormatInt(expires.Unix()-time.Now().Unix(), 10))
}
req := &request{
method: method,
bucket: b.Name,
path: path,
params: uv,
headers: headers,
}
err := b.S3.prepare(req)
if err != nil {
panic(err)
}
u, err := req.url()
if err != nil {
panic(err)
}
if b.S3.Auth.Token() != "" && b.S3.Signature == aws.V2Signature {
return u.String() + "&x-amz-security-token=" + url.QueryEscape(req.headers["X-Amz-Security-Token"][0])
} else {
return u.String()
}
}
示例6: goroutineWork
func goroutineWork(timestamps *[]int64, mutex *sync.Mutex, i int64, arrayCursor *int, url, token string) error {
getParam := "?page="
if strings.Contains(url, "?") {
getParam = "&page="
}
pageUrl := url + getParam + strconv.Itoa(int(i))
stargazers, _, err := getStargazers(pageUrl, token)
if err != nil {
return err
}
for _, star := range stargazers {
var t time.Time
t, err = time.Parse(time.RFC3339, star.Timestamp)
if err != nil {
return fmt.Errorf("An error occured while parsing the timestamp: %v", err)
}
timestamp := t.Unix()
mutex.Lock()
(*timestamps)[*arrayCursor] = timestamp
(*arrayCursor) = (*arrayCursor) + 1
mutex.Unlock()
}
return nil
}
示例7: Protect
//----------------------------------------------- RAID->PROTECTED
// A->B->A->A
func Protect(id int32, until time.Time) bool {
_lock_raids.Lock()
player := _raids[id]
_lock_raids.Unlock()
if player != nil {
player.LCK.Lock()
state := player.State
if state&RAID != 0 {
player.State = int32(OFFLINE | PROTECTED)
player.ProtectTime = until.Unix()
player.LCK.Unlock()
_lock_raids.Lock()
delete(_raids, id) // remove from raids
_lock_raids.Unlock()
_lock_protects.Lock()
_protects[id] = player // add to protects
_lock_protects.Unlock()
return true
}
player.LCK.Unlock()
}
return false
}
示例8: VerifyXsrfToken
// VerifyXsrfToken returns true if token is valid or false otherwise.
// action identifies the web page; now is the current time.
// If no userId is set, VerifyXsrfToken returns false.
func (s UserIdSession) VerifyXsrfToken(
tokenToBeVerified, action string, now time.Time) bool {
idx := strings.IndexByte(tokenToBeVerified, ':')
if idx == -1 {
return false
}
expireUnix, err := strconv.ParseInt(tokenToBeVerified[:idx], 10, 64)
if err != nil {
return false
}
if now.Unix() >= expireUnix {
return false
}
userId, ok := s.UserId()
if !ok {
return false
}
secret, ok := s.xsrfSecret()
if !ok {
return false
}
expectedChecksum := tokenToBeVerified[idx+1:]
mac := hmac.New(sha256.New, secret)
message := fmt.Sprintf("%d_%d_%s", expireUnix, userId, action)
mac.Write(([]byte)(message))
checksum := strings.TrimRight(
base32.StdEncoding.EncodeToString(mac.Sum(nil)), "=")
return hmac.Equal(([]byte)(expectedChecksum), ([]byte)(checksum))
}
示例9: UploadSignedURL
// UploadSignedURL returns a signed URL that allows anyone holding the URL
// to upload the object at path. The signature is valid until expires.
// contenttype is a string like image/png
// name is the resource name in OSS terminology like images/ali.png [obviously excluding the bucket name itself]
func (b *Bucket) UploadSignedURL(name, method, contentType string, expires time.Time) string {
//TODO TESTING
expireDate := expires.Unix()
if method != "POST" {
method = "PUT"
}
tokenData := ""
stringToSign := method + "\n\n" + contentType + "\n" + strconv.FormatInt(expireDate, 10) + "\n" + tokenData + "/" + path.Join(b.Name, name)
secretKey := b.AccessKeySecret
accessId := b.AccessKeyId
mac := hmac.New(sha1.New, []byte(secretKey))
mac.Write([]byte(stringToSign))
macsum := mac.Sum(nil)
signature := base64.StdEncoding.EncodeToString([]byte(macsum))
signature = strings.TrimSpace(signature)
signedurl, err := url.Parse("https://" + b.Name + ".client.amazonaws.com/")
if err != nil {
log.Println("ERROR sining url for OSS upload", err)
return ""
}
signedurl.Path = name
params := url.Values{}
params.Add("OSSAccessKeyId", accessId)
params.Add("Expires", strconv.FormatInt(expireDate, 10))
params.Add("Signature", signature)
signedurl.RawQuery = params.Encode()
return signedurl.String()
}
示例10: ActiveSince
func (x *ActiveApps) ActiveSince(y time.Time) []string {
t := y.Unix()
x.Lock()
a := byTimeMaxHeapSnapshot{}
a.Heap = x.j.Copy()
a.Init()
x.Unlock()
// Collect active applications
b := make([]string, 0)
for a.Len() > 0 {
z := heap.Pop(&a).(*activeAppsEntry)
if z.t < t {
break
}
// Add active application
b = append(b, z.ApplicationId)
}
return b
}
示例11: SignedURLWithMethod
// SignedURLWithMethod returns a signed URL that allows anyone holding the URL
// to either retrieve the object at path or make a HEAD request against it. The signature is valid until expires.
func (b *Bucket) SignedURLWithMethod(method, path string, expires time.Time, params url.Values, headers http.Header) string {
var uv = url.Values{}
if params != nil {
uv = params
}
uv.Set("Expires", strconv.FormatInt(expires.Unix(), 10))
uv.Set("OSSAccessKeyId", b.AccessKeyId)
req := &request{
method: method,
bucket: b.Name,
path: path,
params: uv,
headers: headers,
}
err := b.Client.prepare(req)
if err != nil {
panic(err)
}
u, err := req.url()
if err != nil {
panic(err)
}
return u.String()
}
示例12: ListIssueComments
func ListIssueComments(ctx *context.APIContext) {
var since time.Time
if len(ctx.Query("since")) > 0 {
since, _ = time.Parse(time.RFC3339, ctx.Query("since"))
}
// comments,err:=models.GetCommentsByIssueIDSince(, since)
issue, err := models.GetRawIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
ctx.Error(500, "GetRawIssueByIndex", err)
return
}
comments, err := models.GetCommentsByIssueIDSince(issue.ID, since.Unix())
if err != nil {
ctx.Error(500, "GetCommentsByIssueIDSince", err)
return
}
apiComments := make([]*api.Comment, len(comments))
for i := range comments {
apiComments[i] = comments[i].APIFormat()
}
ctx.JSON(200, &apiComments)
}
示例13: GetModifyDate
// GetModifyDate returns last modify date of given mirror repository.
func (mirror *Mirror) GetModifyDate() (time.Time, error) {
dirs := []string{
"refs/heads",
"refs/tags",
}
var (
modDate time.Time
err error
fileinfo os.FileInfo
)
for _, dir := range dirs {
fileinfo, err = os.Stat(mirror.Dir + "/" + dir)
if err != nil {
if os.IsNotExist(err) {
continue
}
break
}
newModDate := fileinfo.ModTime()
if newModDate.Unix() > modDate.Unix() {
modDate = newModDate
}
}
return modDate, err
}
示例14: processTimeRange
// processTimeRange calls gs.GetLatestGSDirs to get a list of
func (xformer *pdfXformer) processTimeRange(start time.Time, end time.Time) {
glog.Infof("Processing time range: (%s, %s)", start.Truncate(time.Second), end.Truncate(time.Second))
for _, dir := range gs.GetLatestGSDirs(start.Unix(), end.Unix(), *storageJsonDirectory) {
glog.Infof("> Reading gs://%s/%s\n", *storageBucket, dir)
requestedObjects := xformer.client.storageService.Objects.List(*storageBucket).Prefix(dir).Fields(
"nextPageToken", "items/updated", "items/md5Hash", "items/mediaLink", "items/name", "items/metadata")
for requestedObjects != nil {
responseObjects, err := requestedObjects.Do()
if err != nil {
glog.Errorf("request %#v failed: %s", requestedObjects, err)
} else {
for _, jsonObject := range responseObjects.Items {
xformer.counter++
glog.Infof("> > Processing object: gs://%s/%s {%d}", *storageBucket, jsonObject.Name, xformer.counter)
xformer.processJsonFile(jsonObject)
}
}
if len(responseObjects.NextPageToken) > 0 {
requestedObjects.PageToken(responseObjects.NextPageToken)
} else {
requestedObjects = nil
}
}
}
glog.Infof("finished time range.")
}
示例15: StoreLastUpdate
func (f *RrdRawFile) StoreLastUpdate(lastUpdate time.Time) error {
writer := f.dataFile.Writer(f.baseHeaderSize)
if err := writer.WriteUnival(unival(lastUpdate.Unix())); err != nil {
return errors.Wrap(err, 0)
}
return writer.WriteUnival(unival(lastUpdate.Nanosecond() / 1000))
}