@@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"bytes"
5
+ "encoding/json"
5
6
"errors"
6
7
"fmt"
7
8
"github.com/BurntSushi/toml"
@@ -112,8 +113,12 @@ func ParseApiSettings(api *Api, line []byte) (bool, error) {
112
113
}
113
114
114
115
func ParseRoute (line []byte ) (* Route , error ) {
115
- route := & Route {Versions : make (map [int ]* RouteVersion )}
116
- chunks := bytes .Split (line , []byte ("," ))
116
+ route := & Route {
117
+ Versions : make (map [int ]* RouteVersion ),
118
+ PluginPipelines : make ([]* PluginPipeline , 0 ),
119
+ }
120
+ pipelines := bytes .Split (line , []byte ("|" ))
121
+ chunks := bytes .Split (pipelines [0 ], []byte ("," ))
117
122
urlParams := bytes .Split (chunks [0 ], []byte (" " ))
118
123
route .Method = strings .ToUpper (string (urlParams [0 ]))
119
124
route .Path = string (urlParams [1 ])
@@ -139,9 +144,38 @@ func ParseRoute(line []byte) (*Route, error) {
139
144
}
140
145
}
141
146
}
147
+ if len (pipelines ) > 0 {
148
+ for i := 1 ; i < len (pipelines ); i ++ {
149
+ pipeline := pipelines [i ]
150
+ pluginPipeline , err := ParsePluginPipeline (pipeline )
151
+ if err != nil {
152
+ return nil , err
153
+ }
154
+ route .PluginPipelines = append (route .PluginPipelines , pluginPipeline )
155
+ }
156
+ }
142
157
return route , nil
143
158
}
144
159
160
+ func ParsePluginPipeline (content []byte ) (* PluginPipeline , error ) {
161
+ content = bytes .TrimSpace (content )
162
+ chunks := bytes .Split (content , []byte (" " ))
163
+ if len (chunks ) == 0 {
164
+ return nil , errors .New ("Plugin name not supplied in pipeline" )
165
+ }
166
+ pp := & PluginPipeline {Name : string (chunks [0 ])}
167
+ if len (chunks ) == 1 {
168
+ return pp , nil
169
+ }
170
+ jsonContent := bytes .Join (chunks [1 :], []byte (" " ))
171
+ arg := make (map [string ]interface {})
172
+ err := json .Unmarshal (jsonContent , & arg )
173
+ if err != nil {
174
+ return nil , err
175
+ }
176
+ pp .Argument = arg
177
+ return pp , nil
178
+ }
145
179
func ParseSchema (path string , route * Route ) error {
146
180
files , err := filepath .Glob (path + "/schemas/" + route .Name + ".v[0-9]*.schema" )
147
181
if err != nil {
0 commit comments