mirror of
https://github.com/bluenviron/mediamtx
synced 2025-01-23 15:34:28 +00:00
43 lines
740 B
Go
43 lines
740 B
Go
|
package core
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
func externalAuth(
|
||
|
ur string,
|
||
|
ip string,
|
||
|
user string,
|
||
|
password string,
|
||
|
path string,
|
||
|
action string,
|
||
|
) error {
|
||
|
enc, _ := json.Marshal(struct {
|
||
|
IP string `json:"ip"`
|
||
|
User string `json:"user"`
|
||
|
Password string `json:"password"`
|
||
|
Path string `json:"path"`
|
||
|
Action string `json:"action"`
|
||
|
}{
|
||
|
IP: ip,
|
||
|
User: user,
|
||
|
Password: password,
|
||
|
Path: path,
|
||
|
Action: action,
|
||
|
})
|
||
|
res, err := http.Post(ur, "application/json", bytes.NewReader(enc))
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer res.Body.Close()
|
||
|
|
||
|
if res.StatusCode < 200 || res.StatusCode > 299 {
|
||
|
return fmt.Errorf("bad status code: %d", res.StatusCode)
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|