Files
gotsrpc/tests/errors/server/errors.go
Kevin Franklin Kim b64b408b3a feat: modernize
2026-03-22 21:59:12 +01:00

72 lines
1.2 KiB
Go

package server
import (
"github.com/pkg/errors"
)
type MyScalarError string
const (
MyScalarErrorOne MyScalarError = "scalar error one"
MyScalarErrorTwo MyScalarError = "scalar error two"
)
func NewMyScalarError(e MyScalarError) *MyScalarError {
return new(e)
}
func (e *MyScalarError) Error() string {
return string(*e)
}
type MyStructError struct {
Msg string
Map map[string]string
Slice []string
Struct struct {
A string
}
}
func NewMyStructError(msg string) MyStructError {
return MyStructError{
Msg: msg,
Map: map[string]string{"a": "b"},
Slice: []string{"a", "b"},
Struct: struct{ A string }{A: "b"},
}
}
func (e MyStructError) Error() string {
return e.Msg
}
type MyCustomError struct {
Msg string
Map map[string]string
Slice []string
Struct struct {
A string
}
}
func NewMyCustomError(msg string) *MyCustomError {
return &MyCustomError{
Msg: msg,
Map: map[string]string{"a": "b"},
Slice: []string{"a", "b"},
Struct: struct{ A string }{A: "b"},
}
}
func (e *MyCustomError) Error() string {
return e.Msg
}
var (
ErrTyped = errors.New("typed error")
ErrCustom = NewMyCustomError("typed custom error")
ErrScalarOne = new(MyScalarErrorOne)
ErrScalarTwo = new(MyScalarErrorTwo)
)