Don't refer to two things by one name (server)

This commit is contained in:
Chandler Swift 2020-03-29 22:09:57 -05:00
parent 64cd4dab40
commit e24a9b1a52

View file

@ -72,37 +72,37 @@ func main() {
fmt.Printf("Error parsing HTML template: %v\n", err) fmt.Printf("Error parsing HTML template: %v\n", err)
} }
for _, server := range config.Servers { for _, s := range config.Servers {
server.rconConnection, err = rcon.Dial(fmt.Sprintf("%v:%v", server.Host, server.RCONPort), server.RCONPassword) s.rconConnection, err = rcon.Dial(fmt.Sprintf("%v:%v", s.Host, s.RCONPort), s.RCONPassword)
if err != nil { if err != nil {
log.Fatalf("Error making RCON connection to %v: %v", server.Title, err) log.Fatalf("Error making RCON connection to %v: %v", s.Title, err)
} }
defer server.rconConnection.Close() defer s.rconConnection.Close()
} }
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := []serverData{} data := []serverData{}
for _, server := range config.Servers { for _, s := range config.Servers {
playersOnline, err := server.rconCommand("/players o") playersOnline, err := s.rconCommand("/players o")
if err != nil { if err != nil {
log.Printf("Error executing players online command: %v\n", err) log.Printf("Error executing players online command: %v\n", err)
} }
version, err := server.rconCommand("/version") version, err := s.rconCommand("/version")
if err != nil { if err != nil {
log.Printf("Error executing version command: %v\n", err) log.Printf("Error executing version command: %v\n", err)
} }
data = append(data, serverData{ data = append(data, serverData{
server.Host, s.Host,
server.Port, s.Port,
server.Title, s.Title,
playersOnline, playersOnline,
version, version,
server.Description, s.Description,
}) })
} }
@ -116,7 +116,7 @@ func main() {
Cache: autocert.DirCache("certs"), Cache: autocert.DirCache("certs"),
} }
server := &http.Server{ srv := &http.Server{
Addr: ":https", Addr: ":https",
TLSConfig: &tls.Config{ TLSConfig: &tls.Config{
GetCertificate: certManager.GetCertificate, GetCertificate: certManager.GetCertificate,
@ -126,6 +126,6 @@ func main() {
go http.ListenAndServe(":http", certManager.HTTPHandler(nil)) // Handler for LetsEncrypt go http.ListenAndServe(":http", certManager.HTTPHandler(nil)) // Handler for LetsEncrypt
fmt.Println("Serving...") fmt.Println("Serving...")
server.ListenAndServeTLS("", "") // Key/cert come from server.TLSConfig srv.ListenAndServeTLS("", "") // Key/cert come from srv.TLSConfig
} }