github.com/NaverCloudPlatform/ncloud-sdk-go-v2@v1.6.13/services/vses/configuration.go (about) 1 /* 2 * api 3 * 4 * Search Engine Service(VPC) Open API<br/>https://vpcsearchengine.apigw.ntruss.com/api/v1 5 * 6 * API version: 2022-04-21T09:07:51Z 7 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 8 */ 9 10 package vses 11 12 import ( 13 "fmt" 14 "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/ncloud" 15 "os" 16 "strings" 17 ) 18 19 // contextKeys are used to identify the type of value in the context. 20 // Since these are string, it is possible to get a short description of the 21 // context key for logging and debugging using key.String(). 22 23 type contextKey string 24 25 func (c contextKey) String() string { 26 return "auth " + string(c) 27 } 28 29 func NewConfiguration(region string, apiKeys ...*ncloud.APIKey) *ncloud.Configuration { 30 cfg := &ncloud.Configuration{ 31 BasePath: "https://vpcsearchengine.apigw.ntruss.com/api/v1", 32 DefaultHeader: make(map[string]string), 33 UserAgent: "vses//go", 34 } 35 if len(apiKeys) > 0 { 36 cfg.APIKey = apiKeys[0] 37 } 38 cfg.InitCredentials() 39 40 var ncloudApiGw string 41 if os.Getenv("NCLOUD_API_GW") == "" { 42 ncloudApiGw = "https://vpcsearchengine.apigw.ntruss.com" 43 } else { 44 ncloudApiGw = os.Getenv("NCLOUD_API_GW") 45 } 46 47 ncloudApiGw = strings.Replace(ncloudApiGw, "https://ncloud.", "https://vpcsearchengine.", 1) 48 ncloudApiGw = strings.Replace(ncloudApiGw, "https://fin-ncloud.", "https://fin-vpcsearchengine.", 1) 49 50 switch region { 51 case "KR": // 민간, 공공-수도권 52 cfg.BasePath = fmt.Sprintf("%s/api/v1", ncloudApiGw) 53 case "FKR": // 금융 54 cfg.BasePath = fmt.Sprintf("%s/api/v1", ncloudApiGw) 55 default: // 민간-싱가폴, 공공-남부권 56 cfg.BasePath = fmt.Sprintf("%s/api/%s-v1", ncloudApiGw, strings.ToLower(region)) 57 } 58 return cfg 59 }