newGroupResponse creates a new GroupResponse from a models.Group.
(group *models.Group)
| 270 | |
| 271 | // newGroupResponse creates a new GroupResponse from a models.Group. |
| 272 | func (s *Server) newGroupResponse(group *models.Group) *GroupResponse { |
| 273 | appURL := s.SettingsManager.GetAppUrl() |
| 274 | endpoint := "" |
| 275 | if appURL != "" { |
| 276 | u, err := url.Parse(appURL) |
| 277 | if err == nil { |
| 278 | u.Path = strings.TrimRight(u.Path, "/") + "/proxy/" + group.Name |
| 279 | endpoint = u.String() |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | // Parse header rules from JSON |
| 284 | var headerRules []models.HeaderRule |
| 285 | if len(group.HeaderRules) > 0 { |
| 286 | if err := json.Unmarshal(group.HeaderRules, &headerRules); err != nil { |
| 287 | logrus.WithError(err).Error("Failed to unmarshal header rules") |
| 288 | headerRules = make([]models.HeaderRule, 0) |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | return &GroupResponse{ |
| 293 | ID: group.ID, |
| 294 | Name: group.Name, |
| 295 | Endpoint: endpoint, |
| 296 | DisplayName: group.DisplayName, |
| 297 | Description: group.Description, |
| 298 | GroupType: group.GroupType, |
| 299 | Upstreams: group.Upstreams, |
| 300 | ChannelType: group.ChannelType, |
| 301 | Sort: group.Sort, |
| 302 | TestModel: group.TestModel, |
| 303 | ValidationEndpoint: group.ValidationEndpoint, |
| 304 | ParamOverrides: group.ParamOverrides, |
| 305 | ModelRedirectRules: group.ModelRedirectRules, |
| 306 | ModelRedirectStrict: group.ModelRedirectStrict, |
| 307 | Config: group.Config, |
| 308 | HeaderRules: headerRules, |
| 309 | ProxyKeys: group.ProxyKeys, |
| 310 | LastValidatedAt: group.LastValidatedAt, |
| 311 | CreatedAt: group.CreatedAt, |
| 312 | UpdatedAt: group.UpdatedAt, |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | // DeleteGroup handles deleting a group. |
| 317 | func (s *Server) DeleteGroup(c *gin.Context) { |
no test coverage detected