Created
September 1, 2014 07:14
-
-
Save lintianzhi/5fd7cefe7840b0ca3755 to your computer and use it in GitHub Desktop.
parse request id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// run: go run % 3jgAAPjhC9FXslMT ZnkAANzksCImuUcT | |
// build: go build -o /usr/bin/qiniu-reqid % | |
import ( | |
"os" | |
"time" | |
"fmt" | |
"log" | |
"encoding/binary" | |
"encoding/base64" | |
) | |
func main() { | |
reqid := os.Args[1] | |
buf, err := base64.URLEncoding.DecodeString(reqid) | |
if err != nil { panic(err) } | |
log.Println(buf, len(buf), len(reqid)) | |
timeStamp := binary.LittleEndian.Uint64(buf[4:]) | |
println(timeStamp) | |
t := time.Unix(0, int64(timeStamp)).Round(time.Second) | |
pid := binary.LittleEndian.Uint32(buf[:4]) | |
fmt.Println("pid:", pid, "time:", t) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment