从emacs调用时,goimports的行为有所不同

I'm observing a puzzling behaviour of the goimports command called from emacs. I'm using the svgo go package, and a minimal program example in the doc imports "github.com/ajstarks/svgo"

The code works fine. The goimports command is a "Tool to fix (add, remove) your Go imports automatically". Since the "github.com/ajstarks/svgo" is needed, I don't expect goimports to remove it. And it's true when I call it from the terminal:

$ head gg.go 

package main

import (
    "os"
    "github.com/ajstarks/svgo"
)


func main() {

then:

$ goimports gg.go | head

package main

import (
    "os"

    "github.com/ajstarks/svgo"
)

func main() {

as expected, it just rearranged the imports following the "first the standard library, then the external packages". Now the funny part: when I call goimports from emacs, it deletes the "github.com/ajstarks/svgo" line! (and the program no longer compiles).

Here's (the relevant part of) my .init file:

(setq exec-path (cons "/usr/local/go/bin" exec-path))
(add-to-list 'exec-path "~/go/bin")

(defun my-go-mode-hook ()
  (setq gofmt-command "goimports")  ; Use goimports instead of go-fmt
  (add-hook 'before-save-hook 'gofmt-before-save))

(add-hook 'go-mode-hook 'my-go-mode-hook)

If I comment the (setq gofmt-command "goimports") line, the svgo import doesn't get deleted.

How's this possible?