@@ -7,14 +7,26 @@ package parsers
77import (
88 " github.com/haproxytech/client-native/v6/config-parser/common"
99 " github.com/haproxytech/client-native/v6/config-parser/errors"
10+ {{- if not (eq .Model " " ) }}
11+ " github.com/haproxytech/client-native/v6/models"
12+ {{- else }}
1013 " github.com/haproxytech/client-native/v6/config-parser/{{ .DataDir }}types"
14+ {{- end }}
1115)
1216
17+ {{- if not (eq .Doc " " ) }}
18+ // {{ .Doc }}
19+ {{- end }}
20+
1321{{- if not .NoInit }}
1422
1523func (p *{{ .StructName }}) Init() {
1624{{- if .ParserMultiple }}
25+ {{- if not (eq .Model " " ) }}
26+ p.data = make([]models. {{ .Model }}, 0)
27+ {{- else }}
1728 p.data = []types. {{ .ParserType }}{}
29+ {{- end }}
1830{{- else }}
1931 p.data = nil
2032{{- end }}
@@ -52,7 +64,11 @@ func (p *{{ .StructName }}) Get(createIfNotExist bool) (common.ParserData, error
5264{{- else }}
5365 if p.data == nil {
5466 if createIfNotExist {
67+ {{- if not (eq .Model " " ) }}
68+ p.data = &models. {{ .Model }}{}
69+ {{- else }}
5570 p.data = &types. {{ .ParserType }}{}
71+ {{- end }}
5672 return p.data , nil
5773 }
5874 return nil , errors.ErrFetch
@@ -96,7 +112,11 @@ func (p *{{ .StructName }}) Delete(index int) error {
96112{{- if .IsInterface }}
97113 p.data [len (p.data )-1] = nil
98114{{- else }}
115+ {{- if not (eq .Model " " ) }}
116+ p.data [len (p.data )-1] = models. {{ .Model }}{}
117+ {{- else }}
99118 p.data [len (p.data )-1] = types. {{ .ParserType }}{}
119+ {{- end }}
100120{{- end }}
101121 p.data = p.data [:len (p.data )-1]
102122 return nil
@@ -112,32 +132,52 @@ func (p *{{ .StructName }}) Insert(data common.ParserData, index int) error {
112132 return errors.ErrInvalidData
113133 }
114134 switch newValue := data. (type) {
135+ {{- if not (eq .Model " " ) }}
136+ case []models. {{ .Model }}:
137+ {{- else }}
115138 case []types. {{ .ParserType }}:
139+ {{- end }}
116140 p.data = newValue
141+ {{- if not (eq .Model " " ) }}
142+ case *models. {{ .Model }}:
143+ {{- else }}
117144 case *types. {{ .ParserType }}:
145+ {{- end }}
118146 if index > -1 {
119147 if index > len (p.data ) {
120148 return errors.ErrIndexOutOfRange
121149 }
122150{{- if .IsInterface }}
123151 p.data = append(p.data , nil )
124152{{- else }}
153+ {{- if not (eq .Model " " ) }}
154+ p.data = append(p.data , models. {{ .Model }}{})
155+ {{- else }}
125156 p.data = append(p.data , types. {{ .ParserType }}{})
157+ {{- end }}
126158{{- end }}
127159 copy(p.data [index +1:], p.data [index :])
128160 p.data [index ] = *newValue
129161 } else {
130162 p.data = append(p.data , *newValue)
131163 }
164+ {{- if not (eq .Model " " ) }}
165+ case models. {{ .Model }}:
166+ {{- else }}
132167 case types. {{ .ParserType }}:
168+ {{- end }}
133169 if index > -1 {
134170 if index > len (p.data ) {
135171 return errors.ErrIndexOutOfRange
136172 }
137173{{- if .IsInterface }}
138174 p.data = append(p.data , nil )
139175{{- else }}
176+ {{- if not (eq .Model " " ) }}
177+ p.data = append(p.data , models. {{ .Model }}{})
178+ {{- else }}
140179 p.data = append(p.data , types. {{ .ParserType }}{})
180+ {{- end }}
141181{{- end }}
142182 copy(p.data [index +1:], p.data [index :])
143183 p.data [index ] = newValue
@@ -160,17 +200,29 @@ func (p *{{ .StructName }}) Set(data common.ParserData, index int) error {
160200 }
161201{{- if .ParserMultiple }}
162202 switch newValue := data. (type) {
203+ {{- if not (eq .Model " " ) }}
204+ case []models. {{ .Model }}:
205+ {{- else }}
163206 case []types. {{ .ParserType }}:
207+ {{- end }}
164208 p.data = newValue
209+ {{- if not (eq .Model " " ) }}
210+ case *models. {{ .Model }}:
211+ {{- else }}
165212 case *types. {{ .ParserType }}:
213+ {{- end }}
166214 if index > -1 && index < len (p.data ) {
167215 p.data [index ] = *newValue
168216 } else if index == -1 {
169217 p.data = append(p.data , *newValue)
170218 } else {
171219 return errors.ErrIndexOutOfRange
172220 }
221+ {{- if not (eq .Model " " ) }}
222+ case models. {{ .Model }}:
223+ {{- else }}
173224 case types. {{ .ParserType }}:
225+ {{- end }}
174226 if index > -1 && index < len (p.data ) {
175227 p.data [index ] = newValue
176228 } else if index == -1 {
@@ -183,9 +235,17 @@ func (p *{{ .StructName }}) Set(data common.ParserData, index int) error {
183235 }
184236{{- else }}
185237 switch newValue := data. (type) {
238+ {{- if not (eq .Model " " ) }}
239+ case *models. {{ .Model }}:
240+ {{- else }}
186241 case *types. {{ .ParserType }}:
242+ {{- end }}
187243 p.data = newValue
244+ {{- if not (eq .Model " " ) }}
245+ case models. {{ .Model }}:
246+ {{- else }}
188247 case types. {{ .ParserType }}:
248+ {{- end }}
189249 p.data = &newValue
190250 default:
191251 return errors.ErrInvalidData
0 commit comments