2021-08-15 15:19:22 +08:00
|
|
|
// Package cmd /*
|
2021-08-14 23:21:40 +08:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-08-31 23:31:31 +08:00
|
|
|
"log"
|
|
|
|
"net"
|
2021-08-15 15:19:22 +08:00
|
|
|
"os"
|
2021-08-31 23:31:31 +08:00
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2021-08-14 23:21:40 +08:00
|
|
|
|
2021-09-05 15:00:39 +08:00
|
|
|
"gitee.com/timedb/wheatCache/storage/proto"
|
|
|
|
"gitee.com/timedb/wheatCache/storage/server"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/reflection"
|
2021-08-14 23:21:40 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// rootCmd represents the base command when called without any subcommands
|
|
|
|
var rootCmd = &cobra.Command{
|
|
|
|
Use: "storage",
|
2021-08-31 23:31:31 +08:00
|
|
|
Short: "storage",
|
|
|
|
Long: `start storage server`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
storageServer := server.NewServer()
|
|
|
|
// 先写死, 等配置文件
|
|
|
|
listen, err := net.Listen("tcp", ":5201")
|
|
|
|
if err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
s := grpc.NewServer()
|
|
|
|
proto.RegisterCommServerServer(s, storageServer)
|
|
|
|
reflection.Register(s)
|
|
|
|
|
|
|
|
c := make(chan os.Signal)
|
|
|
|
signal.Notify(c, syscall.SIGHUP, syscall.SIGINT)
|
|
|
|
go func() {
|
|
|
|
select {
|
|
|
|
case <-c:
|
|
|
|
s.Stop()
|
|
|
|
|
|
|
|
msg := `
|
|
|
|
|-------Wheat tools---------|
|
|
|
|
| see you next time |
|
|
|
|
|thank you for your efforts |
|
|
|
|
|---------------------------|
|
|
|
|
`
|
|
|
|
fmt.Println(msg)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if err := s.Serve(listen); err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
},
|
2021-08-14 23:21:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
|
|
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
|
|
|
func Execute() {
|
|
|
|
cobra.CheckErr(rootCmd.Execute())
|
|
|
|
}
|