Updated README and cleaned up output

This commit is contained in:
Tom Jowitt 2017-06-04 19:34:13 +10:00
parent edf99b52c0
commit 3d9abde17a
3 changed files with 16 additions and 6 deletions

3
.gitignore vendored
View file

@ -12,3 +12,6 @@
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
# Remove the build binary
slack-cleanup

View file

@ -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

View file

@ -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")
}