Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Organize imports on save will add slog from "golang.org/x/exp/slog" instead of "log/slog" #2996

Answered by ousloob
jurisevo asked this question in Help
Discussion options

Hi!

I have this annoying issue when organizing imports will always prefer slog from "golang.org/x/exp/slog" instead of standard library. The go version in go.mod states go 1.21.0 so I have a reason to believe that log/slog should have priority in this case. I have no idea if this is a bug or configurable behavior, at least I have not found anything related to specific preferences when it comes to package imports.

Any ideas or tips how to solve this?

You must be logged in to vote

@jurisevo
You can handle this in two ways:

On VS Code, add this to your settings.json:

{
 "gopls": {
 "importShortcut": "Definition"
 }
} 

Alternatively, you can remove the experimental package by running go get -d golang.org/x/exp/slog@none followed by go mod tidy. This will clean up your dependencies and force the usage of the standard library version from log/slog. Make sure to update your imports from golang.org/x/exp/slog to log/slog in your code.

Replies: 1 comment

Comment options

@jurisevo
You can handle this in two ways:

On VS Code, add this to your settings.json:

{
 "gopls": {
 "importShortcut": "Definition"
 }
} 

Alternatively, you can remove the experimental package by running go get -d golang.org/x/exp/slog@none followed by go mod tidy. This will clean up your dependencies and force the usage of the standard library version from log/slog. Make sure to update your imports from golang.org/x/exp/slog to log/slog in your code.

You must be logged in to vote
0 replies
Answer selected by jurisevo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /