|
| 1 | +// Copyright 2019 HAProxy Technologies LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package utils |
| 16 | + |
| 17 | +import ( |
| 18 | + "strings" |
| 19 | +) |
| 20 | + |
| 21 | +type Experimental struct { |
| 22 | + UseIngressMerge bool |
| 23 | +} |
| 24 | + |
| 25 | +const ( |
| 26 | + flagSeparator = "," |
| 27 | + // Experimental flags |
| 28 | + flagUseIngressMerge = "use-ingress-merge" |
| 29 | +) |
| 30 | + |
| 31 | +// UnmarshalFlag Unmarshal flag |
| 32 | +func (e *Experimental) UnmarshalFlag(value string) error { |
| 33 | + var errors Errors |
| 34 | + flags := strings.Split(value, flagSeparator) |
| 35 | + |
| 36 | + // Then parse |
| 37 | + for _, flag := range flags { |
| 38 | + if flag == flagUseIngressMerge { |
| 39 | + e.UseIngressMerge = true |
| 40 | + continue |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + return errors.Result() |
| 45 | +} |
| 46 | + |
| 47 | +// MarshalFlag Marshals flag |
| 48 | +func (e Experimental) MarshalFlag() (string, error) { |
| 49 | + flags := []string{} |
| 50 | + if e.UseIngressMerge { |
| 51 | + flags = append(flags, flagUseIngressMerge) |
| 52 | + } |
| 53 | + return strings.Join(flags, flagSeparator), nil |
| 54 | +} |
0 commit comments