➜ go run main.go [GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
[GIN-debug] [WARNING] Running in"debug" mode. Switch to "release" mode in production. - using env: export GIN_MODE=release - using code: gin.SetMode(gin.ReleaseMode)
[GIN-debug] GET / --> main.main.func1 (3 handlers) [GIN-debug] Environment variable PORT is undefined. Using port :8080 by default [GIN-debug] Listening and serving HTTP on :8080
// 接收一个字符串切片参数 funcresolveAddress(addr []string)string { // 如果参数长度为0,默认监听8080 switchlen(addr) { case0: if port := os.Getenv("PORT"); port != "" { debugPrint("Environment variable PORT=\"%s\"", port) return":" + port } debugPrint("Environment variable PORT is undefined. Using port :8080 by default") return":8080" case1: // 如果参数长度为1,监听IP和端口 return addr[0] default: // 如果参数长度大于1,则报错 panic("too many parameters") } }