Browse Source

api: add v1 prefix

pull/509/head v0.17.0
aler9 5 years ago committed by Alessandro Ros
parent
commit
10b5a6b4dd
  1. 22
      apidocs/openapi.yaml
  2. 40
      internal/core/api_test.go

22
apidocs/openapi.yaml

@ -9,7 +9,7 @@ info: @@ -9,7 +9,7 @@ info:
url: https://opensource.org/licenses/MIT
servers:
- url: http://localhost:9997/v1
- url: http://localhost:9997
components:
schemas:
@ -249,7 +249,7 @@ components: @@ -249,7 +249,7 @@ components:
type: string
paths:
/config/get:
/v1/config/get:
get:
operationId: configGet
summary: returns the current configuration.
@ -264,7 +264,7 @@ paths: @@ -264,7 +264,7 @@ paths:
'500':
description: internal server error.
/config/set:
/v1/config/set:
post:
operationId: configSet
summary: changes the current configuration.
@ -283,7 +283,7 @@ paths: @@ -283,7 +283,7 @@ paths:
'500':
description: internal server error.
/config/paths/add/{name}:
/v1/config/paths/add/{name}:
post:
operationId: configPathsAdd
summary: adds the configuration of a path.
@ -309,7 +309,7 @@ paths: @@ -309,7 +309,7 @@ paths:
'500':
description: internal server error.
/config/paths/edit/{name}:
/v1/config/paths/edit/{name}:
post:
operationId: configPathsEdit
summary: changes the configuration of a path.
@ -335,7 +335,7 @@ paths: @@ -335,7 +335,7 @@ paths:
'500':
description: internal server error.
/config/paths/remove/{name}:
/v1/config/paths/remove/{name}:
post:
operationId: configPathsRemove
summary: removes the configuration of a path.
@ -355,7 +355,7 @@ paths: @@ -355,7 +355,7 @@ paths:
'500':
description: internal server error.
/paths/list:
/v1/paths/list:
get:
operationId: pathsList
summary: returns all active paths.
@ -375,7 +375,7 @@ paths: @@ -375,7 +375,7 @@ paths:
'500':
description: internal server error.
/rtspsessions/list:
/v1/rtspsessions/list:
get:
operationId: rtspSessionsList
summary: returns all active RTSP sessions.
@ -395,7 +395,7 @@ paths: @@ -395,7 +395,7 @@ paths:
'500':
description: internal server error.
/rtspsessions/kick/{id}:
/v1/rtspsessions/kick/{id}:
post:
operationId: rtspSessionsKick
summary: kicks out a RTSP session from the server.
@ -415,7 +415,7 @@ paths: @@ -415,7 +415,7 @@ paths:
'500':
description: internal server error.
/rtmpconns/list:
/v1/rtmpconns/list:
get:
operationId: rtmpConnsList
summary: returns all active RTMP connections.
@ -435,7 +435,7 @@ paths: @@ -435,7 +435,7 @@ paths:
'500':
description: internal server error.
/rtmpconns/kick/{id}:
/v1/rtmpconns/kick/{id}:
post:
operationId: rtmpConnsKick
summary: kicks out a RTMP connection from the server.

40
internal/core/api_test.go

@ -58,7 +58,7 @@ func TestAPIConfigGet(t *testing.T) { @@ -58,7 +58,7 @@ func TestAPIConfigGet(t *testing.T) {
defer p.close()
var out map[string]interface{}
err := httpRequest(http.MethodGet, "http://localhost:9997/config/get", nil, &out)
err := httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out)
require.NoError(t, err)
require.Equal(t, true, out["api"])
}
@ -68,7 +68,7 @@ func TestAPIConfigSet(t *testing.T) { @@ -68,7 +68,7 @@ func TestAPIConfigSet(t *testing.T) {
require.Equal(t, true, ok)
defer p.close()
err := httpRequest(http.MethodPost, "http://localhost:9997/config/set", map[string]interface{}{
err := httpRequest(http.MethodPost, "http://localhost:9997/v1/config/set", map[string]interface{}{
"rtmpDisable": true,
}, nil)
require.NoError(t, err)
@ -76,7 +76,7 @@ func TestAPIConfigSet(t *testing.T) { @@ -76,7 +76,7 @@ func TestAPIConfigSet(t *testing.T) {
time.Sleep(500 * time.Millisecond)
var out map[string]interface{}
err = httpRequest(http.MethodGet, "http://localhost:9997/config/get", nil, &out)
err = httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out)
require.NoError(t, err)
require.Equal(t, true, out["rtmpDisable"])
}
@ -86,14 +86,14 @@ func TestAPIConfigPathsAdd(t *testing.T) { @@ -86,14 +86,14 @@ func TestAPIConfigPathsAdd(t *testing.T) {
require.Equal(t, true, ok)
defer p.close()
err := httpRequest(http.MethodPost, "http://localhost:9997/config/paths/add/mypath", map[string]interface{}{
err := httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/add/mypath", map[string]interface{}{
"source": "rtsp://127.0.0.1:9999/mypath",
"sourceOnDemand": true,
}, nil)
require.NoError(t, err)
var out map[string]interface{}
err = httpRequest(http.MethodGet, "http://localhost:9997/config/get", nil, &out)
err = httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out)
require.NoError(t, err)
require.Equal(t, "rtsp://127.0.0.1:9999/mypath", out["paths"].(map[string]interface{})["mypath"].(map[string]interface{})["source"])
}
@ -103,13 +103,13 @@ func TestAPIConfigPathsEdit(t *testing.T) { @@ -103,13 +103,13 @@ func TestAPIConfigPathsEdit(t *testing.T) {
require.Equal(t, true, ok)
defer p.close()
err := httpRequest(http.MethodPost, "http://localhost:9997/config/paths/add/mypath", map[string]interface{}{
err := httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/add/mypath", map[string]interface{}{
"source": "rtsp://127.0.0.1:9999/mypath",
"sourceOnDemand": true,
}, nil)
require.NoError(t, err)
err = httpRequest(http.MethodPost, "http://localhost:9997/config/paths/edit/mypath", map[string]interface{}{
err = httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/edit/mypath", map[string]interface{}{
"source": "rtsp://127.0.0.1:9998/mypath",
"sourceOnDemand": true,
}, nil)
@ -120,7 +120,7 @@ func TestAPIConfigPathsEdit(t *testing.T) { @@ -120,7 +120,7 @@ func TestAPIConfigPathsEdit(t *testing.T) {
Source string `json:"source"`
} `json:"paths"`
}
err = httpRequest(http.MethodGet, "http://localhost:9997/config/get", nil, &out)
err = httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out)
require.NoError(t, err)
require.Equal(t, "rtsp://127.0.0.1:9998/mypath", out.Paths["mypath"].Source)
}
@ -130,19 +130,19 @@ func TestAPIConfigPathsRemove(t *testing.T) { @@ -130,19 +130,19 @@ func TestAPIConfigPathsRemove(t *testing.T) {
require.Equal(t, true, ok)
defer p.close()
err := httpRequest(http.MethodPost, "http://localhost:9997/config/paths/add/mypath", map[string]interface{}{
err := httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/add/mypath", map[string]interface{}{
"source": "rtsp://127.0.0.1:9999/mypath",
"sourceOnDemand": true,
}, nil)
require.NoError(t, err)
err = httpRequest(http.MethodPost, "http://localhost:9997/config/paths/remove/mypath", nil, nil)
err = httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/remove/mypath", nil, nil)
require.NoError(t, err)
var out struct {
Paths map[string]interface{} `json:"paths"`
}
err = httpRequest(http.MethodGet, "http://localhost:9997/config/get", nil, &out)
err = httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out)
require.NoError(t, err)
_, ok = out.Paths["mypath"]
require.Equal(t, false, ok)
@ -158,7 +158,7 @@ func TestAPIPathsList(t *testing.T) { @@ -158,7 +158,7 @@ func TestAPIPathsList(t *testing.T) {
var out struct {
Items map[string]interface{} `json:"items"`
}
err := httpRequest(http.MethodGet, "http://localhost:9997/paths/list", nil, &out)
err := httpRequest(http.MethodGet, "http://localhost:9997/v1/paths/list", nil, &out)
require.NoError(t, err)
_, ok = out.Items["mypath"]
require.Equal(t, true, ok)
@ -180,7 +180,7 @@ func TestAPIRTSPSessionsList(t *testing.T) { @@ -180,7 +180,7 @@ func TestAPIRTSPSessionsList(t *testing.T) {
var out struct {
Items map[string]struct{} `json:"items"`
}
err = httpRequest(http.MethodGet, "http://localhost:9997/rtspsessions/list", nil, &out)
err = httpRequest(http.MethodGet, "http://localhost:9997/v1/rtspsessions/list", nil, &out)
require.NoError(t, err)
require.Equal(t, 1, len(out.Items))
}
@ -201,7 +201,7 @@ func TestAPIRTSPSessionsKick(t *testing.T) { @@ -201,7 +201,7 @@ func TestAPIRTSPSessionsKick(t *testing.T) {
var out1 struct {
Items map[string]struct{} `json:"items"`
}
err = httpRequest(http.MethodGet, "http://localhost:9997/rtspsessions/list", nil, &out1)
err = httpRequest(http.MethodGet, "http://localhost:9997/v1/rtspsessions/list", nil, &out1)
require.NoError(t, err)
var firstID string
@ -209,13 +209,13 @@ func TestAPIRTSPSessionsKick(t *testing.T) { @@ -209,13 +209,13 @@ func TestAPIRTSPSessionsKick(t *testing.T) {
firstID = k
}
err = httpRequest(http.MethodPost, "http://localhost:9997/rtspsessions/kick/"+firstID, nil, nil)
err = httpRequest(http.MethodPost, "http://localhost:9997/v1/rtspsessions/kick/"+firstID, nil, nil)
require.NoError(t, err)
var out2 struct {
Items map[string]struct{} `json:"items"`
}
err = httpRequest(http.MethodGet, "http://localhost:9997/rtspsessions/list", nil, &out2)
err = httpRequest(http.MethodGet, "http://localhost:9997/v1/rtspsessions/list", nil, &out2)
require.NoError(t, err)
require.Equal(t, 0, len(out2.Items))
}
@ -239,7 +239,7 @@ func TestAPIRTMPConnsList(t *testing.T) { @@ -239,7 +239,7 @@ func TestAPIRTMPConnsList(t *testing.T) {
var out struct {
Items map[string]struct{} `json:"items"`
}
err = httpRequest(http.MethodGet, "http://localhost:9997/rtmpconns/list", nil, &out)
err = httpRequest(http.MethodGet, "http://localhost:9997/v1/rtmpconns/list", nil, &out)
require.NoError(t, err)
require.Equal(t, 1, len(out.Items))
}
@ -263,7 +263,7 @@ func TestAPIRTSPConnsKick(t *testing.T) { @@ -263,7 +263,7 @@ func TestAPIRTSPConnsKick(t *testing.T) {
var out1 struct {
Items map[string]struct{} `json:"items"`
}
err = httpRequest(http.MethodGet, "http://localhost:9997/rtmpconns/list", nil, &out1)
err = httpRequest(http.MethodGet, "http://localhost:9997/v1/rtmpconns/list", nil, &out1)
require.NoError(t, err)
var firstID string
@ -271,13 +271,13 @@ func TestAPIRTSPConnsKick(t *testing.T) { @@ -271,13 +271,13 @@ func TestAPIRTSPConnsKick(t *testing.T) {
firstID = k
}
err = httpRequest(http.MethodPost, "http://localhost:9997/rtmpconns/kick/"+firstID, nil, nil)
err = httpRequest(http.MethodPost, "http://localhost:9997/v1/rtmpconns/kick/"+firstID, nil, nil)
require.NoError(t, err)
var out2 struct {
Items map[string]struct{} `json:"items"`
}
err = httpRequest(http.MethodGet, "http://localhost:9997/rtmpconns/list", nil, &out2)
err = httpRequest(http.MethodGet, "http://localhost:9997/v1/rtmpconns/list", nil, &out2)
require.NoError(t, err)
require.Equal(t, 0, len(out2.Items))
}

Loading…
Cancel
Save