Skip to content

Instantly share code, notes, and snippets.

@yusuke024
Created December 12, 2014 11:30
Show Gist options
  • Save yusuke024/38333a1d68e8f1155ad5 to your computer and use it in GitHub Desktop.
Save yusuke024/38333a1d68e8f1155ad5 to your computer and use it in GitHub Desktop.
Clean Slack Files
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
token := "<your_token_here>"
resp, _ := http.Get("https://slack.com/api/files.list?&token=" + token)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
var data map[string]interface{}
json.Unmarshal(body, &data)
files := data["files"].([]interface{})
for i := range files {
file := files[i].(map[string]interface{})
id := file["id"].(string)
fmt.Println(id)
go func(id string, token string) {
fmt.Println("Deleting", id)
resp, _ = http.Post("https://slack.com/api/files.delete?token="+token+"&file="+id, "application/json", nil)
if resp.StatusCode == http.StatusOK {
fmt.Println("Deleted", id)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
}(id, token)
}
var input string
fmt.Scanln(&input)
fmt.Println("done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment