本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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")
}