Hi
I copied a piece of code form https://www.consul.io/docs/connect/native/go in to a main. go file.
like this:
package main
import (
"fmt"
"io/ioutil"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/connect"
)
func main() {
// Create a Consul API client
client, _ := api.NewClient(api.DefaultConfig())
// Create an instance representing this service. "my-service" is the
// name of _this_ service. The service should be cleaned up via Close.
svc, _ := connect.NewService("my-service", client)
defer svc.Close()
// Get an HTTP client
httpClient := svc.HTTPClient()
// Perform a request, then use the standard response
resp, _ := httpClient.Get("http://web.service.consul/autoCode/getColumn")
buf, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(buf))
}
then execute in sequence
go mod init
go get - u -v github.com/hashicorp/consul/api
go get -u - v github.com/hashicorp/consul/connect
go mod tidy
go test
out put error:
\go\pkg\mod\github.com\hashicorp\consul@v1.11.4\connect\testing.go:112:42: undefined: freeport.GetOne
OS: win10
Go version:1.17.7
Can anyone help me solve this question. THANKS.