allow setting port via flag, add systemd service

This commit is contained in:
Cyberes 2024-04-11 17:48:06 -06:00
parent adf11183cc
commit 34ddd05921
2 changed files with 19 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"flag"
"fmt"
"net"
"net/http"
@ -13,9 +14,12 @@ func getMyIP(w http.ResponseWriter, r *http.Request) {
}
func main() {
fmt.Println("Server running on 0.0.0.0:5000")
port := flag.String("port", "5000", "port to listen on")
flag.Parse()
fmt.Printf("== Server running on 0.0.0.0:%s ==\n", *port)
http.HandleFunc("/", getMyIP)
if err := http.ListenAndServe("0.0.0.0:5000", nil); err != nil {
if err := http.ListenAndServe("0.0.0.0:"+*port, nil); err != nil {
panic(err)
}
}

13
canihazip.service Normal file
View File

@ -0,0 +1,13 @@
[Unit]
Description=canihazip
After=network.target
[Service]
SyslogIdentifier=canihazip
User=example
Group=nogroup
ExecStart=/srv/canihazip/canihazip
Restart=always
[Install]
WantedBy=multi-user.target