<commit_before>package main

import (
    "fmt"
    "github.com/gorilla/mux"
    "launchpad.net/goamz/aws"
    "launchpad.net/goamz/s3"
    "net/http"
    "os"
)

func main() {
    r := mux.NewRouter()
    r.HandleFunc("/", rootHandler)
    r.HandleFunc("/bucket-list/{bucket}/{prefix}", bucketListHandler)
    http.Handle("/", r)
    err := http.ListenAndServe(":"+os.Getenv("PORT"), nil)
    if err != nil {
        panic(err)
    }
}

func rootHandler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Welcome to Go Cloud Gallery")
}

func bucketListHandler(w http.ResponseWriter, r *http.Request) {
    vars := mux.Vars(r)
    bucketName := vars["bucket"]
    prefix := vars["prefix"]
  
    auth := aws.Auth{
        AccessKey: os.Getenv("S3_KEY"),
        SecretKey: os.Getenv("S3_SECRET"),
    }
    useast := aws.USEast

    connection := s3.New(auth, useast)
    bucket := connection.Bucket(bucketName)
    res, err := bucket.List(prefix, "", "", 1000)
    if err != nil {
        panic(err)
    }
    for _, v := range res.Contents {
        fmt.Fprint(w, bucket.URL(v.Key) + "\n")
    }
}<commit_msg>Added region env var and JSON response<commit_after>package main

import (
    "encoding/json"
    "fmt"
    "github.com/gorilla/mux"
    "launchpad.net/goamz/aws"
    "launchpad.net/goamz/s3"
    "net/http"
    "os"
)

func main() {
    r := mux.NewRouter()
    r.HandleFunc("/", rootHandler)
    r.HandleFunc("/bucket-list/{bucket}/{prefix}", bucketListHandler)
    http.Handle("/", r)

    err := http.ListenAndServe(":" + os.Getenv("PORT"), nil)
    
    if err != nil {
        panic(err)
    }
}

func rootHandler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Welcome to Go Cloud Gallery")
}

func bucketListHandler(w http.ResponseWriter, r *http.Request) {
    urlMap := make(map[string]string)
    vars := mux.Vars(r)
    bucketName := vars["bucket"]
    prefix := vars["prefix"]
  
    auth := aws.Auth{
        AccessKey: os.Getenv("S3_KEY"),
        SecretKey: os.Getenv("S3_SECRET"),
    }
    region := aws.Regions[os.Getenv("S3_REGION")]

    connection := s3.New(auth, region)
    bucket := connection.Bucket(bucketName)
    res, err := bucket.List(prefix, "", "", 1000)
    if err != nil {
        panic(err)
    }
    for _, v := range res.Contents {
        urlMap[v.Key] = bucket.URL(v.Key)
    }
    urlJson, err := json.Marshal(urlMap)
    
    w.Header().Set("Content-Type", "application/json")
    w.Write(urlJson)
}
{'fraction_non_alphanumeric': 0.1704361873990307, 'fraction_numerical': 0.006865912762520194, 'mean_word_length': 2.73604826546003, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3175080', 'n_tokens_mistral': 900, 'n_tokens_neox': 884, 'n_words': 167}