main.go 602 B

123456789101112131415161718192021222324252627282930
  1. package main
  2. import (
  3. "../service"
  4. "context"
  5. "github.com/smallnest/rpcx/server"
  6. "log"
  7. "strings"
  8. )
  9. const ADDRESS string = "localhost:10001"
  10. type FormatData struct{}
  11. func (fd *FormatData) DoFormat(ctx context.Context, args *service.Args, reply *service.Replay) error {
  12. str := args.Text
  13. reply.Text = strings.ToUpper(str)
  14. return nil
  15. }
  16. func main() {
  17. s := server.NewServer()
  18. err := s.RegisterName("Format", new(FormatData), "")
  19. if err != nil {
  20. log.Fatalln("faile register service: Format")
  21. }
  22. if err = s.Serve("tcp", ADDRESS); err != nil {
  23. log.Fatalln("faile serve at: " + ADDRESS)
  24. }
  25. }