-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.go
45 lines (39 loc) · 1.19 KB
/
web.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"log"
"net"
"net/http"
"strconv"
"strings"
)
func startWebServer(outputDir string, port int) {
http.Handle("/android/repository/", http.StripPrefix("/android/repository/", http.FileServer(http.Dir(outputDir))))
fmt.Printf("Serving files from %s\n", outputDir)
fmt.Printf("Add the following URLs to SDK Manager:\n")
localIP := getLocalIP()
fmt.Printf("%s\n", strings.Replace(urlRepo11, "dl.google.com", localIP, 1))
fmt.Printf("%s\n", strings.Replace(urlAddonsList2, "dl.google.com", localIP, 1))
fmt.Printf("%s\n", strings.Replace(urlAddon, "dl.google.com", localIP, 1))
err := http.ListenAndServe(":"+strconv.Itoa(port), nil) //localIP+":"+string(port), nil)
if err != nil {
panic(err)
log.Fatalf("Could not start webserver on port: %d", port)
}
}
// getLocalIP returns the non loopback local IP of the host
func getLocalIP() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
return ""
}
for _, address := range addrs {
// check the address type and if it is not a loopback the display it
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.IP.String()
}
}
}
return ""
}