mirror of
https://github.com/clearlinux/docker.git
synced 2026-10-03 23:38:24 +00:00
skeleton remote API, only version working (wip)
This commit is contained in:
@@ -1,63 +1,30 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
_"encoding/json"
|
||||
)
|
||||
|
||||
func ListenAndServe(addr string, runtime *Runtime) error {
|
||||
r := mux.NewRouter()
|
||||
log.Printf("Listening for HTTP on %s\n", addr)
|
||||
|
||||
type RestEndpoint struct {
|
||||
*mux.Router
|
||||
runtime *Runtime
|
||||
r.Path("/version").Methods("GET", "POST").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
m := VersionOut{VERSION, GIT_COMMIT, NO_MEMORY_LIMIT}
|
||||
b, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
} else {
|
||||
w.Write(b)
|
||||
}
|
||||
})
|
||||
|
||||
r.Path("/images").Methods("GET", "POST").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
//TODO use runtime
|
||||
})
|
||||
|
||||
return http.ListenAndServe(addr, r)
|
||||
}
|
||||
|
||||
func NewRestEndpoint(runtime *Runtime) *RestEndpoint {
|
||||
endpoint := &RestEndpoint{
|
||||
Router: mux.NewRouter(),
|
||||
runtime: runtime,
|
||||
}
|
||||
endpoint.Path("/images").Methods("GET").HandlerFunc(endpoint.GetImages)
|
||||
endpoint.Path("/images").Methods("POST").HandlerFunc(endpoint.PostImages)
|
||||
endpoint.Path("/images/{id}").Methods("GET").HandlerFunc(endpoint.GetImage)
|
||||
endpoint.Path("/images/{id}").Methods("DELETE").HandlerFunc(endpoint.DeleteImage)
|
||||
endpoint.Path("/containers").Methods("GET").HandlerFunc(endpoint.GetContainers)
|
||||
endpoint.Path("/containers").Methods("POST").HandlerFunc(endpoint.PostContainers)
|
||||
endpoint.Path("/containers/{id}").Methods("GET").HandlerFunc(endpoint.GetContainer)
|
||||
endpoint.Path("/containers/{id}").Methods("DELETE").HandlerFunc(endpoint.DeleteContainer)
|
||||
return endpoint
|
||||
}
|
||||
|
||||
func (ep *RestEndpoint) GetImages(w http.ResponseWriter, r *http.Response) {
|
||||
|
||||
}
|
||||
|
||||
func (ep *RestEndpoint) PostImages(w http.ResponseWriter, r *http.Response) {
|
||||
|
||||
}
|
||||
|
||||
func (ep *RestEndpoint) GetImage(w http.ResponseWriter, r *http.Response) {
|
||||
|
||||
}
|
||||
|
||||
func (ep *RestEndpoint) DeleteImage(w http.ResponseWriter, r *http.Response) {
|
||||
|
||||
}
|
||||
|
||||
func (ep *RestEndpoint) GetContainers(w http.ResponseWriter, r *http.Response) {
|
||||
|
||||
}
|
||||
|
||||
func (ep *RestEndpoint) PostContainers(w http.ResponseWriter, r *http.Response) {
|
||||
|
||||
}
|
||||
|
||||
func (ep *RestEndpoint) GetContainer(w http.ResponseWriter, r *http.Response) {
|
||||
|
||||
}
|
||||
|
||||
func (ep *RestEndpoint) DeleteContainer(w http.ResponseWriter, r *http.Response) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user