mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 20:35:24 +01:00
Merge pull request #583 from matejkramny/develop
fix dependency on mulekick
This commit is contained in:
commit
28482e1d56
6
Gopkg.lock
generated
6
Gopkg.lock
generated
@ -25,12 +25,6 @@
|
||||
revision = "ccb8e960c48f04d6935e72476ae4a51028f9e22f"
|
||||
version = "v9"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/castawaylabs/mulekick"
|
||||
packages = ["."]
|
||||
revision = "7029fb389811e0f873c56cfbbda64d66af48b095"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/go-openapi/analysis"
|
||||
|
@ -2,10 +2,6 @@
|
||||
name = "github.com/Sirupsen/logrus"
|
||||
version = "1.0.4"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/castawaylabs/mulekick"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/go-sql-driver/mysql"
|
||||
version = "1.3.0"
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
"github.com/gorilla/context"
|
||||
"github.com/masterminds/squirrel"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
sq "github.com/masterminds/squirrel"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gopkg.in/ldap.v2"
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
"github.com/gorilla/context"
|
||||
"github.com/masterminds/squirrel"
|
||||
)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
"github.com/gorilla/context"
|
||||
"github.com/masterminds/squirrel"
|
||||
"path/filepath"
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
"github.com/gorilla/context"
|
||||
"github.com/masterminds/squirrel"
|
||||
)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
"github.com/gorilla/context"
|
||||
"github.com/masterminds/squirrel"
|
||||
)
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
"github.com/gorilla/context"
|
||||
"github.com/masterminds/squirrel"
|
||||
"time"
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
"github.com/gorilla/context"
|
||||
"github.com/masterminds/squirrel"
|
||||
)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
"github.com/gorilla/context"
|
||||
"github.com/masterminds/squirrel"
|
||||
)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
"github.com/gorilla/context"
|
||||
"github.com/masterminds/squirrel"
|
||||
)
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"github.com/ansible-semaphore/semaphore/api/sockets"
|
||||
"github.com/ansible-semaphore/semaphore/api/tasks"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
"github.com/gobuffalo/packr"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/russross/blackfriday"
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
"github.com/gorilla/context"
|
||||
"github.com/masterminds/squirrel"
|
||||
)
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
"github.com/gorilla/context"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"github.com/castawaylabs/mulekick"
|
||||
"github.com/ansible-semaphore/mulekick"
|
||||
"github.com/gorilla/context"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
67
mulekick/router.go
Normal file
67
mulekick/router.go
Normal file
@ -0,0 +1,67 @@
|
||||
package mulekick
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
type Router struct {
|
||||
*mux.Router
|
||||
}
|
||||
|
||||
func (r Router) Get(endpoint string, hf http.HandlerFunc) *mux.Route {
|
||||
return r.HandleFunc(endpoint, hf).Methods("GET", "HEAD")
|
||||
}
|
||||
|
||||
func (r Router) GetHandle(endpoint string, hf http.Handler) *mux.Route {
|
||||
return r.Handle(endpoint, hf).Methods("GET", "HEAD")
|
||||
}
|
||||
|
||||
func (r Router) Post(endpoint string, hf http.HandlerFunc) *mux.Route {
|
||||
return r.HandleFunc(endpoint, hf).Methods("POST")
|
||||
}
|
||||
|
||||
func (r Router) PostHandle(endpoint string, hf http.Handler) *mux.Route {
|
||||
return r.Handle(endpoint, hf).Methods("POST")
|
||||
}
|
||||
|
||||
func (r Router) Put(endpoint string, hf http.HandlerFunc) *mux.Route {
|
||||
return r.HandleFunc(endpoint, hf).Methods("PUT")
|
||||
}
|
||||
|
||||
func (r Router) PutHandle(endpoint string, hf http.Handler) *mux.Route {
|
||||
return r.Handle(endpoint, hf).Methods("PUT")
|
||||
}
|
||||
|
||||
func (r Router) Delete(endpoint string, hf http.HandlerFunc) *mux.Route {
|
||||
return r.HandleFunc(endpoint, hf).Methods("DELETE")
|
||||
}
|
||||
|
||||
func (r Router) DeleteHandle(endpoint string, hf http.Handler) *mux.Route {
|
||||
return r.Handle(endpoint, hf).Methods("DELETE")
|
||||
}
|
||||
|
||||
func (r Router) Patch(endpoint string, hf http.HandlerFunc) *mux.Route {
|
||||
return r.HandleFunc(endpoint, hf).Methods("PATCH")
|
||||
}
|
||||
|
||||
func (r Router) PatchHandle(endpoint string, hf http.Handler) *mux.Route {
|
||||
return r.Handle(endpoint, hf).Methods("PATCH")
|
||||
}
|
||||
|
||||
func (r Router) Options(endpoint string, hf http.HandlerFunc) *mux.Route {
|
||||
return r.HandleFunc(endpoint, hf).Methods("OPTIONS")
|
||||
}
|
||||
|
||||
func (r Router) OptionsHandle(endpoint string, hf http.Handler) *mux.Route {
|
||||
return r.Handle(endpoint, hf).Methods("OPTIONS")
|
||||
}
|
||||
|
||||
// Group creates a new sub-router, enabling you to group handlers
|
||||
func (r Router) Group(str string, middleware ...mux.MiddlewareFunc) Router {
|
||||
subR := r.PathPrefix(str).Subrouter()
|
||||
subR.Use(middleware...)
|
||||
|
||||
return Router{subR}
|
||||
}
|
21
mulekick/router_test.go
Normal file
21
mulekick/router_test.go
Normal file
@ -0,0 +1,21 @@
|
||||
package mulekick
|
||||
|
||||
import "net/http"
|
||||
|
||||
func ExampleRouter_Use() {
|
||||
r := &Router{}
|
||||
|
||||
r.Get("/hello", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}))
|
||||
r.Use(func(next http.Handler) http.Handler {
|
||||
// sample middleware
|
||||
return next
|
||||
})
|
||||
r.Post("/world", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}))
|
||||
|
||||
// /hello call will not be affected by middleware
|
||||
// /world will have the middleware in its stack
|
||||
}
|
32
mulekick/utility.go
Normal file
32
mulekick/utility.go
Normal file
@ -0,0 +1,32 @@
|
||||
package mulekick
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
type H map[string]interface{}
|
||||
|
||||
func New(r *mux.Router, middleware ...http.HandlerFunc) Router {
|
||||
return Router{r}
|
||||
}
|
||||
|
||||
func Bind(w http.ResponseWriter, r *http.Request, out interface{}) error {
|
||||
err := json.NewDecoder(r.Body).Decode(out)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func WriteJSON(w http.ResponseWriter, code int, out interface{}) {
|
||||
w.Header().Set("content-type", "application/json")
|
||||
w.WriteHeader(code)
|
||||
|
||||
if err := json.NewEncoder(w).Encode(out); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user