refactor new file dispatch/http_api_client.go

pull/358/head
q191201771 8 months ago
parent da5730f40c
commit d0c084c4a8

@ -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()

@ -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
}
Loading…
Cancel
Save