本文整理汇总了Golang中github.com/rancherio/os/config.LoadConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang LoadConfig函数的具体用法?Golang LoadConfig怎么用?Golang LoadConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LoadConfig函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RunInit
func RunInit() error {
var cfg config.CloudConfig
os.Setenv("PATH", "/sbin:/usr/sbin:/usr/bin")
// Magic setting to tell Docker to do switch_root and not pivot_root
os.Setenv("DOCKER_RAMDISK", "true")
initFuncs := []config.InitFunc{
func(cfg *config.CloudConfig) error {
return dockerlaunch.PrepareFs(&mountConfig)
},
func(cfg *config.CloudConfig) error {
newCfg, err := config.LoadConfig()
if err == nil {
newCfg, err = config.LoadConfig()
}
if err == nil {
*cfg = *newCfg
}
if cfg.Rancher.Debug {
cfgString, err := config.Dump(false, true)
if err != nil {
log.WithFields(log.Fields{"err": err}).Error("Error serializing config")
} else {
log.Debugf("Config: %s", cfgString)
}
}
return err
},
loadModules,
tryMountAndBootstrap,
func(cfg *config.CloudConfig) error {
return cfg.Reload()
},
loadModules,
sysInit,
}
if err := config.RunInitFuncs(&cfg, initFuncs); err != nil {
return err
}
launchConfig, args := getLaunchConfig(&cfg, &cfg.Rancher.SystemDocker)
log.Info("Launching System Docker")
_, err := dockerlaunch.LaunchDocker(launchConfig, config.DOCKER_BIN, args...)
return err
}
开发者ID:clhudson2,项目名称:os,代码行数:50,代码来源:init.go
示例2: configGet
func configGet(c *cli.Context) {
arg := c.Args().Get(0)
if arg == "" {
return
}
cfg, err := config.LoadConfig()
if err != nil {
log.WithFields(log.Fields{"err": err}).Fatal("config get: failed to load config")
}
val, err := cfg.Get(arg)
if err != nil {
log.WithFields(log.Fields{"cfg": cfg, "key": arg, "val": val, "err": err}).Fatal("config get: failed to retrieve value")
}
printYaml := false
switch val.(type) {
case []interface{}:
printYaml = true
case map[interface{}]interface{}:
printYaml = true
}
if printYaml {
bytes, err := yaml.Marshal(val)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(bytes))
} else {
fmt.Println(val)
}
}
开发者ID:rowhit,项目名称:os,代码行数:34,代码来源:config.go
示例3: reload
func reload(c *cli.Context) {
_, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
containers := map[string]*docker.Container{} //parseContainers(cfg)
toStart := make([]*docker.Container, 0, len(c.Args()))
for _, id := range c.Args() {
if container, ok := containers[id]; ok {
toStart = append(toStart, container.Stage())
}
}
var firstErr error
for _, c := range toStart {
err := c.Start().Err
if err != nil {
log.Errorf("Failed to start %s : %v", c.ContainerCfg.Id, err)
if firstErr != nil {
firstErr = err
}
}
}
if firstErr != nil {
log.Fatal(firstErr)
}
}
开发者ID:jgatkinsn,项目名称:os,代码行数:30,代码来源:reload.go
示例4: Generate
func Generate(generateServer bool, outDir string, hostnames []string) error {
cfg, err := config.LoadConfig()
if err != nil {
return err
}
if outDir == "" {
return fmt.Errorf("out directory (-d, --dir) not specified")
}
caCertPath := filepath.Join(outDir, "ca.pem")
caKeyPath := filepath.Join(outDir, "ca-key.pem")
certPath := filepath.Join(outDir, "cert.pem")
keyPath := filepath.Join(outDir, "key.pem")
if generateServer {
certPath = filepath.Join(outDir, "server-cert.pem")
keyPath = filepath.Join(outDir, "server-key.pem")
}
if _, err := os.Stat(outDir); os.IsNotExist(err) {
if err := os.MkdirAll(outDir, 0700); err != nil {
return err
}
}
if err := writeCaCerts(cfg, caCertPath, caKeyPath); err != nil {
return err
}
return writeCerts(generateServer, hostnames, cfg, certPath, keyPath, caCertPath, caKeyPath)
}
开发者ID:rowhit,项目名称:os,代码行数:31,代码来源:tlsconf.go
示例5: generate
func generate(c *cli.Context) error {
cfg, err := config.LoadConfig()
if err != nil {
return err
}
generateServer := c.Bool("server")
outDir := c.String("dir")
if outDir == "" {
return fmt.Errorf("out directory (-d, --dir) not specified")
}
caCertPath := filepath.Join(outDir, "ca.pem")
caKeyPath := filepath.Join(outDir, "ca-key.pem")
certPath := filepath.Join(outDir, "cert.pem")
keyPath := filepath.Join(outDir, "key.pem")
if generateServer {
certPath = filepath.Join(outDir, "server-cert.pem")
keyPath = filepath.Join(outDir, "server-key.pem")
}
if _, err := os.Stat(outDir); os.IsNotExist(err) {
if err := os.MkdirAll(outDir, 0700); err != nil {
return err
}
}
if err := writeCaCerts(cfg, caCertPath, caKeyPath); err != nil {
return err
}
hostnames := c.StringSlice("hostname")
return writeCerts(generateServer, hostnames, cfg, certPath, keyPath, caCertPath, caKeyPath)
}
开发者ID:jgatkinsn,项目名称:os,代码行数:34,代码来源:tlsconf.go
示例6: envAction
func envAction(c *cli.Context) {
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
args := c.Args()
if len(args) == 0 {
return
}
osEnv := os.Environ()
envMap := make(map[string]string, len(cfg.Rancher.Environment)+len(osEnv))
for k, v := range cfg.Rancher.Environment {
envMap[k] = v
}
for k, v := range util.KVPairs2Map(osEnv) {
envMap[k] = v
}
if cmd, err := exec.LookPath(args[0]); err != nil {
log.Fatal(err)
} else {
args[0] = cmd
}
if err := syscall.Exec(args[0], args, util.Map2KVPairs(envMap)); err != nil {
log.Fatal(err)
}
}
开发者ID:rowhit,项目名称:os,代码行数:29,代码来源:env.go
示例7: configGet
func configGet(c *cli.Context) {
arg := c.Args().Get(0)
if arg == "" {
return
}
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
val, err := cfg.Get(arg)
if err != nil {
log.Fatal(err)
}
printYaml := false
switch val.(type) {
case []interface{}:
printYaml = true
case map[interface{}]interface{}:
printYaml = true
}
if printYaml {
bytes, err := yaml.Marshal(val)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(bytes))
} else {
fmt.Println(val)
}
}
开发者ID:Hellslicer,项目名称:os,代码行数:34,代码来源:config.go
示例8: SysInit
func SysInit() error {
cfg, err := config.LoadConfig()
if err != nil {
return err
}
_, err = config.ChainCfgFuncs(cfg,
loadImages,
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
p, err := compose.GetProject(cfg, false)
if err != nil {
return cfg, err
}
return cfg, p.Up()
},
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
syscall.Sync()
return cfg, nil
},
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
log.Infof("RancherOS %s started", config.VERSION)
return cfg, nil
})
return err
}
开发者ID:heliang-whut,项目名称:os,代码行数:25,代码来源:sysinit.go
示例9: enable
func enable(c *cli.Context) {
changed := false
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
for _, service := range c.Args() {
if val, ok := cfg.Rancher.ServicesInclude[service]; !ok || !val {
if strings.HasPrefix(service, "/") && !strings.HasPrefix(service, "/var/lib/rancher/conf") {
log.Fatalf("ERROR: Service should be in path /var/lib/rancher/conf")
}
if _, err := compose.LoadServiceResource(service, true, cfg); err != nil {
log.Fatalf("could not load service %s", service)
}
cfg.Rancher.ServicesInclude[service] = true
changed = true
}
}
if changed {
if err := cfg.Set("rancher.services_include", cfg.Rancher.ServicesInclude); err != nil {
log.Fatal(err)
}
}
}
开发者ID:rowhit,项目名称:os,代码行数:26,代码来源:service.go
示例10: runImport
func runImport(c *cli.Context) {
var input io.ReadCloser
var err error
input = os.Stdin
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
inputFile := c.String("input")
if inputFile != "" {
input, err = os.Open(inputFile)
if err != nil {
log.Fatal(err)
}
defer input.Close()
}
bytes, err := ioutil.ReadAll(input)
if err != nil {
log.Fatal(err)
}
err = cfg.Import(bytes)
if err != nil {
log.Fatal(err)
}
}
开发者ID:Hellslicer,项目名称:os,代码行数:29,代码来源:config.go
示例11: Create
func (p *projectFactory) Create(c *cli.Context) (*project.Project, error) {
cfg, err := config.LoadConfig()
if err != nil {
return nil, err
}
return compose.GetProject(cfg)
}
开发者ID:clhudson2,项目名称:os,代码行数:8,代码来源:compose.go
示例12: getUpgradeUrl
func getUpgradeUrl() (string, error) {
cfg, err := config.LoadConfig()
if err != nil {
return "", err
}
return cfg.Upgrade.Url, nil
}
开发者ID:jgatkinsn,项目名称:os,代码行数:8,代码来源:os.go
示例13: Main
func Main() {
args := os.Args
if len(args) > 1 {
fmt.Println("call " + args[0] + " to load network config from rancher.yml config file")
return
}
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
ApplyNetworkConfigs(&cfg.Network)
}
开发者ID:jgatkinsn,项目名称:os,代码行数:12,代码来源:network.go
示例14: currentDatasource
func currentDatasource() (datasource.Datasource, error) {
cfg, err := rancherConfig.LoadConfig()
if err != nil {
log.Fatalf("Failed to read rancher config %v", err)
}
dss := getDatasources(cfg)
if len(dss) == 0 {
return nil, nil
}
ds := selectDatasource(dss)
return ds, nil
}
开发者ID:Hellslicer,项目名称:os,代码行数:14,代码来源:cloudinit.go
示例15: Main
func Main() {
args := os.Args
if len(args) > 1 {
fmt.Println("call " + args[0] + " to load network config from cloud-config.yml")
return
}
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
log.Fatal(err)
}
}
开发者ID:rowhit,项目名称:os,代码行数:14,代码来源:network.go
示例16: currentDatasource
func currentDatasource() (datasource.Datasource, error) {
cfg, err := rancherConfig.LoadConfig()
if err != nil {
log.WithFields(log.Fields{"err": err}).Error("Failed to read rancher config")
return nil, err
}
dss := getDatasources(cfg)
if len(dss) == 0 {
return nil, nil
}
ds := selectDatasource(dss)
return ds, nil
}
开发者ID:rowhit,项目名称:os,代码行数:15,代码来源:cloudinit.go
示例17: Main
func Main() {
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
if len(os.Args) == 1 {
if err := enter(cfg); err != nil {
log.Fatal(err)
}
} else {
if err := main(cfg); err != nil {
log.Fatal(err)
}
}
}
开发者ID:keevol,项目名称:os,代码行数:16,代码来源:main.go
示例18: merge
func merge(c *cli.Context) {
bytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
log.Fatal(err)
}
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
err = cfg.Merge(bytes)
if err != nil {
log.Fatal(err)
}
}
开发者ID:Hellslicer,项目名称:os,代码行数:16,代码来源:config.go
示例19: configSet
func configSet(c *cli.Context) {
key := c.Args().Get(0)
value := c.Args().Get(1)
if key == "" {
return
}
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
err = cfg.Set(key, value)
if err != nil {
log.Fatal(err)
}
}
开发者ID:Hellslicer,项目名称:os,代码行数:17,代码来源:config.go
示例20: CreateService
func CreateService(cfg *config.CloudConfig, name string, serviceConfig *project.ServiceConfig) (project.Service, error) {
if cfg == nil {
var err error
cfg, err = config.LoadConfig()
if err != nil {
return nil, err
}
}
p, err := RunServiceSet("once", cfg, map[string]*project.ServiceConfig{
name: serviceConfig,
})
if err != nil {
return nil, err
}
return p.CreateService(name)
}
开发者ID:clhudson2,项目名称:os,代码行数:18,代码来源:project.go
注:本文中的github.com/rancherio/os/config.LoadConfig函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论