From e6cc6693330f89429e3eb53cf553f2417481e288 Mon Sep 17 00:00:00 2001 From: Chandler Swift Date: Thu, 19 Mar 2020 23:20:59 -0500 Subject: [PATCH] Create basic html for site --- LICENSE | 19 ++++++++++++++++++ server.go | 46 ++++++++++++++++++++++++++++++++++++++++++++ templates/index.html | 20 +++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 LICENSE create mode 100644 server.go create mode 100644 templates/index.html diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..204b93d --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +MIT License Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/server.go b/server.go new file mode 100644 index 0000000..f107469 --- /dev/null +++ b/server.go @@ -0,0 +1,46 @@ +package main + +import ( + "flag" + "fmt" + "html/template" + "net/http" +) + +type serverData struct { + IPAddr string + Title string + Players string +} + +func main() { + + port := flag.Int("port", 65536, "Port on which the HTTP server should serve") + server := flag.String("serverAddr", "factorio.blackolivepineapple.pizza", "Server to check status of") + flag.Parse() + + if *port < 1 || *port > 65535 { + fmt.Printf("Invalid port %v\n", *port) + return + } + + fmt.Print("Parsing templates...\n") + t, err := template.ParseFiles("templates/index.html") + if err != nil { + fmt.Printf("Error parsing HTML template: %v\n", err) + } + + data := serverData{ + *server, + "bopp server", + "none", + } + + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + t.Execute(w, data) + }) + + fmt.Printf("Serving on :%v...\n", *port) + http.ListenAndServe(fmt.Sprintf(":%v", *port), nil) + +} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..244af6a --- /dev/null +++ b/templates/index.html @@ -0,0 +1,20 @@ + + + + blackolivepineapple.pizza Factorio Server + + + +

blackolivepineapple.pizza Factorio Server

+
    +
  • IP Address: {{.IPAddr}}
  • +
  • Server Name: {{.Title}}
  • +
  • Current players:
    {{.Players}}
  • +
+ +