watson-developer-cloud / go-sdk

:mouse: go SDK for the IBM Watson services.
Apache License 2.0
71 stars 25 forks source link

Failed to compile due to error on line 72 in language_translator_v3.go #81

Closed sljm12 closed 4 years ago

sljm12 commented 4 years ago

Remember, an issue is not the place to ask questions. If you have issues with the APIs or have a question about the Watson services, see Stack Overflow.

Before you open an issue, please check if a similar issue already exists or has been closed before.

Check service status

  1. For service issues or 5xx errors, first, go to the IBM Cloud status page and check the status of the service.
  2. If the service status is OK, continue with a bug report.

Overview What is the issue? Be concise and clear. Compilation failed

Expected behavior What did you expect to happen? Compilation to succeed

Actual behavior What actually happened? During go build the following error was produced.

go\pkg\mod\github.com\watson-developer-cloud\go-sdk@v1.5.0\languagetranslatorv3\language_translator_v3.go:72:41: not enough arguments in call to core.NewBaseService have (core.ServiceOptions) want (core.ServiceOptions, string, string)

How to reproduce Help us to reproduce what you experienced. Include your code snippets (without credentials) go get -u github.com/IBM/go-sdk-core/... go get -u github.com/watson-developer-cloud/go-sdk@v1.5.0

----- Code ------ package main

import ( "fmt"

"github.com/IBM/go-sdk-core/core"
"github.com/watson-developer-cloud/go-sdk/languagetranslatorv3"

)

func main() {

authenticator := &core.IamAuthenticator{
    ApiKey: "{api_key}",
}

options := &languagetranslatorv3.LanguageTranslatorV3Options{
    Version:       "2018-05-01",
    Authenticator: authenticator,
}

languageTranslator, languageTranslatorErr := languagetranslatorv3.NewLanguageTranslatorV3(options)

if languageTranslatorErr != nil {
    panic(languageTranslatorErr)
}

languageTranslator.SetServiceURL("{url}")

result, _, responseErr := languageTranslator.Identify(
    &languagetranslatorv3.IdentifyOptions{
        Text: core.StringPtr("你好吗h"),
    },
)
if responseErr != nil {
    panic(responseErr)
}
//b, _ := json.MarshalIndent(result, "", "  ")
fmt.Println(*result.Languages[0].Language)

}

Screenshots If applicable, add screenshots to help explain your problem.

SDK Version Please provide the SDK version here. github.com/IBM/go-sdk-core v1.1.0 github.com/watson-developer-cloud/go-sdk@v1.5.0

Additional information:

Windows 10

Additional context Add any other details about the problem.

I have checked code in language_translator_v3.go

On line 72 the call to baseService, err := core.NewBaseService(serviceOptions) was missing 2 parameters.

I have replace the line with baseService, err := core.NewBaseService(serviceOptions, DefaultServiceName, "")

and it compiles and executed successfully.

jeff-arn commented 4 years ago

@sljm12 thanks for posting this! I am coming in on some of the Go SDK maintenance and I can look into this issue.

vsential commented 4 years ago

I have run into the same issue with:

Same idea on the above seems to resolve as they are both missing two parameters.

jeff-arn commented 4 years ago

Ok I have done some digging into this and I have some follow up questions:

@sljm12 it looks like you have manually specified a version of the Go SDK Core that is pretty outdated, but you are using the current version of the Go SDK. The version of the Core 1.1.0 does indeed accept 3 parameters for NewBaseService, but that changed in subsequent major releases of the core to be a method that only accepts one parameter:

https://github.com/IBM/go-sdk-core/blob/master/v4/core/base_service.go#L69

If you only add the Go SDK as a dependency to your project using go get -u github.com/watson-developer-cloud/go-sdk@v1.5.0, it should specify the correct version of the Core that it needs in your project's go.mod.

To test this, I initialized an empty project and only ran go get -u github.com/watson-developer-cloud/go-sdk@v1.5.0. Then when I built the project, it imported the correct version of the Core for me. The result was:

go.mod

module example.com/go-test

go 1.13

require (
    github.com/IBM/go-sdk-core v0.0.0-20200217212347-fe152a0e9e89
    github.com/watson-developer-cloud/go-sdk v1.5.0
)

I then pasted your code into the main.go and was able to compile the binary. Can you try this and see if it resolves your issue without having to change the core parameters?

@vsential similar to the description above, can you check what version of the Core you are using and see if the resolution above helps?

jeff-arn commented 4 years ago

Closing as I haven't heard back. I hope this addressed the issue!