Get Endpoint Address for suggestion form

This commit is contained in:
Khanh Ngo 2020-04-20 16:50:50 +07:00
parent deecd9c267
commit 85e466698f
No known key found for this signature in database
GPG key ID: D5FAA6A16150E49E
7 changed files with 164 additions and 2 deletions

View file

@ -281,3 +281,25 @@ func GlobalSettingSubmit() echo.HandlerFunc {
return c.JSON(http.StatusOK, jsonHTTPResponse{true, "Updated global settings successfully"})
}
}
// MachineIPAddresses handler to get local interface ip addresses
func MachineIPAddresses() echo.HandlerFunc {
return func(c echo.Context) error {
// get private ip addresses
interfaceList, err := util.GetInterfaceIPs()
if err != nil {
return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, "Cannot get machine ip addresses"})
}
// get public ip address
// TODO: Remove the go-external-ip dependency
publicInterface, err := util.GetPublicIP()
if err != nil {
log.Warn("Cannot get machine public ip address: ", err)
} else {
interfaceList = append(interfaceList, publicInterface)
}
return c.JSON(http.StatusOK, interfaceList)
}
}