當前位置: 首頁>>代碼示例>>Golang>>正文


Golang hashcode.String函數代碼示例

本文整理匯總了Golang中github.com/hashicorp/terraform/helper/hashcode.String函數的典型用法代碼示例。如果您正苦於以下問題:Golang String函數的具體用法?Golang String怎麽用?Golang String使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了String函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: resourceAwsDbInstanceRead

func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
	v, err := resourceAwsBbInstanceRetrieve(d, meta)

	if err != nil {
		return err
	}
	if v == nil {
		d.SetId("")
		return nil
	}

	d.Set("name", v.DBName)
	d.Set("username", v.MasterUsername)
	d.Set("engine", v.Engine)
	d.Set("engine_version", v.EngineVersion)
	d.Set("allocated_storage", v.AllocatedStorage)
	d.Set("instance_class", v.DBInstanceClass)
	d.Set("availability_zone", v.AvailabilityZone)
	d.Set("backup_retention_period", v.BackupRetentionPeriod)
	d.Set("backup_window", v.PreferredBackupWindow)
	d.Set("maintenance_window", v.PreferredMaintenanceWindow)
	d.Set("multi_az", v.MultiAZ)
	d.Set("port", v.Port)
	d.Set("db_subnet_group_name", v.DBSubnetGroup.Name)
	d.Set("parameter_group_name", v.DBParameterGroupName)
	d.Set("address", v.Address)
	d.Set("endpoint", fmt.Sprintf("%s:%d", v.Address, v.Port))
	d.Set("status", v.DBInstanceStatus)

	// Create an empty schema.Set to hold all vpc security group ids
	ids := &schema.Set{
		F: func(v interface{}) int {
			return hashcode.String(v.(string))
		},
	}
	for _, v := range v.VpcSecurityGroupIds {
		ids.Add(v)
	}
	d.Set("vpc_security_group_ids", ids)

	// Create an empty schema.Set to hold all security group names
	sgn := &schema.Set{
		F: func(v interface{}) int {
			return hashcode.String(v.(string))
		},
	}
	for _, v := range v.DBSecurityGroupNames {
		sgn.Add(v)
	}
	d.Set("security_group_names", sgn)

	return nil
}
開發者ID:packetloop,項目名稱:terraform,代碼行數:53,代碼來源:resource_aws_db_instance.go

示例2: dataSourceGoogleIamPolicyRead

// dataSourceGoogleIamPolicyRead reads a data source from config and writes it
// to state.
func dataSourceGoogleIamPolicyRead(d *schema.ResourceData, meta interface{}) error {
	var policy cloudresourcemanager.Policy
	var bindings []*cloudresourcemanager.Binding

	// The schema supports multiple binding{} blocks
	bset := d.Get("binding").(*schema.Set)

	// All binding{} blocks will be converted and stored in an array
	bindings = make([]*cloudresourcemanager.Binding, bset.Len())
	policy.Bindings = bindings

	// Convert each config binding into a cloudresourcemanager.Binding
	for i, v := range bset.List() {
		binding := v.(map[string]interface{})
		policy.Bindings[i] = &cloudresourcemanager.Binding{
			Role:    binding["role"].(string),
			Members: dataSourceGoogleIamPolicyMembers(binding["members"].(*schema.Set)),
		}
	}

	// Marshal cloudresourcemanager.Policy to JSON suitable for storing in state
	pjson, err := json.Marshal(&policy)
	if err != nil {
		// should never happen if the above code is correct
		return err
	}
	pstring := string(pjson)

	d.Set("policy_data", pstring)
	d.SetId(strconv.Itoa(hashcode.String(pstring)))

	return nil
}
開發者ID:partamonov,項目名稱:terraform,代碼行數:35,代碼來源:data_source_google_iam_policy.go

示例3: HashResource

// HashResource hashes complex structures that are described using
// a *Resource. This is the default set implementation used when a set's
// element type is a full resource.
func HashResource(resource *Resource) SchemaSetFunc {
	return func(v interface{}) int {
		var buf bytes.Buffer
		SerializeResourceForHash(&buf, v, resource)
		return hashcode.String(buf.String())
	}
}
開發者ID:AssertSelenium,項目名稱:terraform,代碼行數:10,代碼來源:set.go

示例4: resourceComputeInstancePersonalityHash

func resourceComputeInstancePersonalityHash(v interface{}) int {
	var buf bytes.Buffer
	m := v.(map[string]interface{})
	buf.WriteString(fmt.Sprintf("%s-", m["file"].(string)))

	return hashcode.String(buf.String())
}
開發者ID:MattiasGees,項目名稱:terraform,代碼行數:7,代碼來源:resource_openstack_compute_instance_v2.go

示例5: resourceArmVirtualMachineStorageOsProfileLinuxConfigHash

func resourceArmVirtualMachineStorageOsProfileLinuxConfigHash(v interface{}) int {
	var buf bytes.Buffer
	m := v.(map[string]interface{})
	buf.WriteString(fmt.Sprintf("%t-", m["disable_password_authentication"].(bool)))

	return hashcode.String(buf.String())
}
開發者ID:yonatanp,項目名稱:terraform,代碼行數:7,代碼來源:resource_arm_virtual_machine.go

示例6: resourceCloudStackFirewallRuleHash

func resourceCloudStackFirewallRuleHash(v interface{}) int {
	var buf bytes.Buffer
	m := v.(map[string]interface{})
	buf.WriteString(fmt.Sprintf(
		"%s-%s-", m["source_cidr"].(string), m["protocol"].(string)))

	if v, ok := m["icmp_type"]; ok {
		buf.WriteString(fmt.Sprintf("%d-", v.(int)))
	}

	if v, ok := m["icmp_code"]; ok {
		buf.WriteString(fmt.Sprintf("%d-", v.(int)))
	}

	// We need to make sure to sort the strings below so that we always
	// generate the same hash code no matter what is in the set.
	if v, ok := m["ports"]; ok {
		vs := v.(*schema.Set).List()
		s := make([]string, len(vs))

		for i, raw := range vs {
			s[i] = raw.(string)
		}
		sort.Strings(s)

		for _, v := range s {
			buf.WriteString(fmt.Sprintf("%s-", v))
		}
	}

	return hashcode.String(buf.String())
}
開發者ID:saulshanabrook,項目名稱:terraform,代碼行數:32,代碼來源:resource_cloudstack_firewall.go

示例7: resourceGoogleComputeBackendServiceBackendHash

func resourceGoogleComputeBackendServiceBackendHash(v interface{}) int {
	if v == nil {
		return 0
	}

	var buf bytes.Buffer
	m := v.(map[string]interface{})

	buf.WriteString(fmt.Sprintf("%s-", m["group"].(string)))

	if v, ok := m["balancing_mode"]; ok {
		buf.WriteString(fmt.Sprintf("%s-", v.(string)))
	}
	if v, ok := m["capacity_scaler"]; ok {
		buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
	}
	if v, ok := m["description"]; ok {
		buf.WriteString(fmt.Sprintf("%s-", v.(string)))
	}
	if v, ok := m["max_rate"]; ok {
		buf.WriteString(fmt.Sprintf("%d-", int64(v.(int))))
	}
	if v, ok := m["max_rate_per_instance"]; ok {
		buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
	}
	if v, ok := m["max_rate_per_instance"]; ok {
		buf.WriteString(fmt.Sprintf("%f-", v.(float64)))
	}

	return hashcode.String(buf.String())
}
開發者ID:saulshanabrook,項目名稱:terraform,代碼行數:31,代碼來源:resource_compute_backend_service.go

示例8: resourceDockerVolumesHash

func resourceDockerVolumesHash(v interface{}) int {
	var buf bytes.Buffer
	m := v.(map[string]interface{})

	if v, ok := m["from_container"]; ok {
		buf.WriteString(fmt.Sprintf("%v-", v.(string)))
	}

	if v, ok := m["container_path"]; ok {
		buf.WriteString(fmt.Sprintf("%v-", v.(string)))
	}

	if v, ok := m["host_path"]; ok {
		buf.WriteString(fmt.Sprintf("%v-", v.(string)))
	}

	if v, ok := m["volume_name"]; ok {
		buf.WriteString(fmt.Sprintf("%v-", v.(string)))
	}

	if v, ok := m["read_only"]; ok {
		buf.WriteString(fmt.Sprintf("%v-", v.(bool)))
	}

	return hashcode.String(buf.String())
}
開發者ID:Originate,項目名稱:terraform,代碼行數:26,代碼來源:resource_docker_container.go

示例9: hashEbsBlockDevice

func hashEbsBlockDevice(v interface{}) int {
	var buf bytes.Buffer
	m := v.(map[string]interface{})
	buf.WriteString(fmt.Sprintf("%s-", m["device_name"].(string)))
	buf.WriteString(fmt.Sprintf("%s-", m["snapshot_id"].(string)))
	return hashcode.String(buf.String())
}
開發者ID:mhlias,項目名稱:terraform,代碼行數:7,代碼來源:resource_aws_spot_fleet_request.go

示例10: resourceLibratoAlertConditionsHash

func resourceLibratoAlertConditionsHash(v interface{}) int {
	var buf bytes.Buffer
	m := v.(map[string]interface{})
	buf.WriteString(fmt.Sprintf("%s-", m["type"].(string)))
	buf.WriteString(fmt.Sprintf("%s-", m["metric_name"].(string)))

	source, present := m["source"]
	if present {
		buf.WriteString(fmt.Sprintf("%s-", source.(string)))
	}

	detect_reset, present := m["detect_reset"]
	if present {
		buf.WriteString(fmt.Sprintf("%t-", detect_reset.(bool)))
	}

	duration, present := m["duration"]
	if present {
		buf.WriteString(fmt.Sprintf("%d-", duration.(int)))
	}

	threshold, present := m["threshold"]
	if present {
		buf.WriteString(fmt.Sprintf("%f-", threshold.(float64)))
	}

	summary_function, present := m["summary_function"]
	if present {
		buf.WriteString(fmt.Sprintf("%s-", summary_function.(string)))
	}

	return hashcode.String(buf.String())
}
開發者ID:paultyng,項目名稱:terraform,代碼行數:33,代碼來源:resource_librato_alert.go

示例11: resourceDockerIpamConfigHash

func resourceDockerIpamConfigHash(v interface{}) int {
	var buf bytes.Buffer
	m := v.(map[string]interface{})

	if v, ok := m["subnet"]; ok {
		buf.WriteString(fmt.Sprintf("%v-", v.(string)))
	}

	if v, ok := m["ip_range"]; ok {
		buf.WriteString(fmt.Sprintf("%v-", v.(string)))
	}

	if v, ok := m["gateway"]; ok {
		buf.WriteString(fmt.Sprintf("%v-", v.(string)))
	}

	if v, ok := m["aux_address"]; ok {
		auxAddress := v.(map[string]interface{})

		keys := make([]string, len(auxAddress))
		i := 0
		for k, _ := range auxAddress {
			keys[i] = k
			i++
		}
		sort.Strings(keys)

		for _, k := range keys {
			buf.WriteString(fmt.Sprintf("%v-%v-", k, auxAddress[k].(string)))
		}
	}

	return hashcode.String(buf.String())
}
開發者ID:Zordrak,項目名稱:terraform,代碼行數:34,代碼來源:resource_docker_network.go

示例12: resourceArmVirtualMachineScaleSetNetworkConfigurationHash

func resourceArmVirtualMachineScaleSetNetworkConfigurationHash(v interface{}) int {
	var buf bytes.Buffer
	m := v.(map[string]interface{})
	buf.WriteString(fmt.Sprintf("%s-", m["name"].(string)))
	buf.WriteString(fmt.Sprintf("%t-", m["primary"].(bool)))
	return hashcode.String(buf.String())
}
開發者ID:partamonov,項目名稱:terraform,代碼行數:7,代碼來源:resource_arm_virtual_machine_scale_set.go

示例13: answersToHash

func answersToHash(v interface{}) int {
	var buf bytes.Buffer
	a := v.(map[string]interface{})
	buf.WriteString(fmt.Sprintf("%s-", a["answer"].(string)))
	if a["region"] != nil {
		buf.WriteString(fmt.Sprintf("%s-", a["region"].(string)))
	}
	metas := make([]int, 0)
	switch t := a["meta"].(type) {
	default:
		panic(fmt.Sprintf("unexpected type %T", t))
	case *schema.Set:
		for _, meta := range t.List() {
			metas = append(metas, metaToHash(meta))
		}
	case []map[string]interface{}:
		for _, meta := range t {
			metas = append(metas, metaToHash(meta))
		}
	}
	sort.Ints(metas)
	for _, metahash := range metas {
		buf.WriteString(fmt.Sprintf("%d-", metahash))
	}
	hash := hashcode.String(buf.String())
	log.Println("Generated answersToHash %d from %+v", hash, a)
	return hash
}
開發者ID:bobtfish,項目名稱:terraform-provider-nsone,代碼行數:28,代碼來源:resource_record.go

示例14: resourceAwsVpcEndpoint

func resourceAwsVpcEndpoint() *schema.Resource {
	return &schema.Resource{
		Create: resourceAwsVPCEndpointCreate,
		Read:   resourceAwsVPCEndpointRead,
		Update: resourceAwsVPCEndpointUpdate,
		Delete: resourceAwsVPCEndpointDelete,
		Schema: map[string]*schema.Schema{
			"policy": &schema.Schema{
				Type:      schema.TypeString,
				Optional:  true,
				Computed:  true,
				StateFunc: normalizeJson,
			},
			"vpc_id": &schema.Schema{
				Type:     schema.TypeString,
				Required: true,
				ForceNew: true,
			},
			"service_name": &schema.Schema{
				Type:     schema.TypeString,
				Required: true,
				ForceNew: true,
			},
			"route_table_ids": &schema.Schema{
				Type:     schema.TypeSet,
				Optional: true,
				Elem:     &schema.Schema{Type: schema.TypeString},
				Set: func(v interface{}) int {
					return hashcode.String(v.(string))
				},
			},
		},
	}
}
開發者ID:AssertSelenium,項目名稱:terraform,代碼行數:34,代碼來源:resource_aws_vpc_endpoint.go

示例15: resourceAwsElasticacheSubnetGroup

func resourceAwsElasticacheSubnetGroup() *schema.Resource {
	return &schema.Resource{
		Create: resourceAwsElasticacheSubnetGroupCreate,
		Read:   resourceAwsElasticacheSubnetGroupRead,
		Update: resourceAwsElasticacheSubnetGroupUpdate,
		Delete: resourceAwsElasticacheSubnetGroupDelete,

		Schema: map[string]*schema.Schema{
			"description": &schema.Schema{
				Type:     schema.TypeString,
				Required: true,
			},
			"name": &schema.Schema{
				Type:     schema.TypeString,
				Required: true,
				ForceNew: true,
				StateFunc: func(val interface{}) string {
					// Elasticache normalizes subnet names to lowercase,
					// so we have to do this too or else we can end up
					// with non-converging diffs.
					return strings.ToLower(val.(string))
				},
			},
			"subnet_ids": &schema.Schema{
				Type:     schema.TypeSet,
				Required: true,
				Elem:     &schema.Schema{Type: schema.TypeString},
				Set: func(v interface{}) int {
					return hashcode.String(v.(string))
				},
			},
		},
	}
}
開發者ID:AssertSelenium,項目名稱:terraform,代碼行數:34,代碼來源:resource_aws_elasticache_subnet_group.go


注:本文中的github.com/hashicorp/terraform/helper/hashcode.String函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。