github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/testutil/session.go (about) 1 package testutil 2 3 import ( 4 "fmt" 5 "math" 6 "strconv" 7 8 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xrand" 9 ) 10 11 type ( 12 sessionIDOption func(*sessionIDHolder) 13 sessionIDHolder struct { 14 serviceID uint32 15 nodeID uint32 16 hash string 17 } 18 ) 19 20 func WithServiceID(serviceID uint32) sessionIDOption { 21 return func(h *sessionIDHolder) { 22 h.serviceID = serviceID 23 } 24 } 25 26 func WithNodeID(nodeID uint32) sessionIDOption { 27 return func(h *sessionIDHolder) { 28 h.nodeID = nodeID 29 } 30 } 31 32 func SessionID(opts ...sessionIDOption) string { 33 h := &sessionIDHolder{ 34 serviceID: uint32(xrand.New().Int64(math.MaxUint32)), 35 nodeID: uint32(xrand.New().Int64(math.MaxUint32)), 36 hash: strconv.FormatInt(xrand.New().Int64(math.MaxInt64), 16), 37 } 38 for _, o := range opts { 39 if o != nil { 40 o(h) 41 } 42 } 43 44 return fmt.Sprintf("ydb://session/%d?node_id=%d&id=%s==", h.serviceID, h.nodeID, h.hash) 45 }