I have a website that has several different functions . I can get to my website by using localhost:5000/ , when I run it in debug mode using vscode-go debugger I get the following message API server listening at: 127.0.0.1:52238
I have a Name function that returns several strings but I can not hit the breakpoint in debug mode . I put a breakpoint in my Name function and put the url as follows: 127.0.0.1:52238/name however it does not hit the breakpoint. What could be going on here ? My code is below if i run the application normally and put http://localhost:5000/name then everything works but in debug mode this 127.0.0.1:52238/name does not hit the breakpoint or page . I am using Go as a backend api so I'll need to hit url endpoints to see what's going on. Is there someway that I can make the debug port also :5000 ?
-- Main
package main
import (
"github.com/gorilla/mux"
"runtime"
"./Models"
"./Controllers"
)
func main() {
Controllers.CircleRoutes(r)
srv := &http.Server{
ReadTimeout: 20 * time.Second,
WriteTimeout: 20 * time.Second,
IdleTimeout: 120 * time.Second,
Addr: ":5000",
}
srv.ListenAndServe()
}
// Circles Route
package Controllers
func Name(w http.ResponseWriter, r *http.Request) {
var result string
r.ParseForm()
result = "Success"
io.WriteString(w, result)
}
func CircleRoutes(r *mux.Router) {
r.HandleFunc("/name", Name)
}
It looks you are using vscode-go debugger. You can configure the port from launch.json configuration file from your vscode.
The config should look like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {
"GOPATH": <your GOPATH>
},
"args": [],
"showLog": true
}
],
"go.lintTool": "gometalinter"
}
You can change port from above settings. To find launch.json
, just ctrl+P
and type launch.json it will show dropdown result of search in your vscode.