add complexIDs bool for configuring
This commit is contained in:
parent
bb47f98bf0
commit
bbeacf637d
1 changed files with 26 additions and 4 deletions
|
|
@ -15,6 +15,8 @@ import (
|
||||||
"oss.terrastruct.com/d2/d2target"
|
"oss.terrastruct.com/d2/d2target"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const complexIDs = false
|
||||||
|
|
||||||
func GenDSL(maxi int) (_ string, err error) {
|
func GenDSL(maxi int) (_ string, err error) {
|
||||||
gs := &dslGenState{
|
gs := &dslGenState{
|
||||||
rand: mathrand.New(mathrand.NewSource(time.Now().UnixNano())),
|
rand: mathrand.New(mathrand.NewSource(time.Now().UnixNano())),
|
||||||
|
|
@ -62,7 +64,11 @@ func (gs *dslGenState) gen(maxi int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gs *dslGenState) genNode(containerID string) (string, error) {
|
func (gs *dslGenState) genNode(containerID string) (string, error) {
|
||||||
nodeID := gs.randStr(8, true)
|
maxLen := 8
|
||||||
|
if complexIDs {
|
||||||
|
maxLen = 32
|
||||||
|
}
|
||||||
|
nodeID := gs.randStr(maxLen, true)
|
||||||
if containerID != "" {
|
if containerID != "" {
|
||||||
nodeID = containerID + "." + nodeID
|
nodeID = containerID + "." + nodeID
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +101,11 @@ func (gs *dslGenState) node() error {
|
||||||
|
|
||||||
if gs.roll(25, 75) == 0 {
|
if gs.roll(25, 75) == 0 {
|
||||||
// 25% chance of adding a label.
|
// 25% chance of adding a label.
|
||||||
gs.g, err = d2oracle.Set(gs.g, nodeID, nil, go2.Pointer(gs.randStr(8, false)))
|
maxLen := 8
|
||||||
|
if complexIDs {
|
||||||
|
maxLen = 256
|
||||||
|
}
|
||||||
|
gs.g, err = d2oracle.Set(gs.g, nodeID, nil, go2.Pointer(gs.randStr(maxLen, false)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -154,7 +164,11 @@ func (gs *dslGenState) edge() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if gs.randBool() {
|
if gs.randBool() {
|
||||||
gs.g, err = d2oracle.Set(gs.g, key, nil, go2.Pointer(gs.randStr(8, false)))
|
maxLen := 8
|
||||||
|
if complexIDs {
|
||||||
|
maxLen = 128
|
||||||
|
}
|
||||||
|
gs.g, err = d2oracle.Set(gs.g, key, nil, go2.Pointer(gs.randStr(maxLen, false)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +205,15 @@ func (gs *dslGenState) randBool() bool {
|
||||||
// TODO go back to using xrand.String, currently some incompatibility with
|
// TODO go back to using xrand.String, currently some incompatibility with
|
||||||
// stuffing these strings into a script for dagre
|
// stuffing these strings into a script for dagre
|
||||||
func randRune() rune {
|
func randRune() rune {
|
||||||
return mathrand.Int31n(26) + 97
|
if complexIDs {
|
||||||
|
if mathrand.Int31n(100) == 0 {
|
||||||
|
// Generate newline 1% of the time.
|
||||||
|
return '\n'
|
||||||
|
}
|
||||||
|
return mathrand.Int31n(128) + 1
|
||||||
|
} else {
|
||||||
|
return mathrand.Int31n(26) + 97
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gs *dslGenState) findOuterSequenceDiagram(nodeID string) string {
|
func (gs *dslGenState) findOuterSequenceDiagram(nodeID string) string {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue