diff --git a/storage/cmd/root.go b/storage/cmd/root.go index e1bac4e..d26625a 100644 --- a/storage/cmd/root.go +++ b/storage/cmd/root.go @@ -3,8 +3,16 @@ package cmd import ( "fmt" + "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" + "log" + "net" "os" + "os/signal" + "syscall" "github.com/spf13/viper" ) @@ -14,16 +22,40 @@ var cfgFile string // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "storage", - Short: "A brief description of your application", - Long: `A longer description that spans multiple lines and likely contains -examples and usage of using your application. For example: + 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) -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, - // Uncomment the following line if your bare application - // has an action associated with it: - // Run: func(cmd *cobra.Command, args []string) { }, + 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) + } + }, } // Execute adds all child commands to the root command and sets flags appropriately. diff --git a/storage/server/server.go b/storage/server/server.go new file mode 100644 index 0000000..41044c2 --- /dev/null +++ b/storage/server/server.go @@ -0,0 +1,20 @@ +package server + +import ( + context "context" + "gitee.com/timedb/wheatCache/storage/proto" +) + +type server struct{} + +func NewServer() proto.CommServerServer { + ser := &server{} + return ser +} + +func (s *server) Commend( + ctx context.Context, + request *proto.CommendRequest, +) (*proto.CommendResponse, error) { + return nil, nil +}