mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-23 22:02:28 +00:00
refactoring
This commit is contained in:
parent
a5d79fddd9
commit
f1c4415fc8
5 changed files with 130 additions and 74 deletions
|
@ -3,7 +3,9 @@ package hooks
|
|||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
|
||||
"github.com/adnanh/webhook/helpers"
|
||||
"github.com/adnanh/webhook/rules"
|
||||
)
|
||||
|
||||
|
@ -25,6 +27,40 @@ type Hooks struct {
|
|||
list []Hook
|
||||
}
|
||||
|
||||
// ParseFormArgs gets arguments from the Form payload that should be passed to the command
|
||||
func (h *Hook) ParseFormArgs(form url.Values) []string {
|
||||
var args = make([]string, len(h.Args))
|
||||
|
||||
args = append(args, h.Command)
|
||||
|
||||
for i := range h.Args {
|
||||
if arg := form[h.Args[i]]; len(arg) > 0 {
|
||||
args = append(args, arg[0])
|
||||
} else {
|
||||
args = append(args, "")
|
||||
}
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
// ParseJSONArgs gets arguments from the JSON payload that should be passed to the command
|
||||
func (h *Hook) ParseJSONArgs(payload interface{}) []string {
|
||||
var args = make([]string, len(h.Args))
|
||||
|
||||
args = append(args, h.Command)
|
||||
|
||||
for i := range h.Args {
|
||||
if arg, ok := helpers.ExtractJSONParameter(h.Args[i], payload); ok {
|
||||
args = append(args, arg)
|
||||
} else {
|
||||
args = append(args, "")
|
||||
}
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
// UnmarshalJSON implementation for a single hook
|
||||
func (h *Hook) UnmarshalJSON(j []byte) error {
|
||||
m := make(map[string]interface{})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue