allow setting port via flag, add systemd service
This commit is contained in:
parent
adf11183cc
commit
34ddd05921
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue