github.com/godevsig/adaptiveservice@v0.9.23/examples/echo/echo.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  
     6  	as "github.com/godevsig/adaptiveservice"
     7  	"github.com/godevsig/adaptiveservice/examples/echo/client"
     8  	"github.com/godevsig/adaptiveservice/examples/echo/server"
     9  )
    10  
    11  func main() {
    12  	var debug bool
    13  	var serverMode bool
    14  	var clientMode bool
    15  	flag.BoolVar(&debug, "d", false, "enable debug")
    16  	flag.BoolVar(&serverMode, "s", false, "server mode")
    17  	flag.BoolVar(&clientMode, "c", false, "client mode")
    18  	clientCmd := flag.String("cmd", "", "client cmd in client mode")
    19  	flag.Parse()
    20  
    21  	var opts []as.Option
    22  	if debug {
    23  		opts = append(opts, as.WithLogger(as.LoggerAll{}))
    24  	}
    25  
    26  	if serverMode {
    27  		server.Run(opts)
    28  	} else if clientMode {
    29  		client.Run(*clientCmd, opts)
    30  	} else {
    31  		//opts = append(opts, as.WithScope(as.ScopeProcess))
    32  		go client.Run(*clientCmd, opts)
    33  		done := make(chan struct{})
    34  		go func() {
    35  			server.Run(opts)
    36  			close(done)
    37  		}()
    38  		<-done
    39  	}
    40  }