package main import ( "encoding/json" "fmt" "io/ioutil" "log" "os" "os/signal" "syscall" "aytechnology.us/gominecraft/mod/aroz" "aytechnology.us/gominecraft/mod/config" "aytechnology.us/gominecraft/mod/server" ) //MCServer should not be exported var MCServer *server.Handler //Config should not be exported var Config *config.Handler var serverConfig startupConfig type startupConfig struct { Java string `json:"java"` Min string `json:"min"` Max string `json:"max"` Jar string `json:"jar"` Folder string `json:"folder"` Arg string `json:"arg"` } var ( handler *aroz.ArozHandler ) //Kill signal handler. Do something before the system the core terminate. func SetupCloseHandler() { c := make(chan os.Signal, 2) signal.Notify(c, os.Interrupt, syscall.SIGTERM) go func() { <-c log.Println("\r- Shutting down demo module.") //Do other things like close database or opened files os.Exit(0) }() } func main() { //AROZOS //If you have other flags, please add them here //Start the aoModule pipeline (which will parse the flags as well). Pass in the module launch information handler = aroz.HandleFlagParse(aroz.ServiceInfo{ Name: "Minecraft Server", Desc: "GO Minecraft", Group: "Development", IconPath: "gominecraft/icon.png", Version: "0.0.1", //You can define any path before the actualy html file. This directory (in this case demo/ ) will be the reverse proxy endpoint for this module StartDir: "gominecraft/index.html", SupportFW: true, LaunchFWDir: "gominecraft/index.html", SupportEmb: true, LaunchEmb: "gominecraft/404.html", InitFWSize: []int{720, 480}, InitEmbSize: []int{720, 480}, SupportedExt: []string{}, }) //init the startup configuration jsonFile, err := os.Open("./startup.json") if err != nil { fmt.Println(err) } byte, _ := ioutil.ReadAll(jsonFile) json.Unmarshal(byte, &serverConfig) MCServer = server.NewHandler(serverConfig.Java, serverConfig.Jar, serverConfig.Min, serverConfig.Max, serverConfig.Arg) Config = config.NewHandler(serverConfig.Folder) Config.AutoUpdate() //enable auto update CrashRestart() /* go func() { i := 0 for { end := MCServer.LenLog() log := MCServer.ReadRangeLog(i, end) for _, line := range log { fmt.Println(line.Log) } i = end } }() */ //To receive kill signal from the System core, you can setup a close handler to catch the kill signal //This is not nessary if you have no opened files / database running SetupCloseHandler() //Any log println will be shown in the core system via STDOUT redirection. But not STDIN. log.Println("gominecraft module started. Listening on " + handler.Port) webServer("./webroot/", serverConfig.Folder, handler.Port) }