This topic describes how to use PublishConfig to automatically publish configurations to Nacos, and therefore reduce O&M costs through automation.


You can call the following operation to publish configurations to Nacos.

PublishConfig(param vo.ConfigParam) (bool, error)

Request parameters

Parameter Type Description

Response parameters

Type Description
Boolean Indicates whether the configuration is pushed to Nacos.


Go format

package main

import (

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 {

    var dataId = ""
    var group = "DEFAULT_GROUP"

    //Publish the configuration.
    success, err := configClient.PublishConfig(vo.ConfigParam{
        DataId:  dataId,
        Group:   group,
        Content: "connectTimeoutInMills=3000"})

    if success {
        fmt.Println("Config published successfully.")

    time.Sleep(3 * time.Second)