代码拉取完成,页面将自动刷新
package basic
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"github.com/sensu/sensu-go/types"
)
// SaveAPIUrl saves the API URL into a configuration file
func (c *Config) SaveAPIUrl(url string) error {
c.Cluster.APIUrl = url
return write(c.Cluster, filepath.Join(c.path, clusterFilename))
}
// SaveFormat saves the user's format preference into a configuration file
func (c *Config) SaveFormat(format string) error {
c.Profile.Format = format
return write(c.Profile, filepath.Join(c.path, profileFilename))
}
// SaveNamespace saves the user's default namespace to a configuration file
func (c *Config) SaveNamespace(namespace string) error {
c.Profile.Namespace = namespace
return write(c.Profile, filepath.Join(c.path, profileFilename))
}
// SaveTokens saves the JWT into a configuration file
func (c *Config) SaveTokens(tokens *types.Tokens) error {
// Update the configuration loaded in memory
c.Cluster.Tokens = tokens
// Load the configuration from the file so we don't save any configuration
// that was overrided with a configuration flag
savedConfig := &Config{}
_ = savedConfig.open(filepath.Join(c.path, clusterFilename))
savedConfig.Cluster.Tokens = tokens
return write(savedConfig.Cluster, filepath.Join(c.path, clusterFilename))
}
func write(data interface{}, path string) error {
// Make sure the directory exists
dir := filepath.Dir(path)
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return err
}
bytes, err := json.MarshalIndent(data, "", " ")
if err != nil {
return err
}
return ioutil.WriteFile(path, bytes, 0644)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。