Skip to content

Commit bd71ae0

Browse files
committed
updated
1 parent bbaf1ab commit bd71ae0

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ WORKDIR /build
1313
COPY . .
1414

1515
# Build the application
16-
RUN go build -o simple_http_server ./simple_http_server.go
16+
RUN go build -o simple_http_server ./simple_http_server.go ./utils.go
1717

1818
# Move to /dist directory as the place for resulting binary folder
1919
WORKDIR /dist

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Remote IP
1313
- All Request Headers
1414
- And Environment Variable called `YOUR_ENV`
15+
- optionally mount html dir to `/dist/html` to serve html pages
1516

1617
### How to use it?
1718

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module pareshpawar/simple-http-server
1+
module pareshpawar.com/simple-http-server
22

33
go 1.20
44

simple_http_server.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package main
33
import (
44
"fmt"
55
"log"
6-
"net"
76
"net/http"
87
"os"
98
"time"
109

1110
"github.com/common-nighthawk/go-figure"
11+
12+
"pareshpawar.com/simple-http-server/utils"
1213
)
1314

1415
func main() {
@@ -40,7 +41,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
4041
fmt.Fprintf(w, "Request Type ==> %s %s %s\n", r.Method, r.URL, r.Proto)
4142
fmt.Fprintf(w, "Hostname/Host ==> %s\n", r.Host)
4243
fmt.Fprintf(w, "Remote Address ==> %s\n", r.RemoteAddr)
43-
fmt.Fprintf(w, "Local Address ==> %s\n\n", GetOutboundIP())
44+
fmt.Fprintf(w, "Local Address ==> %s\n\n", utils.GetMyOutboundIP())
4445

4546
// print request headers
4647
for key, value := range r.Header {
@@ -68,13 +69,3 @@ func handler(w http.ResponseWriter, r *http.Request) {
6869
fmt.Fprintf(w, " by PareshPawar.com \n")
6970
fmt.Fprintf(w, "----------------------------------------------------------\n")
7071
}
71-
72-
func GetOutboundIP() net.IP {
73-
conn, err := net.Dial("udp", "1.1.1.1:80")
74-
if err != nil {
75-
log.Fatal(err)
76-
}
77-
defer conn.Close()
78-
localAddr := conn.LocalAddr().(*net.UDPAddr)
79-
return localAddr.IP
80-
}

utils/iputils.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package utils
2+
3+
import (
4+
"log"
5+
"net"
6+
)
7+
8+
func GetMyOutboundIP() net.IP {
9+
conn, err := net.Dial("udp", "1.1.1.1:80")
10+
if err != nil {
11+
log.Fatal(err)
12+
}
13+
defer conn.Close()
14+
localAddr := conn.LocalAddr().(*net.UDPAddr)
15+
return localAddr.IP
16+
}

0 commit comments

Comments
 (0)