@@ -125,7 +125,7 @@ type ProtoTrace struct {
125125func (pt * ProtoTrace ) UnmarshalText (b []byte ) error {
126126 lines := strings .Split (string (b ), "\n " )
127127 for _ , line := range lines {
128- if matches , matched := checkForDataPathActions ( line ); matched {
128+ if matches , matched := checkMatch ( datapathActionsRegexp , line ); matched {
129129 // first index is always the left most match, following
130130 // are the actual matches
131131 pt .DataPathActions = & dataPathActions {
@@ -135,7 +135,7 @@ func (pt *ProtoTrace) UnmarshalText(b []byte) error {
135135 continue
136136 }
137137
138- if matches , matched := checkForInputFlow ( line ); matched {
138+ if matches , matched := checkMatch ( initialFlowRegexp , line ); matched {
139139 flow := & DataPathFlows {}
140140 err := flow .UnmarshalText ([]byte (matches [1 ]))
141141 if err != nil {
@@ -146,7 +146,7 @@ func (pt *ProtoTrace) UnmarshalText(b []byte) error {
146146 continue
147147 }
148148
149- if matches , matched := checkForFinalFlow ( line ); matched {
149+ if matches , matched := checkMatch ( finalFlowRegexp , line ); matched {
150150 flow := & DataPathFlows {}
151151 err := flow .UnmarshalText ([]byte (matches [1 ]))
152152 if err != nil {
@@ -157,19 +157,19 @@ func (pt *ProtoTrace) UnmarshalText(b []byte) error {
157157 continue
158158 }
159159
160- if _ , matched := checkForMegaFlow ( line ); matched {
160+ if _ , matched := checkMatch ( megaFlowRegexp , line ); matched {
161161 continue
162162 }
163163
164- if _ , matched := checkForTraceStart ( line ); matched {
164+ if _ , matched := checkMatch ( traceStartRegexp , line ); matched {
165165 continue
166166 }
167167
168- if _ , matched := checkForTraceFlow ( line ); matched {
168+ if _ , matched := checkMatch ( traceFlowRegexp , line ); matched {
169169 continue
170170 }
171171
172- if matches , matched := checkForTraceAction ( line ); matched {
172+ if matches , matched := checkMatch ( traceActionRegexp , line ); matched {
173173 pt .FlowActions = append (pt .FlowActions , matches [1 ])
174174 continue
175175 }
@@ -178,62 +178,8 @@ func (pt *ProtoTrace) UnmarshalText(b []byte) error {
178178 return nil
179179}
180180
181- func checkForDataPathActions (s string ) ([]string , bool ) {
182- matches := datapathActionsRegexp .FindStringSubmatch (s )
183- if len (matches ) == 0 {
184- return matches , false
185- }
186-
187- return matches , true
188- }
189-
190- func checkForInputFlow (s string ) ([]string , bool ) {
191- matches := initialFlowRegexp .FindStringSubmatch (s )
192- if len (matches ) == 0 {
193- return matches , false
194- }
195-
196- return matches , true
197- }
198-
199- func checkForFinalFlow (s string ) ([]string , bool ) {
200- matches := finalFlowRegexp .FindStringSubmatch (s )
201- if len (matches ) == 0 {
202- return matches , false
203- }
204-
205- return matches , true
206- }
207-
208- func checkForMegaFlow (s string ) ([]string , bool ) {
209- matches := megaFlowRegexp .FindStringSubmatch (s )
210- if len (matches ) == 0 {
211- return matches , false
212- }
213-
214- return matches , true
215- }
216-
217- func checkForTraceStart (s string ) ([]string , bool ) {
218- matches := traceStartRegexp .FindStringSubmatch (s )
219- if len (matches ) == 0 {
220- return matches , false
221- }
222-
223- return matches , true
224- }
225-
226- func checkForTraceFlow (s string ) ([]string , bool ) {
227- matches := traceFlowRegexp .FindStringSubmatch (s )
228- if len (matches ) == 0 {
229- return matches , false
230- }
231-
232- return matches , true
233- }
234-
235- func checkForTraceAction (s string ) ([]string , bool ) {
236- matches := traceActionRegexp .FindStringSubmatch (s )
181+ func checkMatch (re * regexp.Regexp , s string ) ([]string , bool ) {
182+ matches := re .FindStringSubmatch (s )
237183 if len (matches ) == 0 {
238184 return matches , false
239185 }
0 commit comments