diff --git a/cmd/berty-release/server.go b/cmd/berty-release/server.go new file mode 100644 index 00000000..6f96516c --- /dev/null +++ b/cmd/berty-release/server.go @@ -0,0 +1,27 @@ +package main + +import ( + "github.com/berty/staff/tools/release/server" + "github.com/spf13/cobra" +) + +type serverConfig struct { + addr string +} + +var serverCfg serverConfig + +var serveCmd = &cobra.Command{ + Use: "serve", + Short: "Server release tool", + Run: func(cmd *cobra.Command, args []string) { + s := server.NewServer(cfg.client) + panic(s.Start(serverCfg.addr)) + }, +} + +func init() { + serveCmd.PersistentFlags().StringVarP(&serverCfg.addr, "listen", "l", ":3670", "Listen addr") + + rootCmd.AddCommand(serveCmd) +} diff --git a/server/handler.go b/server/handler.go new file mode 100644 index 00000000..693168f0 --- /dev/null +++ b/server/handler.go @@ -0,0 +1,23 @@ +package server + +import ( + "net/http" + "strconv" + + "github.com/labstack/echo" +) + +func (s *Server) Build(c echo.Context) error { + id := c.Param("build_id") + i, err := strconv.Atoi(id) + if err != nil { + return c.JSON(http.StatusInternalServerError, err) + } + + ret, err := s.client.Build(i) + if err != nil { + return c.JSON(http.StatusInternalServerError, err) + } + + return c.JSON(http.StatusOK, ret) +} diff --git a/server/server.go b/server/server.go new file mode 100644 index 00000000..7fa4ccbe --- /dev/null +++ b/server/server.go @@ -0,0 +1,31 @@ +package server + +import ( + "github.com/berty/staff/tools/release/pkg/circle" + "github.com/labstack/echo" +) + +type httperror struct { + message string `json:message` +} + +type Server struct { + client *circle.Client + e *echo.Echo +} + +func NewServer(client *circle.Client) *Server { + e := echo.New() + s := &Server{client, e} + + e.GET("/build/:build_id", s.Build) + // e.GET("/builds", e.Build) + // e.GET("/artifacts/:build_id", e.Build) + // e.GET("/release/:build_id", e.Build) + + return s +} + +func (s *Server) Start(addr string) error { + return s.e.Start(addr) +}