This topic describes how to use GetConfig to get the values of configuration items from Nacos.
Description
You can call the following operation to get the values of configuration items from Nacos:
GetConfig(param vo.ConfigParam) (string, error)
Request parameters
Parameter | Type | Description |
---|---|---|
Response parameters
Type | Description |
---|---|
String | Indicates the values of configuration items in Nacos. |
Examples
Go
format
package main
import (
"fmt"
"github.com/nacos-group/nacos-sdk-go/clients"
"github.com/nacos-group/nacos-sdk-go/common/constant"
"github.com/nacos-group/nacos-sdk-go/vo"
"time"
)
func main() {
//Use the values of End Point and Namespace ID on the Namespace Details page.
var endpoint = "${endpoint}"
var namespaceId = "${namespaceId}"
//Use the AccessKey ID and AccessKey secret of the RAM user.
var accessKey = "${accessKey}"
var secretKey = "${secretKey}"
clientConfig := constant.ClientConfig{
//
Endpoint: endpoint + ":8080",
NamespaceId: namespaceId,
AccessKey: accessKey,
SecretKey: secretKey,
TimeoutMs: 5 * 1000,
ListenInterval: 30 * 1000,
}
configClient, err := clients.CreateConfigClient(map[string]interface{}{
"clientConfig": clientConfig,
})
if err ! = nil {
fmt.Println(err)
return
}
var dataId = "com.alibaba.nacos.example.properties"
var group = "DEFAULT_GROUP"
//Get the configuration.
content, err := configClient.GetConfig(vo.ConfigParam{
DataId: dataId,
Group: group})
fmt.Println("Get config:" + content)
}