-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rework file structure of value interface
- Loading branch information
Showing
6 changed files
with
123 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package generator | ||
|
||
import ( | ||
"log" | ||
"time" | ||
) | ||
|
||
type dateValue struct { | ||
currentValue time.Time | ||
step time.Duration | ||
} | ||
|
||
func (v *dateValue) generateValue() { | ||
v.currentValue = v.currentValue.Add(v.step) | ||
} | ||
|
||
func (v *dateValue) init(i string) { | ||
var err error | ||
v.currentValue, err = time.Parse("2006-01-02 15:04:05", i) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
v.step = 1000000000 // 1B nanoseconds = 1s | ||
} | ||
|
||
func (v dateValue) getCurrentValue() string { | ||
return v.currentValue.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package generator | ||
|
||
import "strconv" | ||
|
||
type floatValue struct { | ||
currentValue float64 | ||
step float64 | ||
} | ||
|
||
func (v *floatValue) generateValue() { | ||
v.currentValue += v.step | ||
} | ||
|
||
func (v *floatValue) init(i string) { | ||
v.currentValue, _ = strconv.ParseFloat(i, 64) | ||
v.step = 0.1 | ||
} | ||
|
||
func (v floatValue) getCurrentValue() string { | ||
return strconv.FormatFloat(v.currentValue, 'f', 2, 64) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package generator | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/brianvoe/gofakeit/v4" | ||
) | ||
|
||
type idIntValue struct { | ||
currentValue uint64 | ||
} | ||
|
||
/* | ||
* All new types need all the methods in interface value in value.go | ||
*/ | ||
|
||
func (v *idIntValue) generateValue() { | ||
v.currentValue = gofakeit.Uint64() | ||
} | ||
|
||
func (v *idIntValue) init(i string) { | ||
v.currentValue = gofakeit.Uint64() | ||
} | ||
|
||
func (v idIntValue) getCurrentValue() string { | ||
return strconv.FormatUint(v.currentValue, 10) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package generator | ||
|
||
import "strconv" | ||
|
||
type intValue struct { | ||
currentValue int64 | ||
step int64 | ||
} | ||
|
||
func (v *intValue) generateValue() { | ||
v.currentValue += v.step | ||
} | ||
|
||
func (v *intValue) init(i string) { | ||
v.currentValue, _ = strconv.ParseInt(i, 10, 64) | ||
v.step = 1 | ||
} | ||
|
||
func (v intValue) getCurrentValue() string { | ||
return strconv.FormatInt(v.currentValue, 10) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package generator | ||
|
||
import "strconv" | ||
|
||
type stringValue struct { | ||
prefix string | ||
currentValue string | ||
step int64 | ||
currentStep int64 | ||
} | ||
|
||
func (v *stringValue) generateValue() { | ||
v.currentStep = v.currentStep + v.step | ||
v.currentValue = v.prefix + "_" + strconv.FormatInt(v.currentStep, 10) | ||
} | ||
|
||
func (v *stringValue) init(i string) { | ||
v.prefix = i | ||
v.currentStep = 1 | ||
v.currentValue = v.prefix + "_" + strconv.FormatInt(v.currentStep, 10) | ||
v.step = 1 | ||
} | ||
|
||
func (v stringValue) getCurrentValue() string { | ||
return v.currentValue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,7 @@ | ||
package generator | ||
|
||
import ( | ||
"log" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/brianvoe/gofakeit/v4" | ||
) | ||
|
||
type stringValue struct { | ||
prefix string | ||
currentValue string | ||
step int64 | ||
currentStep int64 | ||
} | ||
|
||
type intValue struct { | ||
currentValue int64 | ||
step int64 | ||
} | ||
|
||
type floatValue struct { | ||
currentValue float64 | ||
step float64 | ||
} | ||
|
||
type dateValue struct { | ||
currentValue time.Time | ||
step time.Duration | ||
} | ||
|
||
type idIntValue struct { | ||
currentValue uint64 | ||
} | ||
|
||
type value interface { | ||
getCurrentValue() string | ||
generateValue() | ||
init(i string) | ||
} | ||
|
||
func (v *idIntValue) generateValue() { | ||
v.currentValue = gofakeit.Uint64() | ||
} | ||
|
||
func (v *intValue) generateValue() { | ||
v.currentValue += v.step | ||
} | ||
|
||
func (v *floatValue) generateValue() { | ||
v.currentValue += v.step | ||
} | ||
|
||
func (v *stringValue) generateValue() { | ||
v.currentStep = v.currentStep + v.step | ||
v.currentValue = v.prefix + "_" + strconv.FormatInt(v.currentStep, 10) | ||
} | ||
|
||
func (v *dateValue) generateValue() { | ||
v.currentValue = v.currentValue.Add(v.step) | ||
} | ||
|
||
func (v *idIntValue) init(i string) { | ||
v.currentValue = gofakeit.Uint64() | ||
} | ||
|
||
func (v *intValue) init(i string) { | ||
v.currentValue, _ = strconv.ParseInt(i, 10, 64) | ||
v.step = 1 | ||
} | ||
|
||
func (v *floatValue) init(i string) { | ||
v.currentValue, _ = strconv.ParseFloat(i, 64) | ||
v.step = 0.1 | ||
} | ||
|
||
func (v *stringValue) init(i string) { | ||
v.prefix = i | ||
v.currentStep = 1 | ||
v.currentValue = v.prefix + "_" + strconv.FormatInt(v.currentStep, 10) | ||
v.step = 1 | ||
} | ||
|
||
func (v *dateValue) init(i string) { | ||
var err error | ||
v.currentValue, err = time.Parse("2006-01-02 15:04:05", i) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
v.step = 1000000 // 1M nanoseconds = 1ms | ||
} | ||
|
||
func (v idIntValue) getCurrentValue() string { | ||
return strconv.FormatUint(v.currentValue, 10) | ||
} | ||
|
||
func (v intValue) getCurrentValue() string { | ||
return strconv.FormatInt(v.currentValue, 10) | ||
} | ||
|
||
func (v floatValue) getCurrentValue() string { | ||
return strconv.FormatFloat(v.currentValue, 'f', 2, 64) | ||
} | ||
|
||
func (v stringValue) getCurrentValue() string { | ||
return v.currentValue | ||
} | ||
|
||
func (v dateValue) getCurrentValue() string { | ||
return v.currentValue.String() | ||
} |