7a04f298d2
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
49 lines
1.8 KiB
Cheetah
49 lines
1.8 KiB
Cheetah
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.structConfig*/ -}}
|
|
{{ define "field_mapping" }}{{- $s := .Struct -}}
|
|
|
|
{{- range $f := $s.Fields }}{{ if and (not $f.DoubleSlice) (ne ($f.Type) ("bin.Fields")) }}
|
|
{{ if not $f.Slice }}
|
|
|
|
{{- $mappings := index ($.Config.Mappings) ($f.Type) -}}
|
|
{{- range $mapping := $mappings }}{{- if (not $mapping.Constructor) }}
|
|
{{- /*gotype: go.mau.fi/mautrix-telegram/pkg/gotd/gen.constructorMapping*/ -}}
|
|
// Get{{ $f.Name }}As{{ $mapping.MapperName }} returns mapped value of {{ $f.Name }} {{ if $f.Conditional }}
|
|
{{- if not ($f.ConditionalBool) }}conditional field and
|
|
// boolean which is true if field was set.
|
|
{{- else }}conditional field.
|
|
{{- end }}
|
|
{{- else }}field.
|
|
{{- end }}
|
|
func ({{ $s.Receiver }} *{{ $s.Name }}) Get{{ $f.Name }}As{{ $mapping.MapperName }}() ({{ template "print_mapper_type" $mapping }}, bool) {
|
|
{{- if $f.Conditional }}
|
|
if value, ok := {{ $s.Receiver }}.Get{{ $f.Name }}(); ok {
|
|
return value.As{{ $mapping.MapperName }}()
|
|
}
|
|
return nil, false
|
|
{{- else }}
|
|
return {{ $s.Receiver }}.{{ $f.Name }}.As{{ $mapping.MapperName }}()
|
|
{{- end }}
|
|
}
|
|
{{- end }}{{- end }}
|
|
|
|
{{- else }}
|
|
|
|
{{- if $f.Interface }}
|
|
// Map{{ $f.Name }} returns field {{ $f.Name }} wrapped in {{ template "slice_field_name" $f }} helper.
|
|
func ({{ $s.Receiver }} *{{ $s.Name }}) Map{{ $f.Name }}() (value {{ template "slice_field_name" $f }}{{ if $f.Conditional }}, ok bool{{ end }}) {
|
|
{{- if $f.Conditional }}
|
|
if !{{ $s.Receiver }}.{{ $f.ConditionalField }}.Has({{ $f.ConditionalIndex }}) {
|
|
return value, false
|
|
}
|
|
return {{ template "slice_field_name" $f }}({{ $s.Receiver }}.{{ $f.Name }}), true
|
|
{{- else }}
|
|
return {{ template "slice_field_name" $f }}({{ $s.Receiver }}.{{ $f.Name }})
|
|
{{- end }}
|
|
}
|
|
{{- end }}
|
|
|
|
{{- end }}
|
|
{{- end }}{{- end }}
|
|
|
|
{{ end }}
|