MCPcopy
hub / github.com/apache/answer / NumToShortID

Function NumToShortID

pkg/uid/sid.go:32–50  ·  view source on GitHub ↗

NumToShortID num to string

(id int64)

Source from the content-addressed store, hash-verified

30
31// NumToShortID num to string
32func NumToShortID(id int64) string {
33 sid := strconv.FormatInt(id, 10)
34 if len(sid) < 17 {
35 return ""
36 }
37 sTypeCode := sid[1:4]
38 sid = sid[4:int32(len(sid))]
39 id, err := strconv.ParseInt(sid, 10, 64)
40 if err != nil {
41 return ""
42 }
43 typeCode, err := strconv.ParseInt(sTypeCode, 10, 64)
44 if err != nil {
45 return ""
46 }
47 code := utils.EnShortID(id, salt)
48 tcode := utils.EnShortID(typeCode, salt)
49 return tcode + code
50}
51
52// ShortIDToNum string to num
53func ShortIDToNum(code string) int64 {

Callers 1

EnShortIDFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected