gitlab.com/evatix-go/core@v1.3.55/cmd/main/SimpleStringOnceChecker.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  
     7  	"gitlab.com/evatix-go/core/coredata/corestr"
     8  )
     9  
    10  type simpleStringTester struct {
    11  	count  int
    12  	simple corestr.SimpleStringOnce
    13  }
    14  
    15  func (it *simpleStringTester) Something() (val string, count int) {
    16  	if it.simple.IsInitialized() {
    17  		return it.simple.Value(), it.count
    18  	}
    19  
    20  	it.count++
    21  
    22  	return it.
    23  			simple.
    24  			GetPlusSetOnUninitialized("some value " + strconv.Itoa(it.count)),
    25  		it.count
    26  }
    27  
    28  var (
    29  	simpleStringTester2 = &simpleStringTester{}
    30  )
    31  
    32  func SimpleStringOnceChecker(testCount int) {
    33  	for i := 0; i < testCount; i++ {
    34  		v, count := simpleStringTester2.Something()
    35  
    36  		fmt.Println(i, v, count)
    37  	}
    38  }