Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tank
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
tank
Commits
2b913a86
Commit
2b913a86
authored
7 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
moved api to seperate package
parent
4f162f1b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/v1/api.go
+172
-0
172 additions, 0 deletions
api/v1/api.go
cmd/tank/web.go
+2
-1
2 additions, 1 deletion
cmd/tank/web.go
with
174 additions
and
1 deletion
cmd/tank/web-
apiv1.go
→
api
/
v1
/api
.go
+
172
−
0
View file @
2b913a86
...
...
@@ -22,7 +22,7 @@
// along with tank. If not, see <http://www.gnu.org/licenses/>.
//
package
main
package
v1
import
(
"encoding/json"
...
...
@@ -31,125 +31,126 @@ import (
"github.com/gorilla/mux"
)
type
webAPIv1E
ndpoint
struct
{
type
e
ndpoint
struct
{
Methods
[]
string
`json:"allowed-methods"`
}
var
(
webAPIv1E
ndpoints
=
make
(
map
[
string
]
*
webAPIv1E
ndpoint
)
e
ndpoints
=
make
(
map
[
string
]
*
e
ndpoint
)
)
// common
func
webAPIv1_Index
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
listEndpoints
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
json
.
NewEncoder
(
w
)
.
Encode
(
webAPIv1E
ndpoints
)
json
.
NewEncoder
(
w
)
.
Encode
(
e
ndpoints
)
}
func
webAPIv1__
methodNotAllowed
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
methodNotAllowed
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"method not allowed"
,
http
.
StatusMethodNotAllowed
)
}
// Groups
func
webAPIv1_
Groups
_List
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
list
Groups
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"listing groups not yet implemented"
,
http
.
StatusNotImplemented
)
}
// Imports
func
webAPIv1_
ImportsOfGroup
_List
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
list
ImportsOfGroup
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"listing imports of group not yet implemented"
,
http
.
StatusNotImplemented
)
}
func
webAPIv1_
Import
sOf
Group
_Create
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
create
Import
For
Group
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"creating imports in group not yet implemented"
,
http
.
StatusNotImplemented
)
}
func
webAPIv1_
Import
s
OfGroup
_Read
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
read
ImportOfGroup
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"reading imports of group not yet implemented"
,
http
.
StatusNotImplemented
)
}
func
webAPIv1_
Import
s
OfGroup
_Upload
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
uploadFileTo
ImportOfGroup
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"uploading files to imports of group not yet implemented"
,
http
.
StatusNotImplemented
)
}
func
webAPIv1_
Import
s
OfGroup
_Delete
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
delete
ImportOfGroup
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"deleting imports from group not yet implemented"
,
http
.
StatusNotImplemented
)
}
// Files
func
webAPIv1_
FilesOfGroup
_List
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
list
FilesOfGroup
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"listing files of group not yet implemented"
,
http
.
StatusNotImplemented
)
}
func
webAPIv1_
File
s
OfGroup
_Read
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
read
FileOfGroup
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"reading file of group not yet implemented"
,
http
.
StatusNotImplemented
)
}
func
webAPIv1_
File
s
OfGroup
_Update
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
update
FileOfGroup
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"updateing file of group not yet implemented"
,
http
.
StatusNotImplemented
)
}
func
webAPIv1_
File
s
OfGroup
_Delete
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
delete
FileOfGroup
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"deleting file from group not yet implemented"
,
http
.
StatusNotImplemented
)
}
// Playlists
func
webAPIv1_
PlaylistsOfGroup
_List
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
list
PlaylistsOfGroup
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"listing playlists of group not yet implemented"
,
http
.
StatusNotImplemented
)
}
func
webAPIv1_
Playlist
sOf
Group
_Create
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
create
Playlist
For
Group
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"creating playlists in group not yet implemented"
,
http
.
StatusNotImplemented
)
}
func
webAPIv1_
Playlist
s
OfGroup
_Read
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
read
PlaylistOfGroup
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"reading playlist of group not yet implemented"
,
http
.
StatusNotImplemented
)
}
func
webAPIv1_
Playlist
s
OfGroup
_Update
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
update
PlaylistOfGroup
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"updateing playlist of group not yet implemented"
,
http
.
StatusNotImplemented
)
}
func
webAPIv1_
Playlist
s
OfGroup
_Delete
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
delete
PlaylistOfGroup
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
http
.
Error
(
w
,
"deleting playlist from group not yet implemented"
,
http
.
StatusNotImplemented
)
}
func
webAPIv1
InstallHandler
(
r
*
mux
.
Router
)
{
func
InstallHandler
(
r
*
mux
.
Router
)
{
// Groups
r
.
HandleFunc
(
"/groups"
,
webAPIv1_
Groups
_List
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups"
,
webAPIv1__
methodNotAllowed
)
r
.
HandleFunc
(
"/groups"
,
list
Groups
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups"
,
methodNotAllowed
)
// Imports
r
.
HandleFunc
(
"/groups/{group-id}/imports"
,
webAPIv1_
ImportsOfGroup
_List
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups/{group-id}/imports"
,
webAPIv1_
Import
sOf
Group
_Create
)
.
Methods
(
"POST"
)
r
.
HandleFunc
(
"/groups/{group-id}/imports"
,
webAPIv1__
methodNotAllowed
)
r
.
HandleFunc
(
"/groups/{group-id}/imports"
,
list
ImportsOfGroup
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups/{group-id}/imports"
,
create
Import
For
Group
)
.
Methods
(
"POST"
)
r
.
HandleFunc
(
"/groups/{group-id}/imports"
,
methodNotAllowed
)
r
.
HandleFunc
(
"/groups/{group-id}/imports/{import-id}"
,
webAPIv1_
Import
s
OfGroup
_Read
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups/{group-id}/imports/{import-id}"
,
webAPIv1_
Import
s
OfGroup
_Upload
)
.
Methods
(
"PUT"
)
r
.
HandleFunc
(
"/groups/{group-id}/imports/{import-id}"
,
webAPIv1_
Import
s
OfGroup
_Delete
)
.
Methods
(
"DELETE"
)
r
.
HandleFunc
(
"/groups/{group-id}/imports/{import-id}"
,
webAPIv1__
methodNotAllowed
)
r
.
HandleFunc
(
"/groups/{group-id}/imports/{import-id}"
,
read
ImportOfGroup
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups/{group-id}/imports/{import-id}"
,
uploadFileTo
ImportOfGroup
)
.
Methods
(
"PUT"
)
r
.
HandleFunc
(
"/groups/{group-id}/imports/{import-id}"
,
delete
ImportOfGroup
)
.
Methods
(
"DELETE"
)
r
.
HandleFunc
(
"/groups/{group-id}/imports/{import-id}"
,
methodNotAllowed
)
// Files
r
.
HandleFunc
(
"/groups/{group-id}/files"
,
webAPIv1_
FilesOfGroup
_List
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups/{group-id}/files"
,
webAPIv1__
methodNotAllowed
)
r
.
HandleFunc
(
"/groups/{group-id}/files"
,
list
FilesOfGroup
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups/{group-id}/files"
,
methodNotAllowed
)
r
.
HandleFunc
(
"/groups/{group-id}/files/{file-id}"
,
webAPIv1_
File
s
OfGroup
_Read
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups/{group-id}/files/{file-id}"
,
webAPIv1_
File
s
OfGroup
_Update
)
.
Methods
(
"PUT"
)
r
.
HandleFunc
(
"/groups/{group-id}/files/{file-id}"
,
webAPIv1_
File
s
OfGroup
_Delete
)
.
Methods
(
"DELETE"
)
r
.
HandleFunc
(
"/groups/{group-id}/files/{file-id}"
,
webAPIv1__
methodNotAllowed
)
r
.
HandleFunc
(
"/groups/{group-id}/files/{file-id}"
,
read
FileOfGroup
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups/{group-id}/files/{file-id}"
,
update
FileOfGroup
)
.
Methods
(
"PUT"
)
r
.
HandleFunc
(
"/groups/{group-id}/files/{file-id}"
,
delete
FileOfGroup
)
.
Methods
(
"DELETE"
)
r
.
HandleFunc
(
"/groups/{group-id}/files/{file-id}"
,
methodNotAllowed
)
// Playlists
r
.
HandleFunc
(
"/groups/{group-id}/playlists"
,
webAPIv1_
PlaylistsOfGroup
_List
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups/{group-id}/playlists"
,
webAPIv1_
Playlist
sOf
Group
_Create
)
.
Methods
(
"POST"
)
r
.
HandleFunc
(
"/groups/{group-id}/playlists"
,
webAPIv1__
methodNotAllowed
)
r
.
HandleFunc
(
"/groups/{group-id}/playlists"
,
list
PlaylistsOfGroup
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups/{group-id}/playlists"
,
create
Playlist
For
Group
)
.
Methods
(
"POST"
)
r
.
HandleFunc
(
"/groups/{group-id}/playlists"
,
methodNotAllowed
)
r
.
HandleFunc
(
"/groups/{group-id}/playlists/{playlist-id}"
,
webAPIv1_
Playlist
s
OfGroup
_Read
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups/{group-id}/playlists/{playlist-id}"
,
webAPIv1_
Playlist
s
OfGroup
_Update
)
.
Methods
(
"PUT"
)
r
.
HandleFunc
(
"/groups/{group-id}/playlists/{playlist-id}"
,
webAPIv1_
Playlist
s
OfGroup
_Delete
)
.
Methods
(
"DELETE"
)
r
.
HandleFunc
(
"/groups/{group-id}/playlists/{playlist-id}"
,
webAPIv1__
methodNotAllowed
)
r
.
HandleFunc
(
"/groups/{group-id}/playlists/{playlist-id}"
,
read
PlaylistOfGroup
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/groups/{group-id}/playlists/{playlist-id}"
,
update
PlaylistOfGroup
)
.
Methods
(
"PUT"
)
r
.
HandleFunc
(
"/groups/{group-id}/playlists/{playlist-id}"
,
delete
PlaylistOfGroup
)
.
Methods
(
"DELETE"
)
r
.
HandleFunc
(
"/groups/{group-id}/playlists/{playlist-id}"
,
methodNotAllowed
)
// Index
r
.
HandleFunc
(
"/"
,
webAPIv1_Index
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/"
,
webAPIv1__methodNotAllowed
)
r
.
HandleFunc
(
"/"
,
listEndpoints
)
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/"
,
methodNotAllowed
)
r
.
Walk
(
func
(
route
*
mux
.
Route
,
router
*
mux
.
Router
,
ancestors
[]
*
mux
.
Route
)
error
{
p
,
err
:=
route
.
GetPathTemplate
()
if
err
!=
nil
{
...
...
@@ -161,10 +162,10 @@ func webAPIv1InstallHandler(r *mux.Router) {
return
err
}
if
e
,
exists
:=
webAPIv1E
ndpoints
[
p
];
exists
{
if
e
,
exists
:=
e
ndpoints
[
p
];
exists
{
e
.
Methods
=
append
(
e
.
Methods
,
m
...
)
}
else
{
webAPIv1E
ndpoints
[
p
]
=
&
webAPIv1E
ndpoint
{
m
}
e
ndpoints
[
p
]
=
&
e
ndpoint
{
m
}
}
return
nil
})
...
...
This diff is collapsed.
Click to expand it.
cmd/tank/web.go
+
2
−
1
View file @
2b913a86
...
...
@@ -32,6 +32,7 @@ import (
"time"
"github.com/gorilla/mux"
"gitlab.servus.at/autoradio/tank/api/v1"
)
const
(
...
...
@@ -45,7 +46,7 @@ func runWeb(ln net.Listener) error {
r
.
Handle
(
"/"
,
http
.
RedirectHandler
(
WebUIPathPrefix
,
http
.
StatusSeeOther
))
r
.
PathPrefix
(
WebUIPathPrefix
)
.
Handler
(
http
.
StripPrefix
(
WebUIPathPrefix
,
http
.
FileServer
(
assetFS
())))
webAPI
v1InstallHandler
(
r
.
PathPrefix
(
WebAPIv1Prefix
)
.
Subrouter
())
v1
.
InstallHandler
(
r
.
PathPrefix
(
WebAPIv1Prefix
)
.
Subrouter
())
srv
:=
&
http
.
Server
{
Handler
:
r
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment