[feat] 重新梳理依赖
This commit is contained in:
+18
-17
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"git.fsdpf.net/go/contracts"
|
||||
"git.fsdpf.net/go/req"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
@@ -40,8 +41,8 @@ var wsUpgrader = websocket.Upgrader{
|
||||
},
|
||||
}
|
||||
|
||||
func (this RawResponse) Get(path ...string) contracts.GlobalParams {
|
||||
return lo.Ternary(len(path) == 0, NewGlobalParam(string(this.raw), nil), NewGlobalParam(string(this.raw), nil).Get(strings.Join(path, ".")))
|
||||
func (this RawResponse) Get(path ...string) req.GlobalParams {
|
||||
return lo.Ternary(len(path) == 0, req.NewGlobalParam(string(this.raw), nil), req.NewGlobalParam(string(this.raw), nil).Get(strings.Join(path, ".")))
|
||||
}
|
||||
|
||||
func (this RawResponse) Send(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -54,8 +55,8 @@ func (this RawResponse) Send(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (this JsonResponse) Get(path ...string) contracts.GlobalParams {
|
||||
return lo.Ternary(len(path) == 0, NewGlobalParam(string(this.raw), nil), NewGlobalParam(string(this.raw), nil).Get(strings.Join(path, ".")))
|
||||
func (this JsonResponse) Get(path ...string) req.GlobalParams {
|
||||
return lo.Ternary(len(path) == 0, req.NewGlobalParam(string(this.raw), nil), req.NewGlobalParam(string(this.raw), nil).Get(strings.Join(path, ".")))
|
||||
}
|
||||
|
||||
func (this JsonResponse) Send(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -69,12 +70,12 @@ func (this JsonResponse) Send(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (this MsgResponse) Get(path ...string) contracts.GlobalParams {
|
||||
func (this MsgResponse) Get(path ...string) req.GlobalParams {
|
||||
if resp, err := json.Marshal(map[string]any{
|
||||
"code": this.code,
|
||||
"msg": this.msg,
|
||||
}); err == nil {
|
||||
return lo.Ternary(len(path) == 0, NewGlobalParam(string(resp), nil), NewGlobalParam(string(resp), nil).Get(strings.Join(path, ".")))
|
||||
return lo.Ternary(len(path) == 0, req.NewGlobalParam(string(resp), nil), req.NewGlobalParam(string(resp), nil).Get(strings.Join(path, ".")))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -88,13 +89,13 @@ func (this MsgResponse) Send(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (this ErrResponse) Get(path ...string) contracts.GlobalParams {
|
||||
func (this ErrResponse) Get(path ...string) req.GlobalParams {
|
||||
if resp, err := json.Marshal(map[string]any{
|
||||
"code": this.code,
|
||||
"msg": this.msg,
|
||||
"error": string(this.stack),
|
||||
}); err == nil {
|
||||
return lo.Ternary(len(path) == 0, NewGlobalParam(string(resp), nil), NewGlobalParam(string(resp), nil).Get(strings.Join(path, ".")))
|
||||
return lo.Ternary(len(path) == 0, req.NewGlobalParam(string(resp), nil), req.NewGlobalParam(string(resp), nil).Get(strings.Join(path, ".")))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -108,12 +109,12 @@ func (this ErrResponse) Send(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (this FileResponse) Get(path ...string) contracts.GlobalParams {
|
||||
func (this FileResponse) Get(path ...string) req.GlobalParams {
|
||||
if resp, err := json.Marshal(map[string]any{
|
||||
"name": this.name,
|
||||
"disposition": this.disposition,
|
||||
}); err == nil {
|
||||
return lo.Ternary(len(path) == 0, NewGlobalParam(string(resp), nil), NewGlobalParam(string(resp), nil).Get(strings.Join(path, ".")))
|
||||
return lo.Ternary(len(path) == 0, req.NewGlobalParam(string(resp), nil), req.NewGlobalParam(string(resp), nil).Get(strings.Join(path, ".")))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -130,31 +131,31 @@ func (this FileResponse) Send(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func NewRawResponse(b []byte) contracts.HttpResponse {
|
||||
func NewRawResponse(b []byte) req.HttpResponse {
|
||||
return &RawResponse{raw: b}
|
||||
}
|
||||
|
||||
func NewJsonResponse(b []byte) contracts.HttpResponse {
|
||||
func NewJsonResponse(b []byte) req.HttpResponse {
|
||||
return &JsonResponse{raw: b}
|
||||
}
|
||||
|
||||
func NewFileResponse(name string, disposition string) contracts.HttpResponse {
|
||||
func NewFileResponse(name string, disposition string) req.HttpResponse {
|
||||
return &FileResponse{name: name, disposition: disposition}
|
||||
}
|
||||
|
||||
func NewMsgResponse(msg string, code int) contracts.HttpResponse {
|
||||
func NewMsgResponse(msg string, code int) req.HttpResponse {
|
||||
return &MsgResponse{msg: msg, code: code}
|
||||
}
|
||||
|
||||
func NewErrResponse(err *contracts.Err) contracts.HttpResponse {
|
||||
func NewErrResponse(err *contracts.Err) req.HttpResponse {
|
||||
return NewJsonResponse([]byte(fmt.Sprintf(`{"code": %d, "msg": %q}`, err.Code, err.Error())))
|
||||
}
|
||||
|
||||
func HttpResponse(data any) contracts.HttpResponse {
|
||||
func HttpResponse(data any) req.HttpResponse {
|
||||
var err error
|
||||
// fmt.Printf("%#v \n", data)
|
||||
switch v := data.(type) {
|
||||
case contracts.HttpResponse:
|
||||
case req.HttpResponse:
|
||||
return v
|
||||
case contracts.Errno:
|
||||
return NewMsgResponse(v.Error(), v.Code)
|
||||
|
||||
Reference in New Issue
Block a user