Files
gotsrpc/tests/context/server/handler.go
Kevin Franklin Kim 8f67919d62 fix: gorpc nil context
2026-03-23 07:17:42 +01:00

47 lines
858 B
Go

package server
import (
"context"
"errors"
"fmt"
pkgerrors "github.com/pkg/errors"
)
var (
ErrGo = pkgerrors.New("go")
ErrPkg = pkgerrors.New("pkg error")
)
type Handler struct{}
func (h *Handler) Hello(ctx context.Context, args string) string {
if ctx.Err() != nil {
return "context error"
}
fmt.Println(args)
return "Hello " + args
}
func (h *Handler) Error(ctx context.Context, args string) error {
return ErrGo
}
func (h *Handler) JoinedError(ctx context.Context, args string) error {
return errors.Join(ErrGo, ErrPkg)
}
func (h *Handler) PkgError(ctx context.Context, args string) error {
return ErrPkg
}
func (h *Handler) WrappedError(ctx context.Context, args string) error {
return pkgerrors.Wrap(ErrPkg, "wrapped error")
}
func (h *Handler) CustomError(ctx context.Context, msg string) error {
return NewMyError(msg)
}