Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

Go compiler says "declared and not used" but they are being used

I have the following function that is giving me "variable declared and not used" errors:

type Comparison struct {
        Left []byte
        Right []byte
        Name string
}

func img(w http.ResponseWriter, r *http.Request, c appengine.Context, u *user.User) {
  key := datastore.NewKey("Comparison", r.FormValue("id"), 0, nil)
  side := r.FormValue("side")
  comparison := new(Comparison)
  err := datastore.Get(c, key, comparison)
  check(err)

  if( side == "left"){
    m, _, err := image.Decode(bytes.NewBuffer(comparison.Left))
  } else {
    m, _, err := image.Decode(bytes.NewBuffer(comparison.Right))
  }
  check(err)

  w.Header().Set("Content-type", "image/jpeg")
  jpeg.Encode(w, m, nil)
}

It gives me the following errors:

dpcompare.go:171: m declared and not used
dpcompare.go:171: err declared and not used
dpcompare.go:173: m declared and not used
dpcompare.go:173: err declared and not used
dpcompare.go:178: undefined: m
dpcompare.go:185: key declared and not used

The thing is m, err, and key are all being used. I can't wrap my head around why the compiler thinks thy are not.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...