Create basic html for site
This commit is contained in:
commit
e6cc669333
19
LICENSE
Normal file
19
LICENSE
Normal file
|
@ -0,0 +1,19 @@
|
|||
MIT License Copyright (c) <year> <copyright holders>
|
||||
|
||||
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.
|
46
server.go
Normal file
46
server.go
Normal file
|
@ -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)
|
||||
|
||||
}
|
20
templates/index.html
Normal file
20
templates/index.html
Normal file
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>blackolivepineapple.pizza Factorio Server</title>
|
||||
<style>
|
||||
html {
|
||||
font-family: sans-serif;
|
||||
padding: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>blackolivepineapple.pizza Factorio Server</h1>
|
||||
<ul>
|
||||
<li><b>IP Address:</b> {{.IPAddr}}</li>
|
||||
<li><b>Server Name:</b> {{.Title}}</li>
|
||||
<li><b>Current players:</b><br>{{.Players}}</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue