Skip to content

Commit

Permalink
refactor(项目): 去掉goexl/exc依赖,改为goexl/exception依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
storezhang committed Nov 21, 2023
1 parent 239dc01 commit 6ae986a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/pangum/pangu
go 1.21

require (
github.com/goexl/exc v0.0.5
github.com/goexl/gfx v0.1.7
github.com/goexl/gox v0.3.8
github.com/pelletier/go-toml v1.9.5
Expand All @@ -17,9 +16,10 @@ require (
require (
github.com/drone/envsubst v1.0.3
github.com/goexl/env v0.0.2
github.com/goexl/exception v0.0.1
github.com/goexl/log v0.0.5
github.com/goexl/mengpo v0.2.4
github.com/goexl/xiren v0.0.5
github.com/goexl/mengpo v0.2.5
github.com/goexl/xiren v0.0.6
github.com/olekukonko/tablewriter v0.0.5
github.com/zs5460/art v0.3.0
)
Expand Down
8 changes: 4 additions & 4 deletions internal/container/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package container
import (
"reflect"

"github.com/goexl/exc"
"github.com/goexl/exception"
"github.com/goexl/gox/field"
"github.com/pangum/pangu/internal/message"
"github.com/pangum/pangu/internal/internal/message"
"github.com/pangum/pangu/internal/param"
"github.com/pangum/pangu/internal/runtime"
"github.com/storezhang/dig"
Expand Down Expand Up @@ -102,10 +102,10 @@ func (d *Dependency) verify(constructor any) (err error) {

typ := reflect.TypeOf(constructor)
if reflect.Func != typ.Kind() { // 构造方法必须是方法,不能是其它类型
err = exc.NewField(message.ConstructorMustFunc, field.New("constructor", typ.String()))
err = exception.New().Message(message.ConstructorMustFunc).Field(field.New("constructor", typ.String())).Build()
} else if 0 == typ.NumOut() { // 构造方法必须有返回值
name := runtime.FuncForPC(reflect.ValueOf(constructor).Pointer()).Name()
err = exc.NewField(message.ConstructorMustReturn, field.New("constructor", name))
err = exception.New().Message(message.ConstructorMustReturn).Field(field.New("constructor", name)).Build()
}

return
Expand Down
15 changes: 8 additions & 7 deletions internal/core/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sync"
"syscall"

"github.com/goexl/exc"
"github.com/goexl/exception"
"github.com/goexl/gox"
"github.com/goexl/gox/field"
"github.com/goexl/log"
Expand All @@ -21,7 +21,7 @@ import (
"github.com/pangum/pangu/internal/internal/builder"
"github.com/pangum/pangu/internal/internal/config"
"github.com/pangum/pangu/internal/internal/get"
"github.com/pangum/pangu/internal/message"
"github.com/pangum/pangu/internal/internal/message"
"github.com/pangum/pangu/internal/param"
"github.com/pangum/pangu/internal/runtime"
"github.com/storezhang/dig"
Expand Down Expand Up @@ -117,7 +117,8 @@ func (a *Application) Add(components ...any) (err error) {
case app.Argument:
err = a.addArg(converted)
default:
err = exc.NewField("不支持组件类型", field.New("type", reflect.TypeOf(component).String()))
typ := field.New("type", reflect.TypeOf(component).String())
err = exception.New().Message(message.ComponentNotSupport).Field(typ).Build()
}

if nil != err {
Expand Down Expand Up @@ -341,13 +342,13 @@ func (a *Application) verify(bootstrap runtime.Constructor) (err error) {

typ := reflect.TypeOf(bootstrap)
if reflect.Func != typ.Kind() { // 构造方法必须是方法不能是其它类型
err = exc.NewField(message.ConstructorMustFunc, field.New("bootstrap", typ.String()))
err = exception.New().Message(message.ConstructorMustFunc).Field(field.New("bootstrap", typ.String())).Build()
} else if 0 == typ.NumIn() { // 构造方法必须有依赖项
constructorName := runtime.FuncForPC(reflect.ValueOf(bootstrap).Pointer()).Name()
err = exc.NewField(message.BootstrapMustHasDependencies, field.New("bootstrap", constructorName))
name := runtime.FuncForPC(reflect.ValueOf(bootstrap).Pointer()).Name()
err = exception.New().Message(message.BootstrapMustHasDependencies).Field(field.New("bootstrap", name)).Build()
} else if 1 != typ.NumOut() || reflect.TypeOf((*Bootstrap)(nil)).Elem() != typ.Out(constant.IndexFirst) {
// 只能返回一个类型为Bootstrap返回值
err = exc.NewMessage(message.BootstrapMustReturnBootstrap)
err = exception.New().Message(message.BootstrapMustReturnBootstrap).Build()
}

return
Expand Down
5 changes: 3 additions & 2 deletions internal/internal/loader/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"strings"

"github.com/drone/envsubst"
"github.com/goexl/exc"
"github.com/goexl/exception"
"github.com/goexl/gfx"
"github.com/goexl/gox/field"
"github.com/pangum/pangu/internal/callback/getter"
"github.com/pangum/pangu/internal/config"
"github.com/pangum/pangu/internal/constant"
"github.com/pangum/pangu/internal/internal/message"
"github.com/pangum/pangu/internal/runtime"
"github.com/pelletier/go-toml"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -49,7 +50,7 @@ func (c *Config) Load(path string, config runtime.Pointer) (err error) {

func (c *Config) read(path string) (err error) {
if _, exist := gfx.Exists(path); !exist && !c.nullable {
err = exc.NewField("配置文件不存在", field.New("path", path))
err = exception.New().Message(message.ConfigFileNotfound).Field(field.New("path", path)).Build()
} else if exist {
c.data, err = os.ReadFile(path)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/internal/message/application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package message

const (
ComponentNotSupport = "不支持组件类型"
ConfigFileNotfound = "配置文件不存在"
)
File renamed without changes.
File renamed without changes.

0 comments on commit 6ae986a

Please sign in to comment.