Skip to content

Instantly share code, notes, and snippets.

@lintianzhi
Created September 1, 2014 07:14
Show Gist options
  • Save lintianzhi/5fd7cefe7840b0ca3755 to your computer and use it in GitHub Desktop.
Save lintianzhi/5fd7cefe7840b0ca3755 to your computer and use it in GitHub Desktop.
parse request id
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