| 144 | } |
| 145 | |
| 146 | func (i *imlAPIService) Save(ctx context.Context, id string, model *Edit) error { |
| 147 | if model == nil { |
| 148 | return errors.New("input is nil") |
| 149 | } |
| 150 | return i.apiInfoStore.Transaction(ctx, func(ctx context.Context) error { |
| 151 | ev, err := i.apiInfoStore.GetByUUID(ctx, id) |
| 152 | if err != nil { |
| 153 | return err |
| 154 | } |
| 155 | if model.Name != nil { |
| 156 | ev.Name = *model.Name |
| 157 | } |
| 158 | |
| 159 | if model.Description != nil { |
| 160 | ev.Description = *model.Description |
| 161 | } |
| 162 | if model.Protocols != nil { |
| 163 | ev.Protocol = *model.Protocols |
| 164 | } |
| 165 | if model.Path != nil { |
| 166 | ev.Path = *model.Path |
| 167 | } |
| 168 | if model.Match != nil { |
| 169 | ev.Match = *model.Match |
| 170 | } |
| 171 | if model.Methods != nil { |
| 172 | ev.Method = *model.Methods |
| 173 | } |
| 174 | if model.Disable != nil { |
| 175 | ev.Disable = *model.Disable |
| 176 | } |
| 177 | if model.Upstream != nil { |
| 178 | ev.Upstream = *model.Upstream |
| 179 | } |
| 180 | |
| 181 | e := i.apiInfoStore.Save(ctx, ev) |
| 182 | if e != nil { |
| 183 | return e |
| 184 | } |
| 185 | return i.store.SetLabels(ctx, ev.Id, getLabels(ev)...) |
| 186 | |
| 187 | }) |
| 188 | } |
| 189 | func getLabels(input *api.Info, appends ...string) []string { |
| 190 | labels := make([]string, 0, len(appends)+9) |
| 191 | labels = append(labels, input.UUID, input.Name, input.Description, input.Path, input.Service, input.Team, input.Updater) |