xanzy / go-gitlab

GitLab Go SDK
Apache License 2.0
2.36k stars 935 forks source link

There is a problem with the returned parameters of gitlab.NewClient. #1914

Closed RiverIsWeak closed 4 months ago

RiverIsWeak commented 4 months ago

your code demo is image

But when I used this example to learn the framework, I suddenly found that no matter what I filled in, it would not produce the result of err! = nil. image

my go-gitlab version is thisgithub.com/xanzy/go-gitlab v0.102.0 Looking forward to your reply, thanks

RiverIsWeak commented 4 months ago

and i find this version is the latest version in https://pkg.go.dev/github.com/xanzy/go-gitlab?tab=versions

vntw commented 4 months ago

What do you expect instead? You created a client without error, that you can use to call (for example) a list of users (like it's done in line 5 of that example). There is no "connect" happening in that step

RiverIsWeak commented 4 months ago

What do you expect instead? You created a client without error, that you can use to call (for example) a list of users (like it's done in line 5 of that example). There is no "connect" happening in that step

I think there should be an explicit err prompt that the connection is invalid, like java to throw a custom exception(I am a java developer and am using go-gitlab as my first framework for learning the go language 😆) @vntw

vntw commented 4 months ago

Well, you will get that error when you actually call something, for example

users, _, err := git.Users.ListUsers(&gitlab.ListUsersOptions{})

with an invalid endpoint or invalid credentials but not when creating a new client. Logging success connect is wrong, it doesn't connect to anything yet, it just created a client. The error shows up correctly immediately after (List projects failed… in your screenshot) when the library tries to access the GitLab API for the first time.

RiverIsWeak commented 4 months ago

Well, you will get that error when you actually call something, for example

users, _, err := git.Users.ListUsers(&gitlab.ListUsersOptions{})

with an invalid endpoint or invalid credentials but not when creating a new client. Logging success connect is wrong, it doesn't connect to anything yet, it just created a client. The error shows up correctly immediately after (List projects failed… in your screenshot) when the library tries to access the GitLab API for the first time.

I got your mean,and thank you for your reply. Have a wonderful day.😆 @vntw