feat(storage): add storage server

This commit is contained in:
bandl 2021-08-31 23:31:31 +08:00
parent 8c114bcb9a
commit 30e182d018
2 changed files with 61 additions and 9 deletions

View File

@ -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.

20
storage/server/server.go Normal file
View File

@ -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
}