add code
This commit is contained in:
parent
3121face9d
commit
adf11183cc
|
@ -0,0 +1,2 @@
|
|||
dist/
|
||||
canihazip
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
|
||||
OUTPUTFILE="dist/canihazip"
|
||||
|
||||
mkdir -p "$SCRIPT_DIR/dist"
|
||||
rm "$SCRIPT_DIR"/dist/canihazip &> /dev/null
|
||||
|
||||
go mod tidy
|
||||
go build -v -trimpath -ldflags "-s -w" -o "$OUTPUTFILE"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
chmod +x "$OUTPUTFILE"
|
||||
echo "Build Succeeded -> $OUTPUTFILE"
|
||||
fi
|
|
@ -0,0 +1,21 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func getMyIP(w http.ResponseWriter, r *http.Request) {
|
||||
host, _, _ := net.SplitHostPort(r.RemoteAddr)
|
||||
fmt.Fprint(w, host)
|
||||
fmt.Printf("Received request from %s\n", host)
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("Server running on 0.0.0.0:5000")
|
||||
http.HandleFunc("/", getMyIP)
|
||||
if err := http.ListenAndServe("0.0.0.0:5000", nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue