Skip to content

Commit

Permalink
feat: modify template
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangliang committed May 8, 2021
1 parent 14efca5 commit 02bcb13
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 58 deletions.
20 changes: 7 additions & 13 deletions protoc-gen-series/tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type {{ $project }}Writer interface {
Flush()
Errors() <- chan error
{{- range .Messages -}}{{ $table := upperCamelCase . }}
Write{{ $table }}Point(tag *{{ $project }}{{ $table }}Tag, field *{{ $project }}{{ $table }}Field) error
Write{{ $table }}PointWithTime(tag *{{ $project }}{{ $table }}Tag, field *{{ $project }}{{ $table }}Field, timestamp time.Time) error
Write{{ $table }}Point(tag *{{ $project }}{{ $table }}Tag, field *{{ $project }}{{ $table }}Field)
Write{{ $table }}PointWithTime(tag *{{ $project }}{{ $table }}Tag, field *{{ $project }}{{ $table }}Field, timestamp time.Time)
{{- end }}
}
Expand All @@ -36,21 +36,15 @@ func (w *{{ lowerCamelCase . }}Writer) Errors() <-chan error {
return w.WriteAPI.Errors()
}
{{ range .Messages }}{{ $table := upperCamelCase . }}{{ $lowerSnakeTable := lowerSnakeCase . }}
func (w *{{ $lowerCamelProject }}Writer) Write{{ $table }}Point(tag *{{ $project }}{{ $table }}Tag, field *{{ $project }}{{ $table }}Field) error {
return w.Write{{ $table }}PointWithTime(tag, field, time.Now())
func (w *{{ $lowerCamelProject }}Writer) Write{{ $table }}Point(tag *{{ $project }}{{ $table }}Tag, field *{{ $project }}{{ $table }}Field) {
w.Write{{ $table }}PointWithTime(tag, field, time.Now())
}
func (w *{{ $lowerCamelProject }}Writer) Write{{ $table }}PointWithTime(tag *{{ $project }}{{ $table }}Tag, field *{{ $project }}{{ $table }}Field, timestamp time.Time) error {
if tag == nil || field == nil {
return errors.New("nil point error")
}
point := influxdb.NewPointWithMeasurement("{{ $lowerSnakeProject }}_{{ $lowerSnakeTable }}")
{{ range ( selectSubMsg . "tag" )}}
point.AddTag("{{ lowerSnakeCase . }}", tag.{{ upperCamelCase . }}){{ end }}
{{ range ( selectSubMsg . "field")}}
func (w *{{ $lowerCamelProject }}Writer) Write{{ $table }}PointWithTime(tag *{{ $project }}{{ $table }}Tag, field *{{ $project }}{{ $table }}Field, timestamp time.Time) {
point := influxdb.NewPointWithMeasurement("{{ $lowerSnakeProject }}_{{ $lowerSnakeTable }}"){{ range ( selectSubMsg . "tag" )}}
point.AddTag("{{ lowerSnakeCase . }}", tag.{{ upperCamelCase . }}){{ end }}{{ range ( selectSubMsg . "field")}}
point.AddField("{{ lowerSnakeCase . }}", field.{{ upperCamelCase . }}){{ end }}
w.WriteAPI.WritePoint(point)
return nil
}
{{- end -}}
{{ end }}
Expand Down
65 changes: 20 additions & 45 deletions testdata/series/test.pb.sr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 02bcb13

Please sign in to comment.