github.com/NaverCloudPlatform/ncloud-sdk-go-v2@v1.6.13/services/vnks/configuration.go (about)

     1  /*
     2   * vnks
     3   *
     4   * <br/>https://nks.apigw.ntruss.com/vnks/v2
     5   *
     6   * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
     7   */
     8  
     9  package vnks
    10  
    11  import (
    12  	"fmt"
    13  	"github.com/NaverCloudPlatform/ncloud-sdk-go-v2/ncloud"
    14  	"os"
    15  	"strings"
    16  )
    17  
    18  // contextKeys are used to identify the type of value in the context.
    19  // Since these are string, it is possible to get a short description of the
    20  // context key for logging and debugging using key.String().
    21  
    22  type contextKey string
    23  
    24  func (c contextKey) String() string {
    25  	return "auth " + string(c)
    26  }
    27  
    28  func NewConfiguration(region string, apiKeys ...*ncloud.APIKey) *ncloud.Configuration {
    29  	cfg := &ncloud.Configuration{
    30  		BasePath:      "https://nks.apigw.ntruss.com/vnks/v2",
    31  		DefaultHeader: make(map[string]string),
    32  		UserAgent:     "vnks/1.0.0/go",
    33  	}
    34  	if len(apiKeys) > 0 {
    35  		cfg.APIKey = apiKeys[0]
    36  	}
    37  	cfg.InitCredentials()
    38  
    39  	var ncloudApiGw string
    40  	if os.Getenv("NCLOUD_API_GW") == "" {
    41  		ncloudApiGw = "https://nks.apigw.ntruss.com"
    42  	} else {
    43  		ncloudApiGw = os.Getenv("NCLOUD_API_GW")
    44  	}
    45  
    46  	ncloudApiGw = strings.Replace(ncloudApiGw, "https://ncloud.", "https://nks.", 1)
    47  	ncloudApiGw = strings.Replace(ncloudApiGw, "https://fin-ncloud.", "https://nks.", 1)
    48  
    49  	switch {
    50  	case strings.HasPrefix(region, "F"):
    51  		cfg.BasePath = fmt.Sprintf("%s/nks/v2", ncloudApiGw)
    52  	case region == "KR", strings.Contains(region, "CS"):
    53  		cfg.BasePath = fmt.Sprintf("%s/vnks/v2", ncloudApiGw)
    54  	default:
    55  		cfg.BasePath = fmt.Sprintf("%s/vnks/%s-v2", ncloudApiGw, strings.ToLower(region))
    56  	}
    57  
    58  	cfg.DefaultHeader["x-ncp-region_code"] = region
    59  
    60  	return cfg
    61  }
    62  
    63  func NewConfigurationWithUserAgent(region string, userAgent string, apiKeys ...*ncloud.APIKey) *ncloud.Configuration {
    64  	cfg := NewConfiguration(region, apiKeys...)
    65  	cfg.UserAgent = userAgent
    66  
    67  	return cfg
    68  }