Run go fmt
over the codebase
This commit is contained in:
parent
eb19aca921
commit
1d008a0aad
3 changed files with 15 additions and 19 deletions
18
logserver.go
18
logserver.go
|
@ -69,7 +69,6 @@ func (f *logServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
serveFile(w, r, upath)
|
serveFile(w, r, upath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func serveFile(w http.ResponseWriter, r *http.Request, path string) {
|
func serveFile(w http.ResponseWriter, r *http.Request, path string) {
|
||||||
d, err := os.Stat(path)
|
d, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -144,9 +143,9 @@ func serveDirectory(w http.ResponseWriter, r *http.Request, path string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Streams a dynamically created tar.gz file with the contents of the given directory
|
// Streams a dynamically created tar.gz file with the contents of the given directory
|
||||||
// Will serve a partial, corrupted response if there is a error partway through the
|
// Will serve a partial, corrupted response if there is a error partway through the
|
||||||
// operation as we stream the response.
|
// operation as we stream the response.
|
||||||
//
|
//
|
||||||
// The resultant tarball will contain a single directory containing all the files
|
// The resultant tarball will contain a single directory containing all the files
|
||||||
// so it can unpack cleanly without overwriting other files.
|
// so it can unpack cleanly without overwriting other files.
|
||||||
//
|
//
|
||||||
|
@ -163,14 +162,14 @@ func serveTarball(w http.ResponseWriter, r *http.Request, dir string) error {
|
||||||
// and removes leading and trailing `/` and replaces internal `/` with `_`
|
// and removes leading and trailing `/` and replaces internal `/` with `_`
|
||||||
// to form a suitable filename for use in the content-disposition header
|
// to form a suitable filename for use in the content-disposition header
|
||||||
// dfilename would turn into `2022-01-10_184843-BZZXEGYH`
|
// dfilename would turn into `2022-01-10_184843-BZZXEGYH`
|
||||||
dfilename := strings.Trim(r.URL.Path,"/")
|
dfilename := strings.Trim(r.URL.Path, "/")
|
||||||
dfilename = strings.Replace(dfilename, "/","_",-1)
|
dfilename = strings.Replace(dfilename, "/", "_", -1)
|
||||||
|
|
||||||
// There is no application/tgz or similar; return a gzip file as best option.
|
// There is no application/tgz or similar; return a gzip file as best option.
|
||||||
// This tends to trigger archive type tools, which will then use the filename to
|
// This tends to trigger archive type tools, which will then use the filename to
|
||||||
// identify the contents correctly.
|
// identify the contents correctly.
|
||||||
w.Header().Set("Content-Type", "application/gzip")
|
w.Header().Set("Content-Type", "application/gzip")
|
||||||
w.Header().Set("Content-Disposition", "attachment; filename=" + dfilename + ".tar.gz")
|
w.Header().Set("Content-Disposition", "attachment; filename="+dfilename+".tar.gz")
|
||||||
|
|
||||||
files, err := directory.Readdir(-1)
|
files, err := directory.Readdir(-1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -182,7 +181,6 @@ func serveTarball(w http.ResponseWriter, r *http.Request, dir string) error {
|
||||||
targz := tar.NewWriter(gzip)
|
targz := tar.NewWriter(gzip)
|
||||||
defer targz.Close()
|
defer targz.Close()
|
||||||
|
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if file.IsDir() {
|
if file.IsDir() {
|
||||||
// We avoid including nested directories
|
// We avoid including nested directories
|
||||||
|
@ -206,7 +204,7 @@ func serveTarball(w http.ResponseWriter, r *http.Request, dir string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a single file into the archive.
|
// Add a single file into the archive.
|
||||||
func addToArchive(targz *tar.Writer, dfilename string, filename string) error {
|
func addToArchive(targz *tar.Writer, dfilename string, filename string) error {
|
||||||
file, err := os.Open(filename)
|
file, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
2
main.go
2
main.go
|
@ -180,7 +180,7 @@ func main() {
|
||||||
log.Fatal(http.ListenAndServe(*bindAddr, nil))
|
log.Fatal(http.ListenAndServe(*bindAddr, nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func configureGenericWebhookClient(cfg *config) (*http.Client) {
|
func configureGenericWebhookClient(cfg *config) *http.Client {
|
||||||
if len(cfg.GenericWebhookURLs) == 0 {
|
if len(cfg.GenericWebhookURLs) == 0 {
|
||||||
fmt.Println("No generic_webhook_urls configured.")
|
fmt.Println("No generic_webhook_urls configured.")
|
||||||
return nil
|
return nil
|
||||||
|
|
14
submit.go
14
submit.go
|
@ -58,7 +58,7 @@ type submitServer struct {
|
||||||
slack *slackClient
|
slack *slackClient
|
||||||
|
|
||||||
genericWebhookClient *http.Client
|
genericWebhookClient *http.Client
|
||||||
cfg *config
|
cfg *config
|
||||||
}
|
}
|
||||||
|
|
||||||
// the type of payload which can be uploaded as JSON to the submit endpoint
|
// the type of payload which can be uploaded as JSON to the submit endpoint
|
||||||
|
@ -77,11 +77,10 @@ type jsonLogEntry struct {
|
||||||
Lines string `json:"lines"`
|
Lines string `json:"lines"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type genericWebhookPayload struct {
|
type genericWebhookPayload struct {
|
||||||
parsedPayload
|
parsedPayload
|
||||||
ReportURL string `json:"report_url"`
|
ReportURL string `json:"report_url"`
|
||||||
ListingURL string `json:"listing_url"`
|
ListingURL string `json:"listing_url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// the payload after parsing
|
// the payload after parsing
|
||||||
|
@ -509,7 +508,7 @@ func (s *submitServer) saveReport(ctx context.Context, p parsedPayload, reportDi
|
||||||
|
|
||||||
// submitGenericWebhook submits a basic JSON body to an endpoint configured in the config
|
// submitGenericWebhook submits a basic JSON body to an endpoint configured in the config
|
||||||
//
|
//
|
||||||
// The request does not include the log body, only the metadata in the parsedPayload,
|
// The request does not include the log body, only the metadata in the parsedPayload,
|
||||||
// with the required listingURL to obtain the logs over http if required.
|
// with the required listingURL to obtain the logs over http if required.
|
||||||
//
|
//
|
||||||
// If a github or gitlab issue was previously made, the reportURL will also be passed.
|
// If a github or gitlab issue was previously made, the reportURL will also be passed.
|
||||||
|
@ -523,8 +522,8 @@ func (s *submitServer) submitGenericWebhook(p parsedPayload, listingURL string,
|
||||||
}
|
}
|
||||||
genericHookPayload := genericWebhookPayload{
|
genericHookPayload := genericWebhookPayload{
|
||||||
parsedPayload: p,
|
parsedPayload: p,
|
||||||
ReportURL: reportURL,
|
ReportURL: reportURL,
|
||||||
ListingURL: listingURL,
|
ListingURL: listingURL,
|
||||||
}
|
}
|
||||||
for _, url := range s.cfg.GenericWebhookURLs {
|
for _, url := range s.cfg.GenericWebhookURLs {
|
||||||
// Enrich the parsedPayload with a reportURL and listingURL, to convert a single struct
|
// Enrich the parsedPayload with a reportURL and listingURL, to convert a single struct
|
||||||
|
@ -554,7 +553,6 @@ func (s *submitServer) sendGenericWebhook(req *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *submitServer) submitGithubIssue(ctx context.Context, p parsedPayload, listingURL string, resp *submitResponse) error {
|
func (s *submitServer) submitGithubIssue(ctx context.Context, p parsedPayload, listingURL string, resp *submitResponse) error {
|
||||||
if s.ghClient == nil {
|
if s.ghClient == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
Reference in a new issue