What and how value should I pass to the function

Folks,
I have a function ``` f5.ModifyVirtualServer(vs.Name, config)`` which uses struct as shown below

type VirtualServer struct {
	Name                       string `json:"name,omitempty"`
	Partition                  string `json:"partition,omitempty"`
	FullPath                   string `json:"fullPath,omitempty"`
	Generation                 int    `json:"generation,omitempty"`
        Rules               []string  `json:"rules,omitempty"`

I want to pass value of Rules to the above function, the value is "/Common/Tetration_TCP_L4_ipfix"
the function code is below

func (b *BigIP) ModifyVirtualServer(name string, config *VirtualServer) error {
	return b.put(config, uriLtm, uriVirtual, name)
}

You mean something like this :

vs := VirtualServer{"Name","Partition","FullPath",1,[]string{"/Common/Tetration_TCP_L4_ipfix"}}
ModifyVirtualServer("name", &vs)

It gave me error

for _, vs := range vservers.VirtualServers {
		fmt.Printf(" Name: %s Virtual Server type is %s %s\n ", vs.Name, vs.IPProtocol, vs.Rules)
		vs := VirtualServer{"Name", "Partition", "FullPath", 1, []string{"/Common/Tetration_TCP_L4_ipfix"}}
		//vs.Description = "Modified Sanjay Shitole"
		f5.ModifyVirtualServer(vs.Name, &vs)

	}
 go run f5gohello.go
# command-line-arguments
./f5gohello.go:175:9: undefined: VirtualServer
SJC-ML-00028512:tet shitole$ 

The function is at https://github.com/f5devcentral/terraform-provider-bigip/blob/master/vendor/github.com/f5devcentral/go-bigip/ltm.go

My example is not to be copied as is. The error comes from the fact that VirtualServer struct is to be imported from an other package, the same as ModifyVirtualServer. You should prefix VirtualServer with its package name as well as for ModifyVirtualServer.

1 Like

Thanks @imatmati it worked !!!

for _, vs := range vservers.VirtualServers {
		fmt.Printf(" Name: %s Virtual Server type is %s %s\n ", vs.Name, vs.IPProtocol, vs.Rules)
		vs.Rules = []string{"/Common/Tetration_TCP_L4_ipfix"}
		//vs.Description = "Modified Sanjay Shitole"
		f5.ModifyVirtualServer(vs.Name, &vs)

	}

}

go run f5gohello.go
 TCP iRule  exists on your local machine
 UDP iRule exists on your local machine
 Attempting to connect...
 Checking TCP irule exists on bigip ......
Name: Tetration_TCP_L4_ipfix
 TCP irule Exists on BIG-IP

To know more about that https://tour.golang.org/moretypes/1
Go has pointers came from c.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.