forked from p93542168/wheat-cache
feat(storage): add storage server
This commit is contained in:
parent
8c114bcb9a
commit
30e182d018
|
@ -3,8 +3,16 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gitee.com/timedb/wheatCache/storage/proto"
|
||||||
|
"gitee.com/timedb/wheatCache/storage/server"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/reflection"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
@ -14,16 +22,40 @@ var cfgFile string
|
||||||
// rootCmd represents the base command when called without any subcommands
|
// rootCmd represents the base command when called without any subcommands
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "storage",
|
Use: "storage",
|
||||||
Short: "A brief description of your application",
|
Short: "storage",
|
||||||
Long: `A longer description that spans multiple lines and likely contains
|
Long: `start storage server`,
|
||||||
examples and usage of using your application. For example:
|
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.
|
c := make(chan os.Signal)
|
||||||
This application is a tool to generate the needed files
|
signal.Notify(c, syscall.SIGHUP, syscall.SIGINT)
|
||||||
to quickly create a Cobra application.`,
|
go func() {
|
||||||
// Uncomment the following line if your bare application
|
select {
|
||||||
// has an action associated with it:
|
case <-c:
|
||||||
// Run: func(cmd *cobra.Command, args []string) { },
|
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.
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue