Add argument to change port

This commit is contained in:
Paul-Christian Volkmer 2022-04-08 13:55:41 +02:00
parent 3460c7b815
commit 30c8af2cef
2 changed files with 17 additions and 3 deletions

View File

@ -4,6 +4,17 @@ Simple implementation of an identicon service.
== Usage == Usage
=== Start application
The application takes two optional arguments to specify the location of the config file and the port the application
is listening. The following example shows the default values used if no arguments used.
....
$ idicon -c /etc/idicon/config.toml -p 8000
....
=== Client side
HTTP `GET` is used to request an identicon image. HTTP `GET` is used to request an identicon image.
.... ....

View File

@ -4,6 +4,7 @@ import (
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
"flag" "flag"
"fmt"
"image" "image"
"image/color" "image/color"
"image/draw" "image/draw"
@ -196,13 +197,15 @@ func configure(configFile string) {
} }
func main() { func main() {
configFile := flag.String("c", "/etc/idicon/config.toml", "-c <path to config file>") configFile := flag.String("c", "/etc/idicon/config.toml", "path to config file")
port := flag.Int("p", 8000, "server port")
flag.Parse() flag.Parse()
configure(*configFile) configure(*configFile)
router := mux.NewRouter() router := mux.NewRouter()
router.HandleFunc("/avatar/{id}", requestHandler) router.HandleFunc("/avatar/{id}", requestHandler)
log.Println("Starting ...") log.Println(fmt.Sprintf("Starting on port %d ...", *port))
log.Fatal(http.ListenAndServe(":8000", router)) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), router))
} }