github.com/ckxng/wakeup@v0.0.0-20190105202853-90356a5f5a15/src/main.go (about)

     1  // Copyright (c) 2015 Cameron King. All rights reserved.
     2  // License: BSD 2-clause.
     3  // Website: https://github.com/ckxng/wakeup
     4  
     5  package main
     6  
     7  import (
     8      "os"
     9      "log"
    10  	"wakeup/window"
    11  	"wakeup/config"
    12  	"wakeup/server"
    13  )
    14  
    15  var logger *log.Logger = log.New(os.Stdout, "[main] ", log.Lshortfile)
    16  var main_is_running = false
    17  
    18  func main() {
    19  	cWindow := make(chan int)
    20  	cServer := make(chan int)
    21  	
    22  	logger.Println("config.NewConfig")
    23  	cfg := config.NewConfig()
    24  	cfg.Title = "Wakeup"
    25  	
    26  	// cef2go calls itself several times to start subprocesses of the 
    27  	// executable.  Since we are running a server, only the first executable
    28  	// can bind the port.
    29  	if len(os.Args) > 1 {
    30  		logger.Println("os.Args are present, not running server")
    31  		cfg.EnableServer = false
    32  	}
    33  	
    34  	if(cfg.EnableServer) {
    35  		logger.Println("go server.Go")
    36  		go server.Go(cfg, cServer)
    37  	}
    38  	
    39  	if(cfg.EnableWindow) {
    40  		logger.Println("go window.Go")
    41  		go window.Go(cfg, cWindow)
    42  	}
    43  	
    44  	for {
    45  		select {
    46  			case iExitWindow := <- cWindow:
    47  				logger.Printf("Window Exit: %d\n", iExitWindow)
    48  				os.Exit(iExitWindow)
    49  			case iExitServer := <- cServer:
    50  				logger.Printf("Server Exit: %d\n", iExitServer)
    51  				os.Exit(iExitServer)
    52  		}
    53  	}
    54  }