github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/infra/logid/examples/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "net" 6 7 "github.com/jxskiss/gopkg/v2/infra/logid" 8 ) 9 10 func main() { 11 N := 3 12 13 // default v1 generator 14 fmt.Println("v1 default generator:") 15 { 16 id1 := logid.Gen() 17 fmt.Println(id1) 18 fmt.Println(logid.Decode(id1)) 19 for i := 0; i < N; i++ { 20 fmt.Println(logid.Gen()) 21 } 22 } 23 24 // v2 generator 25 for _, ip := range []string{ 26 "1.2.3.4", 27 "fdbd:dc01:16:16::94", 28 "", 29 } { 30 fmt.Printf("\nv2 generator, ip: %q\n", ip) 31 v2Gen := logid.NewV2Gen(net.ParseIP(ip)) 32 id2 := v2Gen.Gen() 33 fmt.Println(id2) 34 fmt.Println(logid.Decode(id2)) 35 for i := 0; i < N; i++ { 36 fmt.Println(v2Gen.Gen()) 37 } 38 } 39 }