| 1234567891011121314151617181920212223242526272829303132333435 |
- package main
- import (
- "context"
- "fmt"
- "igit.com/robert/xpc"
- )
- // 定义接口
- type HelloService interface {
- SayHello(ctx context.Context, name string) (string, error)
- }
- // 实现接口
- type helloServiceImpl struct {
- xpc.Implements[HelloService]
- }
- func (h *helloServiceImpl) SayHello(ctx context.Context, name string) (string, error) {
- return "Hello, " + name, nil
- }
- func main() {
- if err := xpc.Run(context.Background(), func(ctx context.Context, hello HelloService) error {
- res, err := hello.SayHello(ctx, "World")
- if err != nil {
- return err
- }
- fmt.Println(res)
- return nil
- }); err != nil {
- panic(err)
- }
- }
|