main.go 634 B

1234567891011121314151617181920212223242526272829303132333435
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "igit.com/robert/xpc"
  6. )
  7. // 定义接口
  8. type HelloService interface {
  9. SayHello(ctx context.Context, name string) (string, error)
  10. }
  11. // 实现接口
  12. type helloServiceImpl struct {
  13. xpc.Implements[HelloService]
  14. }
  15. func (h *helloServiceImpl) SayHello(ctx context.Context, name string) (string, error) {
  16. return "Hello, " + name, nil
  17. }
  18. func main() {
  19. if err := xpc.Run(context.Background(), func(ctx context.Context, hello HelloService) error {
  20. res, err := hello.SayHello(ctx, "World")
  21. if err != nil {
  22. return err
  23. }
  24. fmt.Println(res)
  25. return nil
  26. }); err != nil {
  27. panic(err)
  28. }
  29. }