Created
December 26, 2016 02:42
-
-
Save greenboxal/539f73c5648efe7a0620c51b3d96a038 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package accountserver | |
import ( | |
"os" | |
"os/signal" | |
"syscall" | |
"github.com/spf13/cobra" | |
"github.com/zeusproject/zeus-server/account" | |
"github.com/zeusproject/zeus-server/account/server" | |
"github.com/zeusproject/zeus-server/utils" | |
) | |
func NewAccountCommand() *cobra.Command { | |
return &cobra.Command{ | |
Use: "accountserver", | |
Short: "Account Server", | |
RunE: func(cmd *cobra.Command, args []string) error { | |
return runAccount() | |
}, | |
} | |
} | |
func runAccount() error { | |
var accountConfig account.Config | |
var serverConfig server.Config | |
accountViper, err := utils.LoadViper("account") | |
if err != nil { | |
return err | |
} | |
if err := accountViper.Unmarshal(&accountConfig); err != nil { | |
return err | |
} | |
if err := accountViper.Sub("server").Unmarshal(&serverConfig); err != nil { | |
return err | |
} | |
account := account.NewAccountServer(&accountConfig) | |
server, err := server.CreateServer(account, &serverConfig) | |
if err != nil { | |
return err | |
} | |
// Trap signals | |
sig := make(chan os.Signal) | |
signal.Notify(sig, syscall.SIGINT) | |
// Wait for quit signal | |
for s := range sig { | |
if s == syscall.SIGINT { | |
server.Close() | |
os.Exit(0) | |
} | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment