Skip to content

Commit 0a3fc04

Browse files
author
NullpointerW
committed
change
1 parent 79d6ac3 commit 0a3fc04

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

httphandler/commn.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ const (
1616
ServerError statusCode = 500
1717
)
1818

19-
func respOk(w http.ResponseWriter, t any) {
19+
func RespOk(w http.ResponseWriter, t any) {
2020
resp(OK, w, t)
2121
}
22-
func respSrvErr(w http.ResponseWriter, t any) {
22+
func RespSrvErr(w http.ResponseWriter, t any) {
2323
resp(ServerError, w, t)
2424
}
25-
func respBadReq(w http.ResponseWriter, t any) {
25+
func RespBadReq(w http.ResponseWriter, t any) {
2626
resp(BadRequest, w, t)
2727
}
28-
func respMethodNA(w http.ResponseWriter, t any) {
28+
func RespMethodNA(w http.ResponseWriter, t any) {
2929
resp(MethodNotAllowed, w, t)
3030
}
31-
func respUnAuth(w http.ResponseWriter, t any) {
31+
func RespUnAuth(w http.ResponseWriter, t any) {
3232
resp(Unauthorized, w, t)
3333
}
34-
func respForbid(w http.ResponseWriter, t any) {
34+
func RespForbid(w http.ResponseWriter, t any) {
3535
resp(Forbidden, w, t)
3636
}
3737

httphandler/handler.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,47 +25,47 @@ func (h Handler) Push(w http.ResponseWriter, req *http.Request) {
2525
uid, _ := strconv.ParseUint(idStr, 10, 64)
2626
err := h.Adapter.Push(uid, utils.Bcs(_msg))
2727
if err != nil {
28-
respSrvErr(w, err)
28+
RespSrvErr(w, err)
2929
return
3030
}
31-
respOk(w, "ok")
31+
RespOk(w, "ok")
3232
}
3333

3434
func (h Handler) Broadcast(w http.ResponseWriter, req *http.Request) {
3535
_msg, _ := ioutil.ReadAll(req.Body)
3636
//t := time.Now()
3737
err := h.Adapter.Broadcast(utils.Bcs(_msg))
3838
if err != nil {
39-
respSrvErr(w, err)
39+
RespSrvErr(w, err)
4040
return
4141
}
42-
respOk(w, "ok")
42+
RespOk(w, "ok")
4343
}
4444

4545
func (h Handler) MultiPush(w http.ResponseWriter, req *http.Request) {
4646
if req.Method != "POST" {
47-
respMethodNA(w, "non-post method not allowed")
47+
RespMethodNA(w, "non-post method not allowed")
4848
return
4949
}
5050
jsBody, _ := ioutil.ReadAll(req.Body)
5151
cts := &golwpush.Contents{}
5252
err := json.Unmarshal(jsBody, cts)
5353
if err != nil {
54-
respBadReq(w, "json unmarshal error")
54+
RespBadReq(w, "json unmarshal error")
5555
return
5656
}
5757
cts.Res = make(chan uint64, 1)
5858
err, ok := h.Adapter.MultiPush(cts)
5959
if err != nil {
60-
respSrvErr(w, err)
60+
RespSrvErr(w, err)
6161
return
6262
}
63-
respOk(w, ok)
63+
RespOk(w, ok)
6464
}
6565

6666
func (h Handler) Count(w http.ResponseWriter, req *http.Request) {
6767
c := h.Adapter.Count()
68-
respOk(w, c)
68+
RespOk(w, c)
6969
}
7070

7171
func (h Handler) Info(w http.ResponseWriter, req *http.Request) {
@@ -74,14 +74,14 @@ func (h Handler) Info(w http.ResponseWriter, req *http.Request) {
7474
res := make(chan any, 1)
7575
i, err := h.Adapter.Info(golwpush.BizReq{Res: res, Uid: uid, Typ: golwpush.Info})
7676
if err != nil {
77-
respSrvErr(w, err)
77+
RespSrvErr(w, err)
7878
return
7979
}
8080
if i == nil {
81-
respOk(w, fmt.Sprintf("uid :%d offline [%s]", uid, time.Now().Format(utils.TimeParseLayout)))
81+
RespOk(w, fmt.Sprintf("uid :%d offline [%s]", uid, time.Now().Format(utils.TimeParseLayout)))
8282
return
8383
}
8484
w.Header().Add("Content-Type", "application/json")
8585
j, _ := json.Marshal(i)
86-
respOk(w, utils.Bcs(j))
86+
RespOk(w, utils.Bcs(j))
8787
}

0 commit comments

Comments
 (0)