feat: share link
This commit is contained in:
29
internal/shareLink/shareLink.go
Normal file
29
internal/shareLink/shareLink.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package sharelink
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"lash"
|
||||
"lash/internal/errx"
|
||||
"net"
|
||||
)
|
||||
|
||||
func GenerateShareLink(port int) string {
|
||||
link := "http://"
|
||||
link += getLocalIP()
|
||||
link += fmt.Sprintf(":%d", port)
|
||||
link += "/"
|
||||
link += lash.ShareLinkToken
|
||||
return link
|
||||
}
|
||||
|
||||
func getLocalIP() string {
|
||||
conn, err := net.Dial("udp", "8.8.8.8:80")
|
||||
if err != nil {
|
||||
errx.FatalPerror(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
localAddress := conn.LocalAddr().(*net.UDPAddr)
|
||||
|
||||
return localAddress.IP.String()
|
||||
}
|
||||
Reference in New Issue
Block a user