Skip to content

Commit

Permalink
Merge pull request #42 from G-Core/feature/CDN-7567-update-origin-group
Browse files Browse the repository at this point in the history
CDN-7567 transfer originGroup CRUD to new endpoints
  • Loading branch information
MarianaStrix authored Nov 6, 2023
2 parents 381f7be + 0c65761 commit 4eca9f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
9 changes: 4 additions & 5 deletions origingroups/origingroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ type OriginGroupService interface {
type GroupRequest struct {
Name string `json:"name"`
UseNext bool `json:"useNext"`
Origins []OriginRequest `json:"origins"`
Sources []SourceRequest `json:"sources"`
}

type OriginRequest struct {
type SourceRequest struct {
Source string `json:"source"`
Backup bool `json:"backup"`
Enabled bool `json:"enabled"`
Expand All @@ -27,11 +27,10 @@ type OriginGroup struct {
ID int64 `json:"id"`
Name string `json:"name"`
UseNext bool `json:"useNext"`
Origins []Origin `json:"origin_ids"`
Sources []Source `json:"sources"`
}

type Origin struct {
ID int64 `json:"id"`
type Source struct {
Source string `json:"source"`
Backup bool `json:"backup"`
Enabled bool `json:"enabled"`
Expand Down
9 changes: 4 additions & 5 deletions origingroups/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewService(r gcore.Requester) *Service {

func (s *Service) Create(ctx context.Context, req *GroupRequest) (*OriginGroup, error) {
var group OriginGroup
if err := s.r.Request(ctx, http.MethodPost, "/cdn/originGroups", req, &group); err != nil {
if err := s.r.Request(ctx, http.MethodPost, "/cdn/origin_groups", req, &group); err != nil {
return nil, fmt.Errorf("request: %w", err)
}

Expand All @@ -29,7 +29,7 @@ func (s *Service) Create(ctx context.Context, req *GroupRequest) (*OriginGroup,

func (s *Service) Get(ctx context.Context, id int64) (*OriginGroup, error) {
var group OriginGroup
if err := s.r.Request(ctx, http.MethodGet, fmt.Sprintf("/cdn/originGroups/%d", id), nil, &group); err != nil {
if err := s.r.Request(ctx, http.MethodGet, fmt.Sprintf("/cdn/origin_groups/%d", id), nil, &group); err != nil {
return nil, fmt.Errorf("request: %w", err)
}

Expand All @@ -38,16 +38,15 @@ func (s *Service) Get(ctx context.Context, id int64) (*OriginGroup, error) {

func (s *Service) Update(ctx context.Context, id int64, req *GroupRequest) (*OriginGroup, error) {
var group OriginGroup
if err := s.r.Request(ctx, http.MethodPut, fmt.Sprintf("/cdn/originGroups/%d", id), req, &group); err != nil {
if err := s.r.Request(ctx, http.MethodPut, fmt.Sprintf("/cdn/origin_groups/%d", id), req, &group); err != nil {
return nil, fmt.Errorf("request: %w", err)
}

return &group, nil
}

func (s *Service) Delete(ctx context.Context, id int64) error {
if err := s.r.Request(ctx, http.MethodDelete, fmt.Sprintf("/cdn/originGroups/%d", id), nil, nil); err != nil {

if err := s.r.Request(ctx, http.MethodDelete, fmt.Sprintf("/cdn/origin_groups/%d", id), nil, nil); err != nil {
return fmt.Errorf("request: %w", err)
}

Expand Down

0 comments on commit 4eca9f9

Please sign in to comment.