mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
add /api/outbound-ip api
This commit is contained in:
parent
46ce0476be
commit
cd957460c9
|
@ -88,6 +88,19 @@ func (s *Server) newEngine() *gin.Engine {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
r.GET("/api/outbound-ip", func(c *gin.Context) {
|
||||||
|
outboundIP, err := GetOutboundIP()
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"outboundIP": outboundIP.String(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
r.GET("/api/trades", func(c *gin.Context) {
|
r.GET("/api/trades", func(c *gin.Context) {
|
||||||
if s.Environ.TradeService == nil {
|
if s.Environ.TradeService == nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "database is not configured"})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "database is not configured"})
|
||||||
|
@ -621,3 +634,14 @@ func listenAndServe(srv *http.Server) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetOutboundIP() (net.IP, error) {
|
||||||
|
conn, err := net.Dial("udp", "8.8.8.8:80")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
||||||
|
return localAddr.IP, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user