|
| 1 | +// Code generated by go generate; DO NOT EDIT. |
| 2 | +/* |
| 3 | +Copyright 2019 HAProxy Technologies |
| 4 | + |
| 5 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +you may not use this file except in compliance with the License. |
| 7 | +You may obtain a copy of the License at |
| 8 | + |
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + |
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +*/ |
| 17 | +package parsers |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/haproxytech/config-parser/v5/common" |
| 21 | + "github.com/haproxytech/config-parser/v5/errors" |
| 22 | + "github.com/haproxytech/config-parser/v5/types" |
| 23 | +) |
| 24 | + |
| 25 | +func (p *HTTPErrCodes) Init() { |
| 26 | + p.data = []types.HTTPErrCodes{} |
| 27 | + p.preComments = []string{} |
| 28 | +} |
| 29 | + |
| 30 | +func (p *HTTPErrCodes) GetParserName() string { |
| 31 | + return "http-err-codes" |
| 32 | +} |
| 33 | + |
| 34 | +func (p *HTTPErrCodes) Get(createIfNotExist bool) (common.ParserData, error) { |
| 35 | + if len(p.data) == 0 && !createIfNotExist { |
| 36 | + return nil, errors.ErrFetch |
| 37 | + } |
| 38 | + return p.data, nil |
| 39 | +} |
| 40 | + |
| 41 | +func (p *HTTPErrCodes) GetPreComments() ([]string, error) { |
| 42 | + return p.preComments, nil |
| 43 | +} |
| 44 | + |
| 45 | +func (p *HTTPErrCodes) SetPreComments(preComments []string) { |
| 46 | + p.preComments = preComments |
| 47 | +} |
| 48 | + |
| 49 | +func (p *HTTPErrCodes) GetOne(index int) (common.ParserData, error) { |
| 50 | + if index < 0 || index >= len(p.data) { |
| 51 | + return nil, errors.ErrFetch |
| 52 | + } |
| 53 | + return p.data[index], nil |
| 54 | +} |
| 55 | + |
| 56 | +func (p *HTTPErrCodes) Delete(index int) error { |
| 57 | + if index < 0 || index >= len(p.data) { |
| 58 | + return errors.ErrFetch |
| 59 | + } |
| 60 | + copy(p.data[index:], p.data[index+1:]) |
| 61 | + p.data[len(p.data)-1] = types.HTTPErrCodes{} |
| 62 | + p.data = p.data[:len(p.data)-1] |
| 63 | + return nil |
| 64 | +} |
| 65 | + |
| 66 | +func (p *HTTPErrCodes) Insert(data common.ParserData, index int) error { |
| 67 | + if data == nil { |
| 68 | + return errors.ErrInvalidData |
| 69 | + } |
| 70 | + switch newValue := data.(type) { |
| 71 | + case []types.HTTPErrCodes: |
| 72 | + p.data = newValue |
| 73 | + case *types.HTTPErrCodes: |
| 74 | + if index > -1 { |
| 75 | + if index > len(p.data) { |
| 76 | + return errors.ErrIndexOutOfRange |
| 77 | + } |
| 78 | + p.data = append(p.data, types.HTTPErrCodes{}) |
| 79 | + copy(p.data[index+1:], p.data[index:]) |
| 80 | + p.data[index] = *newValue |
| 81 | + } else { |
| 82 | + p.data = append(p.data, *newValue) |
| 83 | + } |
| 84 | + case types.HTTPErrCodes: |
| 85 | + if index > -1 { |
| 86 | + if index > len(p.data) { |
| 87 | + return errors.ErrIndexOutOfRange |
| 88 | + } |
| 89 | + p.data = append(p.data, types.HTTPErrCodes{}) |
| 90 | + copy(p.data[index+1:], p.data[index:]) |
| 91 | + p.data[index] = newValue |
| 92 | + } else { |
| 93 | + p.data = append(p.data, newValue) |
| 94 | + } |
| 95 | + default: |
| 96 | + return errors.ErrInvalidData |
| 97 | + } |
| 98 | + return nil |
| 99 | +} |
| 100 | + |
| 101 | +func (p *HTTPErrCodes) Set(data common.ParserData, index int) error { |
| 102 | + if data == nil { |
| 103 | + p.Init() |
| 104 | + return nil |
| 105 | + } |
| 106 | + switch newValue := data.(type) { |
| 107 | + case []types.HTTPErrCodes: |
| 108 | + p.data = newValue |
| 109 | + case *types.HTTPErrCodes: |
| 110 | + if index > -1 && index < len(p.data) { |
| 111 | + p.data[index] = *newValue |
| 112 | + } else if index == -1 { |
| 113 | + p.data = append(p.data, *newValue) |
| 114 | + } else { |
| 115 | + return errors.ErrIndexOutOfRange |
| 116 | + } |
| 117 | + case types.HTTPErrCodes: |
| 118 | + if index > -1 && index < len(p.data) { |
| 119 | + p.data[index] = newValue |
| 120 | + } else if index == -1 { |
| 121 | + p.data = append(p.data, newValue) |
| 122 | + } else { |
| 123 | + return errors.ErrIndexOutOfRange |
| 124 | + } |
| 125 | + default: |
| 126 | + return errors.ErrInvalidData |
| 127 | + } |
| 128 | + return nil |
| 129 | +} |
| 130 | + |
| 131 | +func (p *HTTPErrCodes) PreParse(line string, parts []string, preComments []string, comment string) (string, error) { |
| 132 | + changeState, err := p.Parse(line, parts, comment) |
| 133 | + if err == nil && preComments != nil { |
| 134 | + p.preComments = append(p.preComments, preComments...) |
| 135 | + } |
| 136 | + return changeState, err |
| 137 | +} |
| 138 | + |
| 139 | +func (p *HTTPErrCodes) Parse(line string, parts []string, comment string) (string, error) { |
| 140 | + if parts[0] == "http-err-codes" { |
| 141 | + data, err := p.parse(line, parts, comment) |
| 142 | + if err != nil { |
| 143 | + if _, ok := err.(*errors.ParseError); ok { |
| 144 | + return "", err |
| 145 | + } |
| 146 | + return "", &errors.ParseError{Parser: "HTTPErrCodes", Line: line} |
| 147 | + } |
| 148 | + p.data = append(p.data, *data) |
| 149 | + return "", nil |
| 150 | + } |
| 151 | + return "", &errors.ParseError{Parser: "HTTPErrCodes", Line: line} |
| 152 | +} |
| 153 | + |
| 154 | +func (p *HTTPErrCodes) ResultAll() ([]common.ReturnResultLine, []string, error) { |
| 155 | + res, err := p.Result() |
| 156 | + return res, p.preComments, err |
| 157 | +} |
0 commit comments