Skip to content

Commit

Permalink
refactor new file dispatch/http_api_client.go
Browse files Browse the repository at this point in the history
  • Loading branch information
q191201771 committed May 24, 2024
1 parent da5730f commit d0c084c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 38 deletions.
38 changes: 0 additions & 38 deletions app/demo/dispatch/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,44 +235,6 @@ func logHandler(w http.ResponseWriter, r *http.Request) {
nazalog.Infof("r=%+v, body=%s", r, b)
}

func kickSession(serverId, streamName, sessionId string) {
reqServer, exist := config.ServerId2Server[serverId]
if !exist {
nazalog.Errorf("[%s] req server id invalid.", serverId)
return
}

url := fmt.Sprintf("http://%s/api/ctrl/kick_session", reqServer.ApiAddr)
var b base.ApiCtrlKickSessionReq
b.StreamName = streamName
b.SessionId = sessionId

nazalog.Infof("[%s] kickSession. send to %s with %+v", serverId, reqServer.ApiAddr, b)
if _, err := nazahttp.PostJson(url, b, nil); err != nil {
nazalog.Errorf("[%s] post json error. err=%+v", serverId, err)
}
return
}

func addIpBlacklist(serverId, ip string, durationSec int) {
reqServer, exist := config.ServerId2Server[serverId]
if !exist {
nazalog.Errorf("[%s] req server id invalid.", serverId)
return
}

url := fmt.Sprintf("http://%s/api/ctrl/add_ip_blacklist", reqServer.ApiAddr)
var b base.ApiCtrlAddIpBlacklistReq
b.Ip = ip
b.DurationSec = durationSec

nazalog.Infof("[%s] addIpBlacklist. send to %s with %+v", serverId, reqServer.ApiAddr, b)
if _, err := nazahttp.PostJson(url, b, nil); err != nil {
nazalog.Errorf("[%s] post json error. err=%+v", serverId, err)
}
return
}

func parseFlag() string {
cf := flag.String("c", "", "specify conf file")
flag.Parse()
Expand Down
54 changes: 54 additions & 0 deletions app/demo/dispatch/http_api_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2024, Chef. All rights reserved.
// https://github.com/q191201771/lal
//
// Use of this source code is governed by a MIT-style license
// that can be found in the License file.
//
// Author: Chef (191201771@qq.com)

package main

import (
"fmt"
"github.com/q191201771/lal/pkg/base"
"github.com/q191201771/naza/pkg/nazahttp"
"github.com/q191201771/naza/pkg/nazalog"
)

func kickSession(serverId, streamName, sessionId string) {
reqServer, exist := config.ServerId2Server[serverId]
if !exist {
nazalog.Errorf("[%s] req server id invalid.", serverId)
return
}

url := fmt.Sprintf("http://%s/api/ctrl/kick_session", reqServer.ApiAddr)
var b base.ApiCtrlKickSessionReq
b.StreamName = streamName
b.SessionId = sessionId

nazalog.Infof("[%s] kickSession. send to %s with %+v", serverId, reqServer.ApiAddr, b)
if _, err := nazahttp.PostJson(url, b, nil); err != nil {
nazalog.Errorf("[%s] post json error. err=%+v", serverId, err)
}
return
}

func addIpBlacklist(serverId, ip string, durationSec int) {
reqServer, exist := config.ServerId2Server[serverId]
if !exist {
nazalog.Errorf("[%s] req server id invalid.", serverId)
return
}

url := fmt.Sprintf("http://%s/api/ctrl/add_ip_blacklist", reqServer.ApiAddr)
var b base.ApiCtrlAddIpBlacklistReq
b.Ip = ip
b.DurationSec = durationSec

nazalog.Infof("[%s] addIpBlacklist. send to %s with %+v", serverId, reqServer.ApiAddr, b)
if _, err := nazahttp.PostJson(url, b, nil); err != nil {
nazalog.Errorf("[%s] post json error. err=%+v", serverId, err)
}
return
}

0 comments on commit d0c084c

Please sign in to comment.