-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor new file dispatch/http_api_client.go
- Loading branch information
1 parent
da5730f
commit d0c084c
Showing
2 changed files
with
54 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ([email protected]) | ||
|
||
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 | ||
} |