Skip to content

Commit 7cc3974

Browse files
committed
mf
1 parent 2f5d846 commit 7cc3974

File tree

4 files changed

+41
-39
lines changed

4 files changed

+41
-39
lines changed

pkg/cmd/run.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const TEMPLATEDIR = "$HOME/.jr/templates"
3636
const DEFAULT_KEY = "null"
3737
const DEFAULT_OUTPUT = "stdout"
3838
const DEFAULT_OUTPUT_TEMPLATE = "{{.V}}\n"
39+
const DEFAULT_OUTPUT_KCAT_TEMPLATE = "{{.K}},{{.V}}\n"
3940
const DEFAULT_SERIALIZER = "json-schema"
4041
const KAFKA_CONFIG = "./kafka/config.properties"
4142
const REGISTRY_CONFIG = "./kafka/registry.properties"
@@ -88,7 +89,7 @@ jr run --templateFileName ~/.jr/templates/net_device.tpl
8889
if kcat {
8990
oneline = true
9091
output = "stdout"
91-
outputTemplate = "{{.K}},{{.V}}\n"
92+
outputTemplate = DEFAULT_OUTPUT_KCAT_TEMPLATE
9293
}
9394

9495
conf := functions.Configuration{

pkg/functions/context.go

+38-36
Original file line numberDiff line numberDiff line change
@@ -62,46 +62,48 @@ type Configuration struct {
6262

6363
// Context is the object passed on the templates which contains all the needed details.
6464
type Context struct {
65-
StartTime time.Time
66-
TemplateDir string
67-
TemplateType []string
68-
GeneratedObjects int64
69-
GeneratedBytes int64
70-
Num int
71-
NumTemplates int
72-
Range []int
73-
Frequency time.Duration
74-
Duration time.Duration
75-
Locale string
76-
Seed int64
77-
CtxCounters map[string]int
78-
Ctx map[string]string
79-
CtxList map[string][]string
80-
LastIndex int
81-
CountryIndex int
82-
CityIndex int
65+
StartTime time.Time
66+
TemplateDir string
67+
TemplateType []string
68+
PreloadTemplateType []string
69+
GeneratedObjects int64
70+
GeneratedBytes int64
71+
Num int
72+
NumTemplates int
73+
Range []int
74+
Frequency time.Duration
75+
Duration time.Duration
76+
Locale string
77+
Seed int64
78+
CtxCounters map[string]int
79+
Ctx map[string]string
80+
CtxList map[string][]string
81+
LastIndex int
82+
CountryIndex int
83+
CityIndex int
8384
}
8485

8586
func init() {
8687

8788
JrContext = Context{
88-
StartTime: time.Now(),
89-
TemplateDir: os.ExpandEnv(TEMPLATEDIR),
90-
TemplateType: make([]string, NUM_TEMPLATES),
91-
GeneratedBytes: 0,
92-
GeneratedObjects: 0,
93-
Num: NUM,
94-
NumTemplates: NUM_TEMPLATES,
95-
Range: make([]int, NUM),
96-
Frequency: FREQUENCY,
97-
Duration: DURATION,
98-
Locale: "us",
99-
Seed: time.Now().UTC().UnixNano(),
100-
CtxCounters: make(map[string]int),
101-
Ctx: make(map[string]string),
102-
CtxList: make(map[string][]string),
103-
LastIndex: -1,
104-
CountryIndex: 232,
105-
CityIndex: -1,
89+
StartTime: time.Now(),
90+
TemplateDir: os.ExpandEnv(TEMPLATEDIR),
91+
TemplateType: make([]string, NUM_TEMPLATES),
92+
PreloadTemplateType: make([]string, NUM_TEMPLATES),
93+
GeneratedBytes: 0,
94+
GeneratedObjects: 0,
95+
Num: NUM,
96+
NumTemplates: NUM_TEMPLATES,
97+
Range: make([]int, NUM),
98+
Frequency: FREQUENCY,
99+
Duration: DURATION,
100+
Locale: "us",
101+
Seed: time.Now().UTC().UnixNano(),
102+
CtxCounters: make(map[string]int),
103+
Ctx: make(map[string]string),
104+
CtxList: make(map[string][]string),
105+
LastIndex: -1,
106+
CountryIndex: 232,
107+
CityIndex: -1,
106108
}
107109
}

pkg/functions/loop.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func DoTemplates(conf Configuration) {
6868
for i := range conf.Preload {
6969
templatePath := fmt.Sprintf("%s/%s.tpl", conf.TemplateDir, conf.Preload[i])
7070
preloadTemplate[i], err = os.ReadFile(templatePath)
71-
JrContext.TemplateType[i] = conf.TemplateNames[i]
71+
JrContext.PreloadTemplateType[i] = conf.Preload[i]
7272
}
7373

7474
if err != nil {

templates/data/fr/movie

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ Terminator
9292
The Truman Show
9393
Top Gun
9494
Toy Story
95-
Toy Story
9695
Trainspotting
9796
Un jour sans fin
9897
Usual Suspects

0 commit comments

Comments
 (0)