当前位置: 首页>>代码示例>>Golang>>正文


Golang gcfg.ReadInto函数代码示例

本文整理汇总了Golang中code/google/com/p/gcfg.ReadInto函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadInto函数的具体用法?Golang ReadInto怎么用?Golang ReadInto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ReadInto函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: newOVirtCloud

func newOVirtCloud(config io.Reader) (*OVirtCloud, error) {
	if config == nil {
		return nil, fmt.Errorf("missing configuration file for ovirt cloud provider")
	}

	oVirtConfig := OVirtApiConfig{}

	/* defaults */
	oVirtConfig.Connection.Username = "[email protected]"

	if err := gcfg.ReadInto(&oVirtConfig, config); err != nil {
		return nil, err
	}

	if oVirtConfig.Connection.ApiEntry == "" {
		return nil, fmt.Errorf("missing ovirt uri in cloud provider configuration")
	}

	request, err := url.Parse(oVirtConfig.Connection.ApiEntry)
	if err != nil {
		return nil, err
	}

	request.Path = path.Join(request.Path, "vms")
	request.User = url.UserPassword(oVirtConfig.Connection.Username, oVirtConfig.Connection.Password)
	request.RawQuery = url.Values{"search": {oVirtConfig.Filters.VmsQuery}}.Encode()

	return &OVirtCloud{VmsRequest: request}, nil
}
开发者ID:ravigadde,项目名称:kube-scheduler,代码行数:29,代码来源:ovirt.go

示例2: readAWSCloudConfig

// readAWSCloudConfig reads an instance of AWSCloudConfig from config reader.
func readAWSCloudConfig(config io.Reader, metadata AWSMetadata) (*AWSCloudConfig, error) {
	var cfg AWSCloudConfig
	var err error

	if config != nil {
		err = gcfg.ReadInto(&cfg, config)
		if err != nil {
			return nil, err
		}
	}

	if cfg.Global.Zone == "" {
		if metadata != nil {
			glog.Info("Zone not specified in configuration file; querying AWS metadata service")
			cfg.Global.Zone, err = getAvailabilityZone(metadata)
			if err != nil {
				return nil, err
			}
		}
		if cfg.Global.Zone == "" {
			return nil, fmt.Errorf("no zone specified in configuration file")
		}
	}

	return &cfg, nil
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:27,代码来源:aws.go

示例3: loadConfig

func loadConfig(filePath string) (*yakvs.Config, error) {
	cfg := new(yakvs.Config)

	file, err := os.Open(filePath)
	if err != nil {
		if os.IsNotExist(err) {
			file, err = os.Create(filePath)
			if err != nil {
				return nil, err
			}

			file.WriteString(defaultConfig)
			file.WriteString("\n")
			file.Close()

			file, err = os.Open(filePath)
			if err != nil {
				return nil, err
			}
		} else {
			return nil, err
		}
	}
	defer file.Close()

	err = gcfg.ReadInto(cfg, file)
	if err != nil {
		return nil, err
	}

	return cfg, nil
}
开发者ID:sci4me,项目名称:yakvs,代码行数:32,代码来源:main.go

示例4: newGCECloud

// newGCECloud creates a new instance of GCECloud.
func newGCECloud(config io.Reader) (*GCECloud, error) {
	projectID, zone, err := getProjectAndZone()
	if err != nil {
		return nil, err
	}
	// TODO: if we want to use this on a machine that doesn't have the http://metadata server
	// e.g. on a user's machine (not VM) somewhere, we need to have an alternative for
	// instance id lookup.
	instanceID, err := getInstanceID()
	if err != nil {
		return nil, err
	}
	externalID, err := getCurrentExternalID()
	if err != nil {
		return nil, err
	}
	networkName, err := getNetworkName()
	if err != nil {
		return nil, err
	}
	tokenSource := google.ComputeTokenSource("")
	if config != nil {
		var cfg Config
		if err := gcfg.ReadInto(&cfg, config); err != nil {
			glog.Errorf("Couldn't read config: %v", err)
			return nil, err
		}
		if cfg.Global.ProjectID != "" {
			projectID = cfg.Global.ProjectID
		}
		if cfg.Global.NetworkName != "" {
			networkName = cfg.Global.NetworkName
		}
		if cfg.Global.TokenURL != "" {
			tokenSource = newAltTokenSource(cfg.Global.TokenURL)
		}
	}
	client := oauth2.NewClient(oauth2.NoContext, tokenSource)
	svc, err := compute.New(client)
	if err != nil {
		return nil, err
	}
	containerSvc, err := container.New(client)
	if err != nil {
		return nil, err
	}
	return &GCECloud{
		service:          svc,
		containerService: containerSvc,
		projectID:        projectID,
		zone:             zone,
		instanceID:       instanceID,
		externalID:       externalID,
		networkName:      networkName,
		metadataAccess:   getMetadata,
	}, nil
}
开发者ID:Bazooki,项目名称:kubernetes,代码行数:58,代码来源:gce.go

示例5: NewOpenStack

func NewOpenStack(config io.Reader) (*OpenStack, error) {
	var cfg Config
	err := gcfg.ReadInto(&cfg, config)
	if err != nil {
		glog.Warning("Failed to parse openstack configure file: %v", err)
		return nil, err
	}

	provider, err := openstack.AuthenticatedClient(cfg.toAuthOptions())
	if err != nil {
		glog.Warning("Failed to auth openstack: %v", err)
		return nil, err
	}

	identity, err := openstack.NewIdentityV2(provider, gophercloud.EndpointOpts{
		Availability: gophercloud.AvailabilityAdmin,
	})
	if err != nil {
		glog.Warning("Failed to find identity endpoint")
		return nil, err
	}

	network, err := openstack.NewNetworkV2(provider, gophercloud.EndpointOpts{
		Region: cfg.Global.Region,
	})
	if err != nil {
		glog.Warning("Failed to find neutron endpoint: %v", err)
		return nil, err
	}

	os := OpenStack{
		identity:   identity,
		network:    network,
		provider:   provider,
		region:     cfg.Global.Region,
		lbOpts:     cfg.LoadBalancer,
		pluginOpts: cfg.Plugin,
		ExtNetID:   cfg.Global.ExtNetID,
	}

	// init plugin
	if cfg.Plugin.PluginName != "" {
		integrationBriage := "br-int"
		if cfg.Plugin.IntegrationBridge != "" {
			integrationBriage = cfg.Plugin.IntegrationBridge
		}

		plugin, _ := plugins.GetNetworkPlugin(cfg.Plugin.PluginName)
		if plugin != nil {
			plugin.Init(integrationBriage)
			os.Plugin = plugin
		}
	}

	return &os, nil
}
开发者ID:hyperhq,项目名称:kubestack,代码行数:56,代码来源:openstack.go

示例6: readConfig

func readConfig(config io.Reader) (Config, error) {
	if config == nil {
		err := fmt.Errorf("no OpenStack cloud provider config file given")
		return Config{}, err
	}

	var cfg Config
	err := gcfg.ReadInto(&cfg, config)
	return cfg, err
}
开发者ID:Tlacenka,项目名称:origin,代码行数:10,代码来源:openstack.go

示例7: Read

func (c *Config) Read(configReader io.Reader) error {
	wrapper := &ConfigWrapper{Scheduler: *c}
	if configReader != nil {
		if err := gcfg.ReadInto(wrapper, configReader); err != nil {
			return err
		}
		*c = wrapper.Scheduler
	}
	return nil
}
开发者ID:qingyuancloud,项目名称:qingyuan,代码行数:10,代码来源:config.go

示例8: readConfig

func readConfig(configReader io.Reader) (*Config, error) {
	config := createDefaultConfig()
	wrapper := &ConfigWrapper{Mesos_Cloud: *config}
	if configReader != nil {
		if err := gcfg.ReadInto(wrapper, configReader); err != nil {
			return nil, err
		}
		config = &(wrapper.Mesos_Cloud)
	}
	return config, nil
}
开发者ID:MarWestermann,项目名称:gofabric8,代码行数:11,代码来源:config.go

示例9: readAWSCloudConfig

// readAWSCloudConfig reads an instance of AWSCloudConfig from config reader.
func readAWSCloudConfig(config io.Reader) (*AWSCloudConfig, error) {
	if config == nil {
		return nil, fmt.Errorf("no AWS cloud provider config file given")
	}

	var cfg AWSCloudConfig
	err := gcfg.ReadInto(&cfg, config)
	if err != nil {
		return nil, err
	}

	if cfg.Global.Region == "" {
		return nil, fmt.Errorf("no region specified in configuration file")
	}

	return &cfg, nil
}
开发者ID:vrosnet,项目名称:kubernetes,代码行数:18,代码来源:aws.go

示例10: newHTTPCloud

// Creates a new instance of httpCloud through the config file sent.
func newHTTPCloud(config io.Reader) (*httpCloud, error) {
	if config != nil {
		var cfg Config
		if err := gcfg.ReadInto(&cfg, config); err != nil {
			return nil, fmt.Errorf("Couldn't read config: %v", err)
		}

		instancesURL := cfg.Global.InstancesURL
		// Validate URL
		_, err := url.ParseRequestURI(instancesURL)
		if err != nil {
			return nil, fmt.Errorf("Can't parse the instances-url provided: %s", err)
		}
		// Handle Trailing slashes
		instancesURL = strings.TrimRight(instancesURL, "/")

		schedulerExtensionURL := cfg.Global.SchedulerExtensionURL
		// Validate URL
		_, err = url.ParseRequestURI(schedulerExtensionURL)
		if err != nil {
			return nil, fmt.Errorf("Can't parse the scheduler-extension-url provided: %s", err)
		}
		// Handle Trailing slashes
		schedulerExtensionURL = strings.TrimRight(schedulerExtensionURL, "/")

		return &httpCloud{
			instancesURL:                instancesURL,
			instancesSupported:          cfg.Global.InstancesSupported,
			tcpLoadBalancerSupported:    cfg.Global.TcpLoadBalancerSupported,
			zonesSupported:              cfg.Global.ZonesSupported,
			clustersSupported:           cfg.Global.ClustersSupported,
			schedulerExtensionURL:       schedulerExtensionURL,
			schedulerExtensionSupported: cfg.Global.SchedulerExtensionSupported,
		}, nil
	}
	return nil, fmt.Errorf("Config file is empty or is not provided")
}
开发者ID:ravigadde,项目名称:kube-scheduler,代码行数:38,代码来源:http.go


注:本文中的code/google/com/p/gcfg.ReadInto函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。