goimports
This commit is contained in:
parent
160d68f29c
commit
a45699efb1
|
|
@ -21,6 +21,7 @@ package main // import "k8s.io/git-sync/cmd/git-sync"
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
@ -33,7 +34,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/thockin/glogr"
|
"github.com/thockin/glogr"
|
||||||
"github.com/thockin/logr"
|
"github.com/thockin/logr"
|
||||||
|
|
@ -62,7 +62,7 @@ var flMaxSyncFailures = flag.Int("max-sync-failures", envInt("GIT_SYNC_MAX_SYNC_
|
||||||
"the number of consecutive failures allowed before aborting (the first pull must succeed, -1 disables aborting for any number of failures after the initial sync)")
|
"the number of consecutive failures allowed before aborting (the first pull must succeed, -1 disables aborting for any number of failures after the initial sync)")
|
||||||
var flChmod = flag.Int("change-permissions", envInt("GIT_SYNC_PERMISSIONS", 0),
|
var flChmod = flag.Int("change-permissions", envInt("GIT_SYNC_PERMISSIONS", 0),
|
||||||
"the file permissions to apply to the checked-out files")
|
"the file permissions to apply to the checked-out files")
|
||||||
|
|
||||||
var flWebhooks = flag.String("webhook", envString("GIT_SYNC_WEBHOOK", ""),
|
var flWebhooks = flag.String("webhook", envString("GIT_SYNC_WEBHOOK", ""),
|
||||||
"the JSON formatted array of webhooks to be sent when git is synced")
|
"the JSON formatted array of webhooks to be sent when git is synced")
|
||||||
var flWebhookTimeout = flag.Int("webhook-timeout", envInt("GIT_SYNC_WEBHOOK_TIMEOUT", 60),
|
var flWebhookTimeout = flag.Int("webhook-timeout", envInt("GIT_SYNC_WEBHOOK_TIMEOUT", 60),
|
||||||
|
|
@ -198,7 +198,6 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// From here on, output goes through logging.
|
// From here on, output goes through logging.
|
||||||
log.V(0).Infof("starting up: %q", os.Args)
|
log.V(0).Infof("starting up: %q", os.Args)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,32 @@
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create an http client that has our timeout by default
|
// Create an http client that has our timeout by default
|
||||||
var netClient = &http.Client{
|
var netClient = &http.Client{
|
||||||
Timeout: time.Duration(time.Second * time.Duration(*flWebhookTimeout) ),
|
Timeout: time.Duration(time.Second * time.Duration(*flWebhookTimeout)),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger channel for webhook requests. If anything is received into this channel
|
// Trigger channel for webhook requests. If anything is received into this channel
|
||||||
// it triggers the webhook goroutine to send new requests.
|
// it triggers the webhook goroutine to send new requests.
|
||||||
var WebhookCallTriggerChannel = make(chan struct{})
|
var WebhookCallTriggerChannel = make(chan struct{})
|
||||||
|
|
||||||
// Webhook collection
|
// Webhook collection
|
||||||
var WebhookArray = []Webhook{}
|
var WebhookArray = []Webhook{}
|
||||||
|
|
||||||
// WebHook structure
|
// WebHook structure
|
||||||
type Webhook struct {
|
type Webhook struct {
|
||||||
// URL for the http/s request
|
// URL for the http/s request
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
// Method for the http/s request
|
// Method for the http/s request
|
||||||
Method string `json:"method"`
|
Method string `json:"method"`
|
||||||
// Code to look for when determining if the request was successful.
|
// Code to look for when determining if the request was successful.
|
||||||
// If this is not specified, request is sent and forgotten about.
|
// If this is not specified, request is sent and forgotten about.
|
||||||
Success *int `json:"success"`
|
Success *int `json:"success"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebhookCall Do webhook call
|
// WebhookCall Do webhook call
|
||||||
|
|
@ -35,8 +35,8 @@ func WebHookCall(url string, method string, statusCode *int) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
resp, err := netClient.Do(req)
|
resp, err := netClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -55,7 +55,7 @@ func WebHookCall(url string, method string, statusCode *int) error {
|
||||||
func ServeWebhooks() {
|
func ServeWebhooks() {
|
||||||
for {
|
for {
|
||||||
// Wait for trigger
|
// Wait for trigger
|
||||||
<- WebhookCallTriggerChannel
|
<-WebhookCallTriggerChannel
|
||||||
|
|
||||||
// Calling webhook - one after another
|
// Calling webhook - one after another
|
||||||
for _, v := range WebhookArray {
|
for _, v := range WebhookArray {
|
||||||
|
|
@ -67,5 +67,5 @@ func ServeWebhooks() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue