refactor(go)!: 分离练习区与独立项目区

- 将现有练习及 module 文件迁移至 go/practice,保持代码和依赖不变
- 新增 go/projects 项目区说明,更新目录约定与开发命令

BREAKING CHANGE: Go 练习命令需改在 go/practice 目录下执行
This commit is contained in:
2026-10-15 22:26:57 +08:00
parent 86f6eb39b2
commit d375463de5
21 changed files with 91 additions and 33 deletions
+34
View File
@@ -0,0 +1,34 @@
package error
import (
"errors"
"fmt"
"testing"
)
type MatchError struct {
code int
err error
}
func (e *MatchError) Error() string {
return fmt.Sprintf("code: %d, error: %v", e.code, e.err)
}
func GetMatchError() error {
return &MatchError{code: 1, err: errors.New("123")}
}
func GetError() error {
return errors.New("123")
}
func TestError(t *testing.T) {
if err, ok := errors.AsType[*MatchError](GetMatchError()); ok {
t.Log(err)
} else {
t.Errorf("expected MatchError, got %T", GetMatchError())
}
if err, ok := errors.AsType[*MatchError](GetError()); ok {
t.Log(err)
} else {
t.Errorf("expected MatchError, got %T", GetError())
}
}