The CDN service provides comprehensive content delivery network functionality, including resource management, caching configuration, SSL/TLS certificates, origin shielding, and detailed analytics.
Service Structure
The CDN service is organized into several key areas:
CDN Resources - Create and manage CDN resources with customizable caching and delivery options
Origin Groups - Configure origin servers with failover and load balancing
SSL Certificates - Manage HTTPS certificates with automated Let’s Encrypt provisioning
Rules - Apply custom caching, security, and delivery rules to specific URL patterns
Logs - Access CDN operation logs for monitoring and troubleshooting
Statistics - View consumption metrics and performance data
Shields - Configure origin shielding to reduce origin server load
Initialize the Client
import (
" github.com/G-Core/gcore-go "
" github.com/G-Core/gcore-go/cdn "
)
// Create client - API key is read from GCORE_API_KEY environment variable
client := gcore . NewClient ()
// Or specify API key explicitly
client := gcore . NewClient (
option . WithAPIKey ( "your-api-key" ),
)
Get Account Overview
Retrieve information about your CDN service account.
account , err := client . CDN . GetAccountOverview ( context . Background ())
if err != nil {
log . Fatal ( err )
}
fmt . Printf ( "Account ID: %d \n " , account . ID )
fmt . Printf ( "Service Status: %s \n " , account . Service . Status )
fmt . Printf ( "CNAME: %s \n " , account . Cname )
Domain zone to which CNAME records should be pointed
CDN service status information Whether the CDN service is activated
Service status: new, trial, trialend, activating, active, paused, or deleted
Whether resources will be deactivated automatically by inactivity
CDN traffic usage limit in gigabytes. Email notification sent when limit is reached
Get Account Limits
Retrieve service limits for your account.
limits , err := client . CDN . GetAccountLimits ( context . Background ())
if err != nil {
log . Fatal ( err )
}
fmt . Printf ( "Resources Limit: %d \n " , limits . ResourcesLimit )
fmt . Printf ( "Rules Limit: %d \n " , limits . RulesLimit )
Maximum number of CDN resources that can be created
Maximum number of rules per CDN resource
Maximum number of origins per origin group
secondary_hostnames_limit
Maximum number of secondary hostnames (additional CNAMEs) per resource
Get Available Features
Retrieve available CDN features for your account.
features , err := client . CDN . GetAvailableFeatures ( context . Background ())
if err != nil {
log . Fatal ( err )
}
for _ , feature := range features . FreeFeatures {
fmt . Printf ( "Free Feature: %s (ID: %d ) \n " , feature . Name , feature . FeatureID )
}
for _ , feature := range features . PaidFeatures {
fmt . Printf ( "Paid Feature: %s (ID: %d ) \n " , feature . Name , feature . FeatureID )
}
Purge Operations
List Purge Statuses
Get the history of cache purge requests.
params := cdn . CDNListPurgeStatusesParams {
Cname : param . NewOpt ( "cdn.example.com" ),
FromCreated : param . NewOpt ( "2024-01-01T00:00:00Z" ),
ToCreated : param . NewOpt ( "2024-01-31T23:59:59Z" ),
Status : param . NewOpt ( "Successful" ),
}
statuses , err := client . CDN . ListPurgeStatuses ( context . Background (), params )
if err != nil {
log . Fatal ( err )
}
for _ , status := range * statuses {
fmt . Printf ( "Purge ID: %d , Type: %s , Status: %s \n " ,
status . PurgeID , status . PurgeType , status . Status )
}
Filter by CDN resource CNAME
Start date/time of the period (ISO 8601 format, UTC)
End date/time of the period (ISO 8601 format, UTC)
Filter by purge type: purge_by_pattern, purge_by_url, or purge_all
Filter by status: In progress, Successful, Failed, or Status report disabled
List AWS Regions
regions , err := client . CDN . ListAwsRegions ( context . Background ())
if err != nil {
log . Fatal ( err )
}
for _ , region := range * regions {
fmt . Printf ( " %s : %s ( %d ) \n " , region . Code , region . Name , region . ID )
}
List Alibaba Regions
regions , err := client . CDN . ListAlibabaRegions ( context . Background ())
if err != nil {
log . Fatal ( err )
}
for _ , region := range * regions {
fmt . Printf ( " %s : %s ( %d ) \n " , region . Code , region . Name , region . ID )
}
Update Account Settings
Modify your CDN account configuration.
params := cdn . CDNUpdateAccountParams {
UtilizationLevel : param . NewOpt [ int64 ]( 10000 ), // 10TB limit
}
account , err := client . CDN . UpdateAccount ( context . Background (), params )
if err != nil {
log . Fatal ( err )
}
fmt . Printf ( "Updated utilization level: %d GB \n " , account . UtilizationLevel )
CDN traffic usage limit in gigabytes. Email notification will be sent when the limit is reached
CDN Resources Manage CDN resources and delivery configurations
Resource Rules Configure custom rules for URL patterns
SSL Certificates Manage SSL/TLS certificates for HTTPS delivery
CDN Logs Access and download CDN operation logs