Skip to content

Instantly share code, notes, and snippets.

@greenboxal
Created December 26, 2016 02:42
Show Gist options
  • Save greenboxal/539f73c5648efe7a0620c51b3d96a038 to your computer and use it in GitHub Desktop.
Save greenboxal/539f73c5648efe7a0620c51b3d96a038 to your computer and use it in GitHub Desktop.
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