Create basic html for site
This commit is contained in:
commit
e6cc669333
3 changed files with 85 additions and 0 deletions
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)
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue