-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (57 loc) · 1.57 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"flag"
"io/ioutil"
"log"
"net"
"net/http"
"os"
"github.com/labstack/echo"
"github.com/sirupsen/logrus"
)
func main() {
var socketPath string
flag.StringVar(&socketPath, "socket", "/run/guest/volumes-service.sock", "Unix domain socket to listen on")
flag.Parse()
os.RemoveAll(socketPath)
logrus.New().Infof("Starting listening on %s\n", socketPath)
router := echo.New()
router.HideBanner = true
startURL := ""
ln, err := listen(socketPath)
if err != nil {
log.Fatal(err)
}
router.Listener = ln
router.GET("/hello", hello)
router.GET("/compose-files", composeFileList)
router.GET("/compose-file", composeFile)
log.Fatal(router.Start(startURL))
}
type composeFileListItem struct {
Name string `json:"name"`
Description string `json:"description"`
}
func listen(path string) (net.Listener, error) {
return net.Listen("unix", path)
}
func hello(ctx echo.Context) error {
return ctx.JSON(http.StatusOK, HTTPMessageBody{Message: "hello"})
}
func composeFile(ctx echo.Context) error {
resp, _ := http.Get("https://gist.githubusercontent.com/adamelliotfields/cd49f056deab05250876286d7657dc4b/raw/31198290728608a78b47b0496ef51e60be6b6d0b/docker-compose.yml")
body, _ := ioutil.ReadAll(resp.Body)
return ctx.JSON(http.StatusOK, HTTPMessageBody{
Message: string(body),
})
}
func composeFileList(ctx echo.Context) error {
resp, _ := http.Get("http:https://localhost:8000/composes")
body, _ := ioutil.ReadAll(resp.Body)
return ctx.JSON(http.StatusOK, HTTPMessageBody{
Message: string(body),
})
}
type HTTPMessageBody struct {
Message string
}