Rename internals struct.

Signed-off-by: François de Metz <francois@stormz.me>
Signed-off-by: Cyril Duez <cyril@stormz.me>
This commit is contained in:
François de Metz
2016-05-27 17:51:53 +02:00
parent 6775719975
commit a1927ea6ed
4 changed files with 17 additions and 19 deletions

View File

@@ -12,26 +12,25 @@ import (
)
func init() {
webhooks_models.Add("github", func(path string) webhooks_models.Webhook { return NewGithubWebhooks(path) })
webhooks_models.Add("github", func(path string) webhooks_models.Webhook { return NewGithubWebhook(path) })
}
type GithubWebhooks struct {
type GithubWebhook struct {
Path string
acc telegraf.Accumulator
}
func NewGithubWebhooks(path string) *GithubWebhooks {
return &GithubWebhooks{Path: path}
func NewGithubWebhook(path string) *GithubWebhook {
return &GithubWebhook{Path: path}
}
func (gh *GithubWebhooks) Register(router *mux.Router, acc telegraf.Accumulator) {
func (gh *GithubWebhook) Register(router *mux.Router, acc telegraf.Accumulator) {
router.HandleFunc(gh.Path, gh.eventHandler).Methods("POST")
log.Printf("Started the webhooks_github on %s\n", gh.Path)
gh.acc = acc
}
// Handles the / route
func (gh *GithubWebhooks) eventHandler(w http.ResponseWriter, r *http.Request) {
func (gh *GithubWebhook) eventHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
eventType := r.Header["X-Github-Event"][0]
data, err := ioutil.ReadAll(r.Body)

View File

@@ -11,7 +11,7 @@ import (
func GithubWebhookRequest(event string, jsonString string, t *testing.T) {
var acc testutil.Accumulator
gh := NewGithubWebhooks("/github")
gh := NewGithubWebhook("/github")
gh.acc = &acc
req, _ := http.NewRequest("POST", "/github", strings.NewReader(jsonString))
req.Header.Add("X-Github-Event", event)