After starting the program the program directly stop the Go Web Gin framework of problem-solving


1. The following original code

package main

import "github.com/gin-gonic/gin"

func main() {
    r := gin.Default()
    r.GET("/ping", func(c *gin.Context) {
        c.JSON(200, gin.H{
            "message": "pong",
        })
    })
    r.Run("8080") 
}

After using Gin framework of a monitor port, it found no error, run up, but did not succeed in listening to the port.


2. troubleshooter to solve

Fmt output log through the investigation and other means of, and did not find any problems.

So, a brief look at the official website, copy the example direct run down, but it is normal!
example:

package main

import "github.com/gin-gonic/gin"

func main() {
    r := gin.Default()
    r.GET("/ping", func(c *gin.Context) {
        c.JSON(200, gin.H{
            "message": "pong",
        })
    })
    r.Run(":8080") 
}

Contrast found at

r.Run("8080") 		//我的
r.Run(":8080") 		//example

Missing colon, resulting in no success running up listening port! When we use must pay attention to these details!

Published 204 original articles · won praise 59 · Views 140,000 +

Guess you like

Origin blog.csdn.net/baidu_34122324/article/details/90182120