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


Golang utils.Convert函数代码示例

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


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

示例1: MergeServicesV1

// MergeServicesV1 merges a v1 compose file into an existing set of service configs
func MergeServicesV1(existingServices *ServiceConfigs, environmentLookup EnvironmentLookup, resourceLookup ResourceLookup, file string, datas RawServiceMap, options *ParseOptions) (map[string]*ServiceConfigV1, error) {
	if options.Interpolate {
		if err := Interpolate(environmentLookup, &datas); err != nil {
			return nil, err
		}
	}

	if options.Preprocess != nil {
		var err error
		datas, err = options.Preprocess(datas)
		if err != nil {
			return nil, err
		}
	}

	if options.Validate {
		if err := validate(datas); err != nil {
			return nil, err
		}
	}

	for name, data := range datas {
		data, err := parseV1(resourceLookup, environmentLookup, file, data, datas, options)
		if err != nil {
			logrus.Errorf("Failed to parse service %s: %v", name, err)
			return nil, err
		}

		if serviceConfig, ok := existingServices.Get(name); ok {
			var rawExistingService RawService
			if err := utils.Convert(serviceConfig, &rawExistingService); err != nil {
				return nil, err
			}

			data = mergeConfig(rawExistingService, data)
		}

		datas[name] = data
	}

	if options.Validate {
		for name, data := range datas {
			err := validateServiceConstraints(data, name)
			if err != nil {
				return nil, err
			}
		}
	}

	serviceConfigs := make(map[string]*ServiceConfigV1)
	if err := utils.Convert(datas, &serviceConfigs); err != nil {
		return nil, err
	}

	return serviceConfigs, nil
}
开发者ID:vdemeester,项目名称:rancher-compose,代码行数:57,代码来源:merge_v1.go

示例2: MergeServices

// MergeServices merges a compose file into an existing set of service configs
func MergeServices(existingServices *Configs, environmentLookup EnvironmentLookup, resourceLookup ResourceLookup, file string, bytes []byte) (map[string]*ServiceConfig, error) {
	configs := make(map[string]*ServiceConfig)

	datas := make(RawServiceMap)
	if err := yaml.Unmarshal(bytes, &datas); err != nil {
		return nil, err
	}

	if err := Interpolate(environmentLookup, &datas); err != nil {
		return nil, err
	}

	if err := validate(datas); err != nil {
		return nil, err
	}

	for name, data := range datas {
		data, err := parse(resourceLookup, environmentLookup, file, data, datas)
		if err != nil {
			logrus.Errorf("Failed to parse service %s: %v", name, err)
			return nil, err
		}

		if serviceConfig, ok := existingServices.Get(name); ok {
			var rawExistingService RawService
			if err := utils.Convert(serviceConfig, &rawExistingService); err != nil {
				return nil, err
			}

			data = mergeConfig(rawExistingService, data)
		}

		datas[name] = data
	}

	for name, data := range datas {
		err := validateServiceConstraints(data, name)
		if err != nil {
			return nil, err
		}
	}

	if err := utils.Convert(datas, &configs); err != nil {
		return nil, err
	}

	adjustValues(configs)

	return configs, nil
}
开发者ID:kunalkushwaha,项目名称:libcompose,代码行数:51,代码来源:merge.go

示例3: MergeServicesV2

// MergeServicesV2 merges a v2 compose file into an existing set of service configs
func MergeServicesV2(existingServices *ServiceConfigs, environmentLookup EnvironmentLookup, resourceLookup ResourceLookup, file string, bytes []byte, options *ParseOptions) (map[string]*ServiceConfig, error) {
	var config Config
	if err := yaml.Unmarshal(bytes, &config); err != nil {
		return nil, err
	}

	datas := config.Services

	if options.Interpolate {
		if err := Interpolate(environmentLookup, &datas); err != nil {
			return nil, err
		}
	}

	if options.Preprocess != nil {
		var err error
		datas, err = options.Preprocess(datas)
		if err != nil {
			return nil, err
		}
	}

	for name, data := range datas {
		data, err := parseV2(resourceLookup, environmentLookup, file, data, datas, options)
		if err != nil {
			logrus.Errorf("Failed to parse service %s: %v", name, err)
			return nil, err
		}

		if serviceConfig, ok := existingServices.Get(name); ok {
			var rawExistingService RawService
			if err := utils.Convert(serviceConfig, &rawExistingService); err != nil {
				return nil, err
			}

			data = mergeConfig(rawExistingService, data)
		}

		datas[name] = data
	}

	serviceConfigs := make(map[string]*ServiceConfig)
	if err := utils.Convert(datas, &serviceConfigs); err != nil {
		return nil, err
	}

	return serviceConfigs, nil
}
开发者ID:jainvipin,项目名称:libcompose,代码行数:49,代码来源:merge_v2.go

示例4: unmarshalBytes

func (c *Context) unmarshalBytes(composeBytes, bytes []byte) error {
	rawServiceMap := project.RawServiceMap{}
	if composeBytes != nil {
		if err := yaml.Unmarshal(composeBytes, &rawServiceMap); err != nil {
			return err
		}

		for key := range rawServiceMap {
			delete(rawServiceMap[key], "hostname")
		}
	}
	if bytes != nil {
		if err := yaml.Unmarshal(bytes, &rawServiceMap); err != nil {
			return err
		}
	}
	if err := project.Interpolate(c.EnvironmentLookup, &rawServiceMap); err != nil {
		return err
	}
	if err := utils.Convert(rawServiceMap, &c.RancherConfig); err != nil {
		return err
	}
	for _, v := range c.RancherConfig {
		rUtils.RemoveInterfaceKeys(v.Metadata)
	}
	return nil
}
开发者ID:cloudnautique,项目名称:rancher-compose,代码行数:27,代码来源:context.go

示例5: parse

func (q *QuestionLookup) parse(file string) error {
	contents, err := ioutil.ReadFile(file)
	if os.IsNotExist(err) {
		return nil
	} else if err != nil {
		return err
	}

	data := map[string]map[string]interface{}{}
	if err := yaml.Unmarshal(contents, &data); err != nil {
		return err
	}

	rawQuestions := data[".catalog"]
	if rawQuestions != nil {
		var wrapper questionWrapper
		if err := utils.Convert(rawQuestions, &wrapper); err != nil {
			return err
		}

		for _, question := range wrapper.Questions {
			q.questions[question.Variable] = question
		}
	}

	return nil
}
开发者ID:xaka,项目名称:rancher-compose,代码行数:27,代码来源:questions.go

示例6: parse

func (q *QuestionLookup) parse(file string) error {
	contents, err := ioutil.ReadFile(file)
	if os.IsNotExist(err) {
		return nil
	} else if err != nil {
		return err
	}

	config, err := config.CreateConfig(contents)
	if err != nil {
		return err
	}
	data := config.Services

	rawQuestions := data[".catalog"]
	if rawQuestions != nil {
		var wrapper questionWrapper
		if err := utils.Convert(rawQuestions, &wrapper); err != nil {
			return err
		}

		for _, question := range wrapper.Questions {
			q.questions[question.Variable] = question
		}
	}

	return nil
}
开发者ID:vdemeester,项目名称:rancher-compose,代码行数:28,代码来源:questions.go

示例7: ParseCatalogConfig

func ParseCatalogConfig(contents []byte) (*model.RancherCompose, error) {
	cfg, err := config.CreateConfig(contents)
	if err != nil {
		return nil, err
	}
	var rawCatalogConfig interface{}

	if cfg.Version == "2" && cfg.Services[".catalog"] != nil {
		rawCatalogConfig = cfg.Services[".catalog"]
	}

	var data map[string]interface{}
	if err := yaml.Unmarshal(contents, &data); err != nil {
		return nil, err
	}

	if data["catalog"] != nil {
		rawCatalogConfig = data["catalog"]
	} else if data[".catalog"] != nil {
		rawCatalogConfig = data[".catalog"]
	}

	if rawCatalogConfig != nil {
		var catalogConfig model.RancherCompose
		if err := utils.Convert(rawCatalogConfig, &catalogConfig); err != nil {
			return nil, err
		}

		return &catalogConfig, nil
	}

	return &model.RancherCompose{}, nil
}
开发者ID:rancher,项目名称:rancher-catalog-service,代码行数:33,代码来源:questions.go

示例8: mergeProject

func mergeProject(p *Project, bytes []byte) (map[string]*ServiceConfig, error) {
	configs := make(map[string]*ServiceConfig)

	datas := make(rawServiceMap)
	if err := yaml.Unmarshal(bytes, &datas); err != nil {
		return nil, err
	}

	if err := interpolate(p.context.EnvironmentLookup, &datas); err != nil {
		return nil, err
	}

	for name, data := range datas {
		data, err := parse(p.context.ConfigLookup, p.context.EnvironmentLookup, p.File, data, datas)
		if err != nil {
			logrus.Errorf("Failed to parse service %s: %v", name, err)
			return nil, err
		}

		datas[name] = data
	}

	if err := utils.Convert(datas, &configs); err != nil {
		return nil, err
	}

	adjustValues(configs)
	return configs, nil
}
开发者ID:pirater,项目名称:os,代码行数:29,代码来源:merge.go

示例9: createLaunchConfigs

func createLaunchConfigs(r *RancherService) (rancherClient.LaunchConfig, []rancherClient.SecondaryLaunchConfig, error) {
	secondaryLaunchConfigs := []rancherClient.SecondaryLaunchConfig{}
	launchConfig, err := createLaunchConfig(r, r.Name(), r.Config())
	if err != nil {
		return launchConfig, nil, err
	}
	launchConfig.HealthCheck = r.HealthCheck("")

	if secondaries, ok := r.Context().SidekickInfo.primariesToSidekicks[r.Name()]; ok {
		for _, secondaryName := range secondaries {
			serviceConfig, ok := r.Context().Project.Configs[secondaryName]
			if !ok {
				return launchConfig, nil, fmt.Errorf("Failed to find sidekick: %s", secondaryName)
			}

			launchConfig, err := createLaunchConfig(r, secondaryName, serviceConfig)
			if err != nil {
				return launchConfig, nil, err
			}
			launchConfig.HealthCheck = r.HealthCheck(secondaryName)

			var secondaryLaunchConfig rancherClient.SecondaryLaunchConfig
			utils.Convert(launchConfig, &secondaryLaunchConfig)
			secondaryLaunchConfig.Name = secondaryName

			if secondaryLaunchConfig.Labels == nil {
				secondaryLaunchConfig.Labels = map[string]interface{}{}
			}
			secondaryLaunchConfigs = append(secondaryLaunchConfigs, secondaryLaunchConfig)
		}
	}

	return launchConfig, secondaryLaunchConfigs, nil
}
开发者ID:xaka,项目名称:rancher-compose,代码行数:34,代码来源:configs.go

示例10: readEnvFile

func readEnvFile(configLookup ConfigLookup, inFile string, serviceData rawService) (rawService, error) {
	var config ServiceConfig

	if err := utils.Convert(serviceData, &config); err != nil {
		return nil, err
	}

	if len(config.EnvFile.Slice()) == 0 {
		return serviceData, nil
	}

	if configLookup == nil {
		return nil, fmt.Errorf("Can not use env_file in file %s no mechanism provided to load files", inFile)
	}

	vars := config.Environment.Slice()

	for i := len(config.EnvFile.Slice()) - 1; i >= 0; i-- {
		envFile := config.EnvFile.Slice()[i]
		content, _, err := configLookup.Lookup(envFile, inFile)
		if err != nil {
			return nil, err
		}

		if err != nil {
			return nil, err
		}

		scanner := bufio.NewScanner(bytes.NewBuffer(content))
		for scanner.Scan() {
			line := strings.TrimSpace(scanner.Text())
			key := strings.SplitAfter(line, "=")[0]

			found := false
			for _, v := range vars {
				if strings.HasPrefix(v, key) {
					found = true
					break
				}
			}

			if !found {
				vars = append(vars, line)
			}
		}

		if scanner.Err() != nil {
			return nil, scanner.Err()
		}
	}

	serviceData["environment"] = vars

	delete(serviceData, "env_file")

	return serviceData, nil
}
开发者ID:jojimt,项目名称:libcompose,代码行数:57,代码来源:merge.go

示例11: unmarshalBytes

func (c *Context) unmarshalBytes(bytes []byte) error {
	rawServiceMap := project.RawServiceMap{}
	if err := yaml.Unmarshal(bytes, &rawServiceMap); err != nil {
		return err
	}
	if err := project.Interpolate(c.EnvironmentLookup, &rawServiceMap); err != nil {
		return err
	}
	return utils.Convert(rawServiceMap, &c.RancherConfig)
}
开发者ID:alena1108,项目名称:rancher-compose-executor,代码行数:10,代码来源:context.go

示例12: hashObj

func hashObj(obj interface{}) (string, error) {
	hash := sha1.New()

	mapObj := map[interface{}]interface{}{}
	if err := utils.Convert(obj, &mapObj); err != nil {
		return "", err
	}

	writeNativeMap(hash, mapObj)

	return hex.EncodeToString(hash.Sum(nil)), nil
}
开发者ID:vdemeester,项目名称:rancher-compose,代码行数:12,代码来源:hash.go

示例13: ExtractBindings

//ExtractBindings gets bindings from created RawServiceMap
func ExtractBindings(yamlContent []byte) (BindingProperty, error) {
	var rawConfigDocker config.RawServiceMap
	var bindingsMap map[string]ServiceBinding
	var bindingPropertyMap BindingProperty
	var labels libYaml.SliceorMap

	config, err := config.CreateConfig(yamlContent)
	if err != nil {
		return nil, err
	}
	rawConfigDocker = config.Services

	preProcessServiceMap := preprocess.PreprocessServiceMap(nil)
	rawConfigDocker, err = preProcessServiceMap(rawConfigDocker)
	if err != nil {
		log.Errorf("Error during preprocess : %v\n", err)
		return nil, err
	}

	bindingsMap = make(map[string]ServiceBinding)
	bindingPropertyMap = make(map[string]interface{})

	for key := range rawConfigDocker {
		if _, serviceParsed := bindingsMap[key]; serviceParsed {
			log.Debugf("Service bindings already provided")
			continue
		}
		newServiceBinding := ServiceBinding{}

		newServiceBinding.Labels = MapLabel{}
		newServiceBinding.Ports = PortArray{}

		if rawConfigDocker[key]["labels"] != nil {
			err := utils.Convert(rawConfigDocker[key]["labels"], &labels)
			if err != nil {
				return nil, err
			}
			for k, v := range labels {
				newServiceBinding.Labels[k] = v
			}
		}
		if rawConfigDocker[key]["ports"] != nil {
			for _, port := range rawConfigDocker[key]["ports"].([]interface{}) {
				newServiceBinding.Ports = append(newServiceBinding.Ports, port)
			}
		}
		bindingsMap[key] = newServiceBinding
	}

	bindingPropertyMap["services"] = bindingsMap

	return bindingPropertyMap, nil
}
开发者ID:rancher,项目名称:rancher-catalog-service,代码行数:54,代码来源:bindings.go

示例14: ParseNetworks

// ParseNetworks parses networks in a compose file
func ParseNetworks(bytes []byte) (map[string]*NetworkConfig, error) {
	networkConfigs := make(map[string]*NetworkConfig)

	var config Config
	if err := yaml.Unmarshal(bytes, &config); err != nil {
		return nil, err
	}

	if err := utils.Convert(config.Networks, &networkConfigs); err != nil {
		return nil, err
	}

	return networkConfigs, nil
}
开发者ID:jainvipin,项目名称:libcompose,代码行数:15,代码来源:merge_v2.go

示例15: ParseVolumes

// ParseVolumes parses volumes in a compose file
func ParseVolumes(bytes []byte) (map[string]*VolumeConfig, error) {
	volumeConfigs := make(map[string]*VolumeConfig)

	var config Config
	if err := yaml.Unmarshal(bytes, &config); err != nil {
		return nil, err
	}

	if err := utils.Convert(config.Volumes, &volumeConfigs); err != nil {
		return nil, err
	}

	return volumeConfigs, nil
}
开发者ID:jainvipin,项目名称:libcompose,代码行数:15,代码来源:merge_v2.go


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