From 3d9abde17af706d4749d5b1bbba3d923eb4283fb Mon Sep 17 00:00:00 2001 From: Tom Jowitt Date: Sun, 4 Jun 2017 19:34:13 +1000 Subject: [PATCH] Updated README and cleaned up output --- .gitignore | 3 +++ README.md | 10 +++++++--- main.go | 9 ++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index a1338d6..a5d9c8c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 .glide/ + +# Remove the build binary +slack-cleanup diff --git a/README.md b/README.md index c6da9cc..d678f6d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,11 @@ A program for cleaning up slack files to free up space. ## Setup -You will need to generate an API token that has permission to delete files. If you do not have administrator -privileges you will only be able to delete your own files. Generate an API token at the following link: +Install Slack Cleanup -[Legacy Tokens](https://api.slack.com/custom-integrations/legacy-tokens) + go get github.com/madecomfy/slack-cleanup + +You will need to generate an API token that has permission to delete files. Add this token to your environment +variables (we use Direnv to manage env vars). + + export SLACK_API_TOKEN=xoxp-111111-1111111-1111111-1111111-111111 diff --git a/main.go b/main.go index e658d05..ab3f9d4 100644 --- a/main.go +++ b/main.go @@ -10,12 +10,12 @@ import ( "time" ) -// Files contains the list of files we want to clean +// Files contains the list of files we want to delete type Files struct { FileList []File `json:"files"` } -// File is an individual file we wish to remove from Slack +// File is an individual file we wish to delete from Slack type File struct { ID string `json:"id"` } @@ -52,6 +52,7 @@ func main() { log.Fatal(err) } + count := 0 for _, file := range files.FileList { req, err := http.NewRequest("GET", "https://slack.com/api/files.delete", nil) if err != nil { @@ -66,7 +67,7 @@ func main() { httpClient := &http.Client{} resp, err := httpClient.Do(req) if err != nil { - log.Fatal(err) + log.Println(err) } _, err = ioutil.ReadAll(resp.Body) if err != nil { @@ -74,6 +75,8 @@ func main() { } fmt.Println("File", file.ID, "successfully deleted") + count++ } + fmt.Println("Fin.", count, "files successfully deleted") }