A
A
Alexander Ampleev2020-02-12 16:29:07
go
Alexander Ampleev, 2020-02-12 16:29:07

Why doesn't Debug work in GoLand?

Here is the code I have

package main

import (
  "github.com/go-chi/chi"
  "log"
  "net/http"
  "os"
  "os/signal"
)

var DB map[string]string

func main() {

  stopchan := make(chan os.Signal)

  router := chi.NewRouter()

  router.Route("/", func(r chi.Router) {
    r.Get("/", GetIndexHandler)
    r.Post("/", GetPostIndexHandler)
  })

  go func() {
    err := http.ListenAndServe(":8080", router)
    log.Fatal(err)
  }()

  signal.Notify(stopchan, os.Kill, os.Interrupt)

  <-stopchan
}

func GetIndexHandler(w http.ResponseWriter, r *http.Request) {
  key := chi.URLParam(r, "key")
  value, exists := DB[key]

  if exists {
    w.Write([]byte(value))
  } else {
    w.WriteHeader(http.StatusNotFound)
  }
}

func GetPostIndexHandler(w http.ResponseWriter, r *http.Request) {
  key := chi.URLParam(r, "key")
  value := chi.URLParam(r, "value")
  DB[key] = value
  w.WriteHeader(http.StatusCreated)
  w.Write([]byte(value))
}


I want to make a stop at the time of the post request to the server. I add a stop to the corresponding line: I
5e43fcc0c4f4b957574372.png
start Run -> Debug

Shows this:
5e43fd26b3471336398754.png

Strictly speaking, I did not use this before, but simply output the values ​​to the console. But now for the first time it was needed and it is not clear how to set it up. Is there anything I can do in this situation to make the breakpoint work and I can see the current values ​​of the variables?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Papa, 2020-02-12
@Ampleev

Because your application crashes on startup. And even an error displays that port 8080 is busy.

B
bvv13, 2020-07-21
@bvv13

And I just don’t stop at the breakpoint, but go through all the points to the end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question