@@ -10,6 +10,8 @@ import (
1010 "time"
1111
1212 "github.com/incubator4/go-resty-expr/expr"
13+
14+ "github.com/api7/api7-ingress-controller/api/common"
1315)
1416
1517const (
@@ -113,16 +115,16 @@ type Service struct {
113115type Route struct {
114116 Metadata `json:",inline" yaml:",inline"`
115117
116- EnableWebsocket * bool `json:"enable_websocket,omitempty" yaml:"enable_websocket,omitempty"`
117- FilterFunc string `json:"filter_func,omitempty" yaml:"filter_func,omitempty"`
118- Hosts []string `json:"hosts,omitempty" yaml:"hosts,omitempty"`
119- Methods []string `json:"methods,omitempty" yaml:"methods,omitempty"`
120- Plugins Plugins `json:"plugins,omitempty" yaml:"plugins,omitempty"`
121- Priority * int64 `json:"priority,omitempty" yaml:"priority,omitempty"`
122- RemoteAddrs []string `json:"remote_addrs,omitempty" yaml:"remote_addrs,omitempty"`
123- Timeout * Timeout `json:"timeout,omitempty" yaml:"timeout,omitempty"`
124- Uris []string `json:"uris" yaml:"uris"`
125- Vars Vars `json:"vars,omitempty" yaml:"vars,omitempty"`
118+ EnableWebsocket * bool `json:"enable_websocket,omitempty" yaml:"enable_websocket,omitempty"`
119+ FilterFunc string `json:"filter_func,omitempty" yaml:"filter_func,omitempty"`
120+ Hosts []string `json:"hosts,omitempty" yaml:"hosts,omitempty"`
121+ Methods []string `json:"methods,omitempty" yaml:"methods,omitempty"`
122+ Plugins Plugins `json:"plugins,omitempty" yaml:"plugins,omitempty"`
123+ Priority * int64 `json:"priority,omitempty" yaml:"priority,omitempty"`
124+ RemoteAddrs []string `json:"remote_addrs,omitempty" yaml:"remote_addrs,omitempty"`
125+ Timeout * Timeout `json:"timeout,omitempty" yaml:"timeout,omitempty"`
126+ Uris []string `json:"uris" yaml:"uris"`
127+ Vars common. Vars `json:"vars,omitempty" yaml:"vars,omitempty"`
126128}
127129
128130type Timeout struct {
@@ -325,62 +327,6 @@ func (n *UpstreamNodes) UnmarshalJSON(p []byte) error {
325327 return nil
326328}
327329
328- // Vars represents the route match expressions of APISIX.
329- type Vars [][]StringOrSlice
330-
331- // UnmarshalJSON implements json.Unmarshaler interface.
332- // lua-cjson doesn't distinguish empty array and table,
333- // and by default empty array will be encoded as '{}'.
334- // We have to maintain the compatibility.
335- func (vars * Vars ) UnmarshalJSON (p []byte ) error {
336- if p [0 ] == '{' {
337- if len (p ) != 2 {
338- return errors .New ("unexpected non-empty object" )
339- }
340- return nil
341- }
342- var data [][]StringOrSlice
343- if err := json .Unmarshal (p , & data ); err != nil {
344- return err
345- }
346- * vars = data
347- return nil
348- }
349-
350- // StringOrSlice represents a string or a string slice.
351- // TODO Do not use interface{} to avoid the reflection overheads.
352- type StringOrSlice struct {
353- StrVal string `json:"-"`
354- SliceVal []string `json:"-"`
355- }
356-
357- func (s * StringOrSlice ) MarshalJSON () ([]byte , error ) {
358- var (
359- p []byte
360- err error
361- )
362- if s .SliceVal != nil {
363- p , err = json .Marshal (s .SliceVal )
364- } else {
365- p , err = json .Marshal (s .StrVal )
366- }
367- return p , err
368- }
369-
370- func (s * StringOrSlice ) UnmarshalJSON (p []byte ) error {
371- var err error
372-
373- if len (p ) == 0 {
374- return errors .New ("empty object" )
375- }
376- if p [0 ] == '[' {
377- err = json .Unmarshal (p , & s .SliceVal )
378- } else {
379- err = json .Unmarshal (p , & s .StrVal )
380- }
381- return err
382- }
383-
384330// ComposeRouteName uses namespace, name and rule name to compose
385331// the route name.
386332func ComposeRouteName (namespace , name string , rule string ) string {
0 commit comments