首页 > 解决方案 > 无法从其他设备访问 Windows Server 上的 Go API

问题描述

我无法在 Windows 服务器上连接到我的 Go API,端口允许,但它仍然不允许我从不同设备连接到 API,但我的 Go API 使用邮递员在 localhost 上工作

更改端口,更改e-channel.ini文件但仍然无法连接

这是我的代码

package main

import (
    "flag"

    "fmt"
    "log"
    "net/http"

    "./config_db"
    "./controller"
    "github.com/gin-gonic/gin"
    _ "github.com/go-sql-driver/mysql"
)

func main() {
    fileConfig := flag.String("f", "e_channel.ini", "config file")
    flag.Parse()
    config, err := config_db.LoadConfig(*fileConfig)
    if err != nil {
        fmt.Println(err.Error())

    }
    db := config_db.Connectdb()
    inDB := &controller.DB{DBE: db}
    r := gin.Default()

    fmt.Println("Listening at Port " + config.ListeningPort)
    r.Run(":" + config.ListeningPort)

}

func root(c *gin.Context) {
    c.Header("Content-Type", "application/json")
    c.JSON(http.StatusOK, gin.H{
        "message": "welcome my api",
    })
}

这是我的 e-channel.ini

{
    "app_name"       : "HELLOWORLD_API",
    "listening_port" : "1195",
    "host"           : "0.0.0.0",
    "port"           : "3306",
    "user"           : "root",
    "passwd"         : "",
    "dbname"        : "kube71"
}

我希望 API 可以被其他设备访问。

标签: httpgoserverportrdp

解决方案


推荐阅读