本文整理汇总了Golang中github.com/jen20/riviera/azure.String函数的典型用法代码示例。如果您正苦于以下问题:Golang String函数的具体用法?Golang String怎么用?Golang String使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了String函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createResourceGroup
func createResourceGroup(azureClient *azure.Client) (string, error) {
name := fmt.Sprintf("riviera_resource_group_%d", rand.Intn(8999)+1000)
r := azureClient.NewRequest()
r.Command = azure.CreateResourceGroup{
Name: name,
Location: azure.WestUS,
Tags: map[string]*string{
"Key1": azure.String("value1"),
"Key2": azure.String("value2"),
},
}
response, err := r.Execute()
if err != nil {
return "", err
}
if !response.IsSuccessful() {
return "", fmt.Errorf("Error creating resource group %q", name)
}
return name, nil
}
示例2: main
func main() {
// 1 - Configure the ARM Client with credentials
creds := &azure.AzureResourceManagerCredentials{
ClientID: os.Getenv("ARM_CLIENT_ID"),
ClientSecret: os.Getenv("ARM_CLIENT_SECRET"),
TenantID: os.Getenv("ARM_TENANT_ID"),
SubscriptionID: os.Getenv("ARM_SUBSCRIPTION_ID"),
}
azureClient, err := azure.NewClient(creds)
if err != nil {
log.Fatal(err)
}
// 2 - Create a new request with a location attached
r := azureClient.NewRequest()
// 3 - Create a command object, and assign it to the request
r.Command = azure.CreateResourceGroup{
Name: resourceGroupName,
Location: azure.WestUS,
Tags: map[string]*string{
"Key1": azure.String("value1"),
"Key2": azure.String("value2"),
},
}
// 4 - Execute the command
response, err := r.Execute()
if err != nil {
log.Fatal(err)
}
// 5 - Make use of the result
if response.IsSuccessful() {
result := response.Parsed.(*azure.CreateResourceGroupResponse)
fmt.Printf("Created resource group %q:\n", *result.Name)
fmt.Printf("\tID: %s\n", *result.ID)
fmt.Printf("\tLocation: %s\n", *result.Location)
fmt.Printf("\tProvisioningState: %s\n", *result.ProvisioningState)
} else {
log.Fatalf("Failed creating resource group: %s", response.Error.Error())
}
// 6 - Delete the resource group
d := azureClient.NewRequest()
d.Command = azure.DeleteResourceGroup{
Name: resourceGroupName,
}
deleteResponse, err := d.Execute()
if err != nil {
log.Fatal(err)
}
if deleteResponse.IsSuccessful() {
log.Printf("Successfully deleted resource group %q", resourceGroupName)
} else {
log.Printf("Error deleting resource group %q", resourceGroupName)
}
}
示例3: resourceArmLoadBalancerCreate
func resourceArmLoadBalancerCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient)
loadBalancerClient := client.loadBalancerClient
log.Printf("[INFO] preparing arguments for Azure ARM LoadBalancer creation.")
name := d.Get("name").(string)
location := d.Get("location").(string)
resGroup := d.Get("resource_group_name").(string)
tags := d.Get("tags").(map[string]interface{})
expandedTags := expandTags(tags)
properties := network.LoadBalancerPropertiesFormat{}
if _, ok := d.GetOk("frontend_ip_configuration"); ok {
properties.FrontendIPConfigurations = expandAzureRmLoadBalancerFrontendIpConfigurations(d)
}
loadbalancer := network.LoadBalancer{
Name: azure.String(name),
Location: azure.String(location),
Tags: expandedTags,
Properties: &properties,
}
_, err := loadBalancerClient.CreateOrUpdate(resGroup, name, loadbalancer, make(chan struct{}))
if err != nil {
return errwrap.Wrapf("Error Creating/Updating LoadBalancer {{err}}", err)
}
read, err := loadBalancerClient.Get(resGroup, name, "")
if err != nil {
return errwrap.Wrapf("Error Getting LoadBalancer {{err}", err)
}
if read.ID == nil {
return fmt.Errorf("Cannot read LoadBalancer %s (resource group %s) ID", name, resGroup)
}
d.SetId(*read.ID)
log.Printf("[DEBUG] Waiting for LoadBalancer (%s) to become available", name)
stateConf := &resource.StateChangeConf{
Pending: []string{"Accepted", "Updating"},
Target: []string{"Succeeded"},
Refresh: loadbalancerStateRefreshFunc(client, resGroup, name),
Timeout: 10 * time.Minute,
}
if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for LoadBalancer (%s) to become available: %s", name, err)
}
return resourecArmLoadBalancerRead(d, meta)
}
示例4: expandAzureRmLoadBalancerNatRule
func expandAzureRmLoadBalancerNatRule(d *schema.ResourceData, lb *network.LoadBalancer) (*network.InboundNatRule, error) {
properties := network.InboundNatRulePropertiesFormat{
Protocol: network.TransportProtocol(d.Get("protocol").(string)),
FrontendPort: azure.Int32(int32(d.Get("frontend_port").(int))),
BackendPort: azure.Int32(int32(d.Get("backend_port").(int))),
}
if v := d.Get("frontend_ip_configuration_name").(string); v != "" {
rule, _, exists := findLoadBalancerFrontEndIpConfigurationByName(lb, v)
if !exists {
return nil, fmt.Errorf("[ERROR] Cannot find FrontEnd IP Configuration with the name %s", v)
}
feip := network.SubResource{
ID: rule.ID,
}
properties.FrontendIPConfiguration = &feip
}
natRule := network.InboundNatRule{
Name: azure.String(d.Get("name").(string)),
Properties: &properties,
}
return &natRule, nil
}
示例5: resourceArmContainerRegistryCreate
func resourceArmContainerRegistryCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).containerRegistryClient
log.Printf("[INFO] preparing arguments for AzureRM Container Registry creation.")
resourceGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)
location := d.Get("location").(string)
adminUserEnabled := d.Get("admin_enabled").(bool)
tags := d.Get("tags").(map[string]interface{})
parameters := containerregistry.Registry{
Location: &location,
RegistryProperties: &containerregistry.RegistryProperties{
AdminUserEnabled: &adminUserEnabled,
},
Tags: expandTags(tags),
}
accounts := d.Get("storage_account").(*schema.Set).List()
account := accounts[0].(map[string]interface{})
storageAccountName := account["name"].(string)
storageAccountAccessKey := account["access_key"].(string)
parameters.RegistryProperties.StorageAccount = &containerregistry.StorageAccountProperties{
Name: azure.String(storageAccountName),
AccessKey: azure.String(storageAccountAccessKey),
}
_, err := client.CreateOrUpdate(resourceGroup, name, parameters)
if err != nil {
return err
}
read, err := client.GetProperties(resourceGroup, name)
if err != nil {
return err
}
if read.ID == nil {
return fmt.Errorf("Cannot read Container Registry %s (resource group %s) ID", name, resourceGroup)
}
d.SetId(*read.ID)
return resourceArmContainerRegistryRead(d, meta)
}
示例6: resourceArmSqlServerCreate
func resourceArmSqlServerCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient)
rivieraClient := client.rivieraClient
tags := d.Get("tags").(map[string]interface{})
expandedTags := expandTags(tags)
createRequest := rivieraClient.NewRequest()
createRequest.Command = &sql.CreateOrUpdateServer{
Name: d.Get("name").(string),
Location: d.Get("location").(string),
ResourceGroupName: d.Get("resource_group_name").(string),
AdministratorLogin: azure.String(d.Get("administrator_login").(string)),
AdministratorLoginPassword: azure.String(d.Get("administrator_login_password").(string)),
Version: azure.String(d.Get("version").(string)),
Tags: *expandedTags,
}
createResponse, err := createRequest.Execute()
if err != nil {
return fmt.Errorf("Error creating SQL Server: %s", err)
}
if !createResponse.IsSuccessful() {
return fmt.Errorf("Error creating SQL Server: %s", createResponse.Error)
}
readRequest := rivieraClient.NewRequest()
readRequest.Command = &sql.GetServer{
Name: d.Get("name").(string),
ResourceGroupName: d.Get("resource_group_name").(string),
}
readResponse, err := readRequest.Execute()
if err != nil {
return fmt.Errorf("Error reading SQL Server: %s", err)
}
if !readResponse.IsSuccessful() {
return fmt.Errorf("Error reading SQL Server: %s", readResponse.Error)
}
resp := readResponse.Parsed.(*sql.GetServerResponse)
d.SetId(*resp.ID)
return resourceArmSqlServerRead(d, meta)
}
示例7: setup
func setup(t *testing.T, conf map[string]string) {
creds, err := getCredentialsFromConf(conf)
if err != nil {
t.Fatalf("Error getting credentials from conf: %v", err)
}
rivieraClient, err := getRivieraClient(creds)
if err != nil {
t.Fatalf("Error instantiating the riviera client: %v", err)
}
// Create resource group
r := rivieraClient.NewRequest()
r.Command = riviera.CreateResourceGroup{
Name: conf["resource_group_name"],
Location: riviera.WestUS,
}
response, err := r.Execute()
if err != nil {
t.Fatalf("Error creating a resource group: %v", err)
}
if !response.IsSuccessful() {
t.Fatalf("Error creating a resource group: %v", response.Error.Error())
}
// Create storage account
r = rivieraClient.NewRequest()
r.Command = storage.CreateStorageAccount{
ResourceGroupName: conf["resource_group_name"],
Name: conf["storage_account_name"],
AccountType: riviera.String("Standard_LRS"),
Location: riviera.WestUS,
}
response, err = r.Execute()
if err != nil {
t.Fatalf("Error creating a storage account: %v", err)
}
if !response.IsSuccessful() {
t.Fatalf("Error creating a storage account: %v", response.Error.Error())
}
// Create container
accessKey, err := getStorageAccountAccessKey(conf, conf["resource_group_name"], conf["storage_account_name"])
if err != nil {
t.Fatalf("Error creating a storage account: %v", err)
}
storageClient, err := mainStorage.NewBasicClient(conf["storage_account_name"], accessKey)
if err != nil {
t.Fatalf("Error creating storage client for storage account %q: %s", conf["storage_account_name"], err)
}
blobClient := storageClient.GetBlobService()
_, err = blobClient.CreateContainerIfNotExists(conf["container_name"], mainStorage.ContainerAccessTypePrivate)
if err != nil {
t.Fatalf("Couldn't create container with name %s: %s.", conf["container_name"], err)
}
}
示例8: resourceArmSqlFirewallRuleCreate
func resourceArmSqlFirewallRuleCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient)
rivieraClient := client.rivieraClient
createRequest := rivieraClient.NewRequest()
createRequest.Command = &sql.CreateOrUpdateFirewallRule{
Name: d.Get("name").(string),
ResourceGroupName: d.Get("resource_group_name").(string),
ServerName: d.Get("server_name").(string),
StartIPAddress: azure.String(d.Get("start_ip_address").(string)),
EndIPAddress: azure.String(d.Get("end_ip_address").(string)),
}
createResponse, err := createRequest.Execute()
if err != nil {
return fmt.Errorf("Error creating SQL Server Firewall Rule: %s", err)
}
if !createResponse.IsSuccessful() {
return fmt.Errorf("Error creating SQL Server Firewall Rule: %s", createResponse.Error)
}
readRequest := rivieraClient.NewRequest()
readRequest.Command = &sql.GetFirewallRule{
Name: d.Get("name").(string),
ResourceGroupName: d.Get("resource_group_name").(string),
ServerName: d.Get("server_name").(string),
}
readResponse, err := readRequest.Execute()
if err != nil {
return fmt.Errorf("Error reading SQL Server Firewall Rule: %s", err)
}
if !readResponse.IsSuccessful() {
return fmt.Errorf("Error reading SQL Server Firewall Rule: %s", readResponse.Error)
}
resp := readResponse.Parsed.(*sql.GetFirewallRuleResponse)
d.SetId(*resp.ID)
return resourceArmSqlFirewallRuleRead(d, meta)
}
示例9: expandAzureRmLoadBalancerRule
func expandAzureRmLoadBalancerRule(d *schema.ResourceData, lb *network.LoadBalancer) (*network.LoadBalancingRule, error) {
properties := network.LoadBalancingRulePropertiesFormat{
Protocol: network.TransportProtocol(d.Get("protocol").(string)),
FrontendPort: azure.Int32(int32(d.Get("frontend_port").(int))),
BackendPort: azure.Int32(int32(d.Get("backend_port").(int))),
EnableFloatingIP: azure.Bool(d.Get("enable_floating_ip").(bool)),
}
if v, ok := d.GetOk("idle_timeout_in_minutes"); ok {
properties.IdleTimeoutInMinutes = azure.Int32(int32(v.(int)))
}
if v := d.Get("load_distribution").(string); v != "" {
properties.LoadDistribution = network.LoadDistribution(v)
}
if v := d.Get("frontend_ip_configuration_name").(string); v != "" {
rule, _, exists := findLoadBalancerFrontEndIpConfigurationByName(lb, v)
if !exists {
return nil, fmt.Errorf("[ERROR] Cannot find FrontEnd IP Configuration with the name %s", v)
}
feip := network.SubResource{
ID: rule.ID,
}
properties.FrontendIPConfiguration = &feip
}
if v := d.Get("backend_address_pool_id").(string); v != "" {
beAP := network.SubResource{
ID: &v,
}
properties.BackendAddressPool = &beAP
}
if v := d.Get("probe_id").(string); v != "" {
pid := network.SubResource{
ID: &v,
}
properties.Probe = &pid
}
lbRule := network.LoadBalancingRule{
Name: azure.String(d.Get("name").(string)),
LoadBalancingRulePropertiesFormat: &properties,
}
return &lbRule, nil
}
示例10: expandRedisConfiguration
func expandRedisConfiguration(d *schema.ResourceData) *map[string]*string {
configuration := d.Get("redis_configuration").([]interface{})
output := make(map[string]*string)
if configuration == nil {
return &output
}
// TODO: can we use this to remove the below? \/
//config := configuration[0].(map[string]interface{})
for _, v := range configuration {
config := v.(map[string]interface{})
maxClients := config["maxclients"].(string)
if maxClients != "" {
output["maxclients"] = azure.String(maxClients)
}
maxMemoryDelta := config["maxmemory_delta"].(string)
if maxMemoryDelta != "" {
output["maxmemory-delta"] = azure.String(maxMemoryDelta)
}
maxMemoryReserved := config["maxmemory_reserved"].(string)
if maxMemoryReserved != "" {
output["maxmemory-reserved"] = azure.String(maxMemoryReserved)
}
maxMemoryPolicy := config["maxmemory_policy"].(string)
if maxMemoryPolicy != "" {
output["maxmemory-policy"] = azure.String(maxMemoryPolicy)
}
}
return &output
}
示例11: expandAzureRmLoadBalancerProbe
func expandAzureRmLoadBalancerProbe(d *schema.ResourceData, lb *network.LoadBalancer) (*network.Probe, error) {
properties := network.ProbePropertiesFormat{
NumberOfProbes: azure.Int32(int32(d.Get("number_of_probes").(int))),
IntervalInSeconds: azure.Int32(int32(d.Get("interval_in_seconds").(int))),
Port: azure.Int32(int32(d.Get("port").(int))),
}
if v, ok := d.GetOk("protocol"); ok {
properties.Protocol = network.ProbeProtocol(v.(string))
}
if v, ok := d.GetOk("request_path"); ok {
properties.RequestPath = azure.String(v.(string))
}
probe := network.Probe{
Name: azure.String(d.Get("name").(string)),
Properties: &properties,
}
return &probe, nil
}
示例12: expandAzureRmVirtualMachineDiagnosticsProfile
func expandAzureRmVirtualMachineDiagnosticsProfile(d *schema.ResourceData) *compute.DiagnosticsProfile {
bootDiagnostics := d.Get("boot_diagnostics").([]interface{})
diagnosticsProfile := &compute.DiagnosticsProfile{}
if len(bootDiagnostics) > 0 {
bootDiagnostic := bootDiagnostics[0].(map[string]interface{})
diagnostic := &compute.BootDiagnostics{
Enabled: riviera.Bool(bootDiagnostic["enabled"].(bool)),
StorageURI: riviera.String(bootDiagnostic["storage_uri"].(string)),
}
diagnosticsProfile.BootDiagnostics = diagnostic
return diagnosticsProfile
}
return nil
}
示例13: TestAccCreateDnsZone
func TestAccCreateDnsZone(t *testing.T) {
rgName := test.RandPrefixString("testrg_", 20)
zoneName := test.RandString(10) + ".com"
test.Test(t, test.TestCase{
Steps: []test.Step{
&test.StepRegisterResourceProvider{
Namespace: "Microsoft.Network",
},
&test.StepCreateResourceGroup{
Name: rgName,
Location: azure.WestUS,
},
&test.StepRunCommand{
StateBagKey: "dnszone",
RunCommand: &CreateDNSZone{
Name: zoneName,
ResourceGroupName: rgName,
Location: azure.Global,
Tags: map[string]*string{
"Purpose": azure.String("Acceptance Testing"),
},
},
StateCommand: &GetDNSZone{
Name: zoneName,
ResourceGroupName: rgName,
},
CleanupCommand: &DeleteDNSZone{
Name: zoneName,
ResourceGroupName: rgName,
},
},
&test.StepAssert{
StateBagKey: "dnszone",
Assertions: seq.Map{
"Name": zoneName,
"NumberOfRecordSets": 2,
},
},
},
})
}
示例14: TestAccUpdateResourceGroup
func TestAccUpdateResourceGroup(t *testing.T) {
rgName := RandPrefixString("testrg_", 20)
Test(t, TestCase{
Steps: []Step{
&StepCreateResourceGroup{
Name: rgName,
Location: azure.WestUS,
},
&StepAssert{
StateBagKey: "resourcegroup",
Assertions: seq.Map{
"Name": rgName,
"Location": azure.WestUS,
},
},
&StepRunCommand{
StateBagKey: "resourcegroup",
RunCommand: &azure.UpdateResourceGroup{
Name: rgName,
Tags: map[string]*string{
"Purpose": azure.String("Acceptance Testing"),
},
},
StateCommand: &azure.GetResourceGroup{
Name: rgName,
},
},
&StepAssert{
StateBagKey: "resourcegroup",
Assertions: seq.Map{
"Name": rgName,
"Tags.Purpose": "Acceptance Testing",
},
},
},
})
}
示例15: TestAccCreateDnsARecordSet
func TestAccCreateDnsARecordSet(t *testing.T) {
rgName := test.RandPrefixString("testrg_", 20)
zoneName := test.RandString(10) + ".com"
recordSetName := test.RandPrefixString("rs_", 10)
test.Test(t, test.TestCase{
Steps: []test.Step{
&test.StepRegisterResourceProvider{
Namespace: "Microsoft.Network",
},
&test.StepCreateResourceGroup{
Name: rgName,
Location: azure.WestUS,
},
&test.StepRunCommand{
StateBagKey: "dnszone",
RunCommand: &CreateDNSZone{
Name: zoneName,
ResourceGroupName: rgName,
Location: azure.Global,
Tags: map[string]*string{
"Purpose": azure.String("Acceptance Testing"),
},
},
StateCommand: &GetDNSZone{
Name: zoneName,
ResourceGroupName: rgName,
},
CleanupCommand: &DeleteDNSZone{
Name: zoneName,
ResourceGroupName: rgName,
},
},
&test.StepRunCommand{
StateBagKey: "dnsrecordset",
RunCommand: &CreateARecordSet{
Name: recordSetName,
ZoneName: zoneName,
ResourceGroupName: rgName,
Location: azure.Global,
Tags: map[string]*string{
"Purpose": azure.String("Acceptance Testing"),
},
TTL: 300,
ARecords: []ARecord{
ARecord{
IPv4Address: "10.0.10.1",
},
ARecord{
IPv4Address: "10.0.10.2",
},
},
},
StateCommandURIKey: "ID",
StateCommand: &GetARecordSet{},
CleanupCommand: &DeleteRecordSet{
Name: recordSetName,
ZoneName: zoneName,
ResourceGroupName: rgName,
RecordSetType: "A",
},
},
&test.StepAssert{
StateBagKey: "dnsrecordset",
Assertions: seq.Map{
"TTL": 300,
"Name": recordSetName,
"Location": azure.Global,
"ARecords[0].ipv4Address": "10.0.10.1",
"ARecords[1].ipv4Address": "10.0.10.2",
},
},
},
})
}