forked from daBONDi/go-rest-wol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (32 loc) · 1.41 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
// ComputerList contains all Computers who we can use to work with
var ComputerList []Computer
func main() {
// Start Processing Shell Arguments or use Default Values defined i const.go
httpPort, computerFilePath := processShellArgs()
// Process Environment Variables
httpPort, computerFilePath = processEnvVars(httpPort, computerFilePath)
// Loading Computer CSV File to Memory File in Memory
var loadComputerCSVFileError error
if ComputerList, loadComputerCSVFileError = loadComputerList(computerFilePath); loadComputerCSVFileError != nil {
log.Fatalf("Error on loading Computerlist File \"%s\" check File access and formating", computerFilePath)
}
// Init HTTP Router - mux
router := mux.NewRouter()
// Define Home Route
router.HandleFunc("/", renderHomePage).Methods("GET")
// Define Wakeup Api functions with a Computer Name
router.HandleFunc("/api/wakeup/computer/{computerName}", restWakeUpWithComputerName).Methods("GET")
router.HandleFunc("/api/wakeup/computer/{computerName}/", restWakeUpWithComputerName).Methods("GET")
// Setup Webserver
httpListen := fmt.Sprint(":", httpPort)
log.Printf("Startup Webserver on \"%s\"", httpListen)
log.Fatal(http.ListenAndServe(httpListen, handlers.RecoveryHandler(handlers.PrintRecoveryStack(true))(router)))
}