-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
CDI-468: add origin shielding
- Loading branch information
Showing
3 changed files
with
88 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package originshielding | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type OriginShieldingService interface { | ||
Update(ctx context.Context, id int64, req *UpdateRequest) (*OriginShieldingData, error) | ||
Get(ctx context.Context, id int64) (*OriginShieldingData, error) | ||
GetLocations(ctx context.Context) (*OriginShieldingLocations, error) | ||
} | ||
|
||
type OriginShieldingData struct { | ||
ShieldingPop int `json:"shielding_pop"` | ||
} | ||
|
||
type UpdateRequest struct { | ||
ShieldingPop int `json:"shielding_pop"` | ||
} | ||
|
||
type OriginShieldingLocations struct { | ||
ID int `json:"id"` | ||
Datacenter string `json:"datacenter"` | ||
Country string `json:"country"` | ||
City string `json:"city"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package originshielding | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/G-Core/gcorelabscdn-go/gcore" | ||
"net/http" | ||
) | ||
|
||
var _ OriginShieldingService = (*Service)(nil) | ||
|
||
type Service struct { | ||
r gcore.Requester | ||
} | ||
|
||
func NewService(r gcore.Requester) *Service { | ||
return &Service{r: r} | ||
} | ||
|
||
func (s *Service) Update(ctx context.Context, id int64, req *UpdateRequest) (*OriginShieldingData, error) { | ||
var origin_shielding OriginShieldingData | ||
if err := s.r.Request(ctx, http.MethodPut, fmt.Sprintf("/cdn/resources/%d/shielding_v2", id), req, &origin_shielding); err != nil { | ||
return nil, fmt.Errorf("request: %w", err) | ||
} | ||
return &origin_shielding, nil | ||
} | ||
|
||
func (s *Service) Get(ctx context.Context, id int64) (*OriginShieldingData, error) { | ||
var origin_shielding OriginShieldingData | ||
if err := s.r.Request(ctx, http.MethodGet, fmt.Sprintf("/cdn/resources/%d/shielding_v2", id), nil, &origin_shielding); err != nil { | ||
return nil, fmt.Errorf("request: %w", err) | ||
} | ||
|
||
return &origin_shielding, nil | ||
|
||
} | ||
|
||
func (s *Service) GetLocations(ctx context.Context) (*OriginShieldingLocations, error) { | ||
var origin_shielding_locations OriginShieldingLocations | ||
if err := s.r.Request(ctx, http.MethodGet, "/cdn/shieldingpop_v2", nil, &origin_shielding_locations); err != nil { | ||
return nil, fmt.Errorf("request: %w", err) | ||
} | ||
|
||
return &origin_shielding_locations, nil | ||
} |