Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
zrcoder committed Dec 19, 2024
1 parent 6e602a4 commit 76771bd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions comp/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ func (a action) TransformMultiple(inputs any, successMsg string, transfor func(a
}

func (a action) transform(input any, dstKey, successMsg string, transfor func(any) (any, error)) action {
route := fmt.Sprintf("/__amisgo_api_%d", getInnerApiID())
route := getRoute()
servermux.Mux().HandleFunc(route, func(w http.ResponseWriter, r *http.Request) {
inputData, err := io.ReadAll(r.Body)
if err != nil {
resp := ErrorResponse(err.Error())
w.Write(resp.Json())
respError(w, err)
return
}
defer r.Body.Close()
Expand All @@ -75,8 +74,7 @@ func (a action) transform(input any, dstKey, successMsg string, transfor func(an
input := m["input"]
output, err := transfor(input)
if err != nil {
resp := ErrorResponse(err.Error())
w.Write(resp.Json())
respError(w, err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion comp/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Response struct {
}

func ErrorResponse(msg string) *Response {
return &Response{Status: -1, Msg: msg}
return &Response{Status: 1, Msg: msg}
}

func SuccessResponse(msg string, data Data) *Response {
Expand Down
2 changes: 1 addition & 1 deletion comp/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ func serveUpload(maxMemory int64, action func([]byte) (path string, err error))
}

func respError(w http.ResponseWriter, err error) {
resp := Response{Status: 1, Msg: err.Error()}
resp := ErrorResponse(err.Error())
w.Write(resp.Json())
}

0 comments on commit 76771bd

Please sign in to comment.