hi, guys:
I’m new to go and try to write terraform provider.
Here is Microsoft API I’m calling.
I’m currently writing a provider call Pipeline and have code as following:
func expandRunPipeline(d *schema.ResourceData, forCreate bool) (*pipelines.RunPipelineParameters , string, int, error) {
Project := d.Get("project_name").(string)
variables, err := expandVariables(d)
//Ref_Name := converter.String(d.Get("sourceBranch").(string))
//token:= converter.String(d.Get("parameter_accessKey").(string))
PipelineId := d.Get("pipeline_id").(int)
if err != nil {
return nil, "",0,fmt.Errorf("Error expanding varibles: %+v", err)
}
Repository_resource :=map[string]pipelines.RepositoryResourceParameters{
RefName: d.Get("sourceBranch").(string),
"Token": converter.String(d.Get("parameter_accessKey").(string)),
}
RunResource := pipelines.RunResourcesParameters{
Repositories: &Repository_resource,
}
RunPipeline := pipelines.RunPipelineParameters{
Resources: &RunResource,
Variables: variables,
}
return &RunPipeline, Project ,PipelineId,nil
}
RefName: d.Get(“sourceBranch”).(string), is the line got issue and it says RefName is undeclared?
any ideas about this one?
Sorry guys. I make it simpler here.
[https://play.golang.org/p/QRgmRiGyFgk](http://Playground link)
package main
import (
"fmt"
)
type StructWithMapPointer struct {
Strings *map[string]RepositoryResourceParameters
}
type RepositoryResourceParameters struct {
RefName *string `json:"refName,omitempty"`
}
func main() {
test1:="sdfsadf"
m := map[string]RepositoryResourceParameters{
RefName: test1,
}
mPointer := &m
// Set via pointer
// (*mPointer)["RefName"] = test1
// Get via pointer
fmt.Println("RefName is:", (*mPointer)["RefName"])
}
petrus
(petrus)
3
package main
import "fmt"
type StructWithMapPointer struct {
Strings *map[string]RepositoryResourceParameters
}
type RepositoryResourceParameters struct {
RefName *string `json:"refName,omitempty"`
}
func main() {
mapkey := "qwert"
refname := "sdfsadf"
m := map[string]RepositoryResourceParameters{
mapkey: RepositoryResourceParameters{RefName: &refname},
}
fmt.Println("RefName is:", *m[mapkey].RefName)
}
https://play.golang.org/p/MOFaoeLcGdZ
RefName is: sdfsadf
I am not entirely sure why you use a pointer for the string in your struct, but this works
https://play.golang.org/p/3TBGXQ15KhU
package main
import (
"fmt"
)
type RepositoryResourceParameters struct {
RefName string `json:"refName,omitempty"`
}
func main() {
m := make(map[string]RepositoryResourceParameters)
m["RefName"] = RepositoryResourceParameters{RefName: "Hello Kitty"}
fmt.Println(m["RefName"].RefName)
}
Setting the value m[“RefName”] = RepositoryResourceParameters{RefName: “Hello Kitty”}
Getting the value m[“RefName”].RefName
system
(system)
Closed
5
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.