Skip to content

Commit

Permalink
feat(release): Add server
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton committed Oct 2, 2018
1 parent 4bcdaa4 commit fd3bcca
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cmd/berty-release/server.go
Original file line number Diff line number Diff line change
@@ -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)
}
23 changes: 23 additions & 0 deletions server/handler.go
Original file line number Diff line number Diff line change
@@ -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)
}
31 changes: 31 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit fd3bcca

Please sign in to comment.