mvp
This commit is contained in:
parent
5d40de4bf3
commit
902cb5dd23
5 changed files with 67 additions and 3 deletions
|
|
@ -1,11 +1,25 @@
|
|||
package main
|
||||
|
||||
import "git.barakmich.com/barak/hoboken"
|
||||
import (
|
||||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"git.barakmich.com/barak/hoboken"
|
||||
)
|
||||
|
||||
var (
|
||||
path = flag.String("path", "./", "Set working path to watch for new projects")
|
||||
host = flag.String("host", "0.0.0.0", "Listen host")
|
||||
port = flag.String("port", "8081", "Listen port")
|
||||
)
|
||||
|
||||
func main() {
|
||||
p, err := hoboken.NewProjects("./")
|
||||
flag.Parse()
|
||||
p, err := hoboken.NewProjects(*path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
hoboken.WatchDir("./...", p)
|
||||
go hoboken.WatchDir(filepath.Join(*path, "/..."), p)
|
||||
hp := *host + ":" + *port
|
||||
hoboken.Listen(hp, p)
|
||||
}
|
||||
|
|
|
|||
37
http.go
Normal file
37
http.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package hoboken
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Listen(host string, p *Projects) {
|
||||
r := gin.Default()
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
for _, x := range p.projects {
|
||||
c.String(http.StatusOK, "%s\n", x.Name)
|
||||
}
|
||||
})
|
||||
r.GET("/hook", func(c *gin.Context) {
|
||||
project := c.Query("project")
|
||||
if project == "" {
|
||||
c.AbortWithStatus(http.StatusBadRequest)
|
||||
}
|
||||
p.RLock()
|
||||
defer p.RUnlock()
|
||||
for _, x := range p.projects {
|
||||
if x.Name == project {
|
||||
err := x.Exec()
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, "Err, didn't run")
|
||||
return
|
||||
}
|
||||
c.String(http.StatusOK, "Successfully ran")
|
||||
return
|
||||
}
|
||||
}
|
||||
c.String(http.StatusBadRequest, "No such project")
|
||||
})
|
||||
r.Run(host)
|
||||
}
|
||||
9
test/test.sh
Executable file
9
test/test.sh
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd $1
|
||||
mkdir -p src/git.barakmich.com/barak/hoboken
|
||||
export GOPATH=$1
|
||||
git clone https://git.barakmich.com/barak/hoboken.git src/git.barakmich.com/barak/hoboken
|
||||
go get git.barakmich.com/barak/hoboken
|
||||
go build git.barakmich.com/barak/hoboken/cmd/hoboken
|
||||
cp ./hoboken /tmp
|
||||
2
test/test.yaml
Normal file
2
test/test.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
name: barakFoo
|
||||
script: test.sh
|
||||
2
test/test2.yaml
Normal file
2
test/test2.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
name: Foo3
|
||||
script: test.sh
|
||||
Loading…
Add table
Add a link
Reference in a new issue