diff --git a/app.go b/app.go index b3ea930..9619bbd 100644 --- a/app.go +++ b/app.go @@ -3,7 +3,7 @@ package kit import ( "context" "errors" - "fmt" + "git.diulo.com/mogfee/kit/core/logx" _ "git.diulo.com/mogfee/kit/encoding/form" _ "git.diulo.com/mogfee/kit/encoding/json" _ "git.diulo.com/mogfee/kit/encoding/xml" @@ -47,7 +47,6 @@ func New(opts ...Option) *App { for _, opt := range opts { opt(&o) } - fmt.Println(o.id) if o.logger != nil { logx.SetLogger(o.logger) } diff --git a/options.go b/options.go index 548e0b3..812459a 100644 --- a/options.go +++ b/options.go @@ -2,6 +2,7 @@ package kit import ( "context" + "git.diulo.com/mogfee/kit/core/logx" "git.diulo.com/mogfee/kit/registry" "git.diulo.com/mogfee/kit/transport" "net/url" diff --git a/transport/http/client.go b/transport/http/client.go index 24760b9..bdc7c45 100644 --- a/transport/http/client.go +++ b/transport/http/client.go @@ -6,6 +6,7 @@ import ( "crypto/tls" "fmt" "git.diulo.com/mogfee/kit/encoding" + "git.diulo.com/mogfee/kit/errors" "git.diulo.com/mogfee/kit/internal/host" "git.diulo.com/mogfee/kit/internal/httputil" "git.diulo.com/mogfee/kit/middleware" @@ -259,7 +260,7 @@ func (client *Client) do(req *http.Request) (*http.Response, error) { node selector.Node ) if node, done, err = client.selector.Select(req.Context(), selector.WithNodeFilter(client.opts.nodeFilters...)); err != nil { - return nil, errorx.ServiceUnavailable("NODE_NOT_FOUND", err.Error()) + return nil, errors.ServiceUnavailable("NODE_NOT_FOUND", err.Error()) } if client.insecure { req.URL.Scheme = "http" @@ -306,13 +307,13 @@ func DefaultErrorDecoder(ctx context.Context, res *http.Response) error { data, err := io.ReadAll(res.Body) defer res.Body.Close() if err == nil { - e := new(errorx.Error) + e := new(errors.Error) if err = CodecForResponse(res).Unmarshal(data, e); err == nil { e.Code = int32(res.StatusCode) return e } } - return errorx.Newf(res.StatusCode, errorx.UnknownReason, "").WithCause(err) + return errors.Newf(res.StatusCode, errors.UnknownReason, "").WithCause(err) } func CodecForResponse(r *http.Response) encoding.Codec { codec := encoding.GetCodec(httputil.ContentSubtype(r.Request.Header.Get("Content-Type"))) diff --git a/transport/http/codec.go b/transport/http/codec.go index a67d893..3ad3ade 100644 --- a/transport/http/codec.go +++ b/transport/http/codec.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "git.diulo.com/mogfee/kit/encoding" + "git.diulo.com/mogfee/kit/errors" "git.diulo.com/mogfee/kit/internal/httputil" "git.diulo.com/mogfee/kit/transport/http/binding" "github.com/gorilla/mux" @@ -38,18 +39,18 @@ func DefaultRequestQuery(r *http.Request, v any) error { func DefaultRequestDecoder(r *http.Request, v any) error { codec, ok := CodeForRequest(r, "Content-Type") if !ok { - return errorx.BadRequest("CODEC", fmt.Sprintf("unregister Content-Type: %s", codec)) + return errors.BadRequest("CODEC", fmt.Sprintf("unregister Content-Type: %s", codec)) } data, err := io.ReadAll(r.Body) if err != nil { - return errorx.BadRequest("CODEC", err.Error()) + return errors.BadRequest("CODEC", err.Error()) } r.Body = io.NopCloser(bytes.NewBuffer(data)) if len(data) == 0 { return nil } if err = codec.Unmarshal(data, v); err != nil { - return errorx.BadRequest("CODEC", err.Error()) + return errors.BadRequest("CODEC", err.Error()) } return nil } @@ -72,7 +73,7 @@ func DefaultResponseEncoder(w http.ResponseWriter, r *http.Request, v any) error return err } func DefaultErrorEncoder(w http.ResponseWriter, r *http.Request, err error) { - se := errorx.FromError(err) + se := errors.FromError(err) codec, _ := CodeForRequest(r, "Accept") body, err := codec.Marshal(se) if err != nil { diff --git a/transport/http/server.go b/transport/http/server.go index 6e6bce8..cf5a39a 100644 --- a/transport/http/server.go +++ b/transport/http/server.go @@ -4,6 +4,7 @@ import ( "context" "crypto/tls" "errors" + "git.diulo.com/mogfee/kit/core/logx" "git.diulo.com/mogfee/kit/internal/endpoint" "git.diulo.com/mogfee/kit/internal/host" "git.diulo.com/mogfee/kit/internal/matcher"