<commit_before>package main

import (
	"fmt"
	"./twitch"
	"net/http"
	"io/ioutil"
	"os"
	"encoding/json"
	"log"
)

func main() {
	// clientID := os.Getenv("CLIENT_ID")
	fmt.Println("Booting the server...")

	// Configure a sample route
	http.HandleFunc("/users", myTwitchHandler)
	http.HandleFunc("/channel", myChannelHandler)
	http.HandleFunc("/streams", myStreamHandler)


	// Run your server
	http.ListenAndServe(":8080", nil)
}

func myTwitchHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("Recieved the following request:", r.Body)
	clientID := os.Getenv("CLIENT_ID")
	twitch.DoSomething()

	// YOUR ROUTES LOGIC GOES HERE
	//
	// Feel free to structure your routing however you see fit, this is just an example to get you started.

	client := &http.Client{}

	// resp, err := client.Get("https://api.twitch.tv/kraken/users?login=dallas,dallasnchains")
	
	request, err := http.NewRequest("GET", "https://api.twitch.tv/kraken/users?login=dallas,dallasnchains", nil)
	if err != nil {
		fmt.Println(err.Error())
	 	os.Exit(1)
	} 
	request.Header.Set("Client-ID", clientID)
	request.Header.Set("Accept", "application/vnd.twitchtv.v5+json")

	resp, err := client.Do(request)
        
    responseData, err := ioutil.ReadAll(resp.Body)
    if err != nil {
		log.Fatal(err)
	}
    fmt.Fprintf(w, string(responseData))
    
    var responseObject GetUsersAPIResponse
	json.Unmarshal(responseData, &responseObject)

    fmt.Println(responseObject.TotalUsers)
  	fmt.Println(responseObject.UserList[0].Id)
  	user_id := responseObject.UserList[0].Id

  	fmt.Println("Making Second Request")
  	request, err = http.NewRequest("GET", "https://api.twitch.tv/kraken/channels/" + user_id, nil)
	if err != nil {
		fmt.Println(err.Error())
	 	os.Exit(1)
	} 
	request.Header.Set("Client-ID", clientID)
	request.Header.Set("Accept", "application/vnd.twitchtv.v5+json")

	client = &http.Client{}
	resp, err = client.Do(request)
        
    responseData2, err := ioutil.ReadAll(resp.Body)
    if err != nil {
		log.Fatal(err)
	}
    fmt.Fprintf(w, string(responseData2))
}


func myChannelHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("Recieved the following request:", r.Body)
	clientID := os.Getenv("CLIENT_ID")
	// YOUR ROUTES LOGIC GOES HERE
	//
	// Feel free to structure your routing however you see fit, this is just an example to get you started.

	client := &http.Client{}

	// resp, err := client.Get("https://api.twitch.tv/kraken/users?login=dallas,dallasnchains")
	
	request, err := http.NewRequest("GET", "https://api.twitch.tv/kraken/channels/44322889", nil)
	if err != nil {
		fmt.Println(err.Error())
	 	os.Exit(1)
	} 
	request.Header.Set("Client-ID", clientID)
	request.Header.Set("Accept", "application/vnd.twitchtv.v5+json")

	resp, err := client.Do(request)
        
    responseData, err := ioutil.ReadAll(resp.Body)
    if err != nil {
		log.Fatal(err)
	}
    fmt.Fprintf(w, string(responseData))
}

func myStreamHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("Recieved the following request:", r.Body)
	clientID := os.Getenv("CLIENT_ID")
	// YOUR ROUTES LOGIC GOES HERE
	//
	// Feel free to structure your routing however you see fit, this is just an example to get you started.

	client := &http.Client{}

	// resp, err := client.Get("https://api.twitch.tv/kraken/users?login=dallas,dallasnchains")
	
	request, err := http.NewRequest("GET", "https://api.twitch.tv/kraken/streams/44322889", nil)
	if err != nil {
		fmt.Println(err.Error())
	 	os.Exit(1)
	} 
	request.Header.Set("Client-ID", clientID)
	request.Header.Set("Accept", "application/vnd.twitchtv.v5+json")

	resp, err := client.Do(request)
        
    responseData, err := ioutil.ReadAll(resp.Body)
    if err != nil {
		log.Fatal(err)
	}
    fmt.Fprintf(w, string(responseData))

}

type GetUsersAPIResponse struct {
	TotalUsers int `json:"_total"`
	UserList []Users `json:"users"`<commit_msg>Pulling URL form request object<commit_after>package main

import (
	"fmt"
	"./twitch"
	"net/http"
	// "path"
	"io/ioutil"
	"os"
	"encoding/json"
	"log"
)

func main() {
	// clientID := os.Getenv("CLIENT_ID")
	fmt.Println("Booting the server...")

	// Configure a sample route
	http.HandleFunc("/users", myTwitchHandler)

	// Run your server
	http.ListenAndServe(":8080", nil)
}

func myTwitchHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println("Recieved the following request:", r.Body)
	clientID := os.Getenv("CLIENT_ID")
	twitch.DoSomething()
	fmt.Println(r.URL)
	// fmt.Println(path.Base(r))

	// YOUR ROUTES LOGIC GOES HERE
	//
	// Feel free to structure your routing however you see fit, this is just an example to get you started.

	client := &http.Client{}

	// resp, err := client.Get("https://api.twitch.tv/kraken/users?login=dallas,dallasnchains")
	
	request, err := http.NewRequest("GET", "https://api.twitch.tv/kraken/users?login=dallas", nil)
	if err != nil {
		fmt.Println(err.Error())
	 	os.Exit(1)
	} 
	request.Header.Set("Client-ID", clientID)
	request.Header.Set("Accept", "application/vnd.twitchtv.v5+json")

	resp, err := client.Do(request)
        
    responseData, err := ioutil.ReadAll(resp.Body)
    if err != nil {
		log.Fatal(err)
	}
    fmt.Fprintf(w, string(responseData))
    
    var responseObject GetUsersAPIResponse
	json.Unmarshal(responseData, &responseObject)

    fmt.Println(responseObject.TotalUsers)
  	fmt.Println(responseObject.UserList[0].Id)
  	user_id := responseObject.UserList[0].Id

  	fmt.Println("Making Second Request")
  	request, err = http.NewRequest("GET", "https://api.twitch.tv/kraken/channels/" + user_id, nil)
	if err != nil {
		fmt.Println(err.Error())
	 	os.Exit(1)
	} 
	request.Header.Set("Client-ID", clientID)
	request.Header.Set("Accept", "application/vnd.twitchtv.v5+json")

	client = &http.Client{}
	resp, err = client.Do(request)
        
    responseData2, err := ioutil.ReadAll(resp.Body)
    if err != nil {
		log.Fatal(err)
	}
    fmt.Fprintf(w, string(responseData2))

    fmt.Println("Making Third Request")
    
    client = &http.Client{}
	request, err = http.NewRequest("GET", "https://api.twitch.tv/kraken/streams/" + user_id, nil)
	if err != nil {
		fmt.Println(err.Error())
	 	os.Exit(1)
	} 
	request.Header.Set("Client-ID", clientID)
	request.Header.Set("Accept", "application/vnd.twitchtv.v5+json")

	resp, err = client.Do(request)
        
    responseData3, err := ioutil.ReadAll(resp.Body)
    if err != nil {
		log.Fatal(err)
	}
	fmt.Println(responseData3)
	fmt.Fprintf(w, "Stream Status")
    fmt.Fprintf(w, string(responseData3))
}

type GetUsersAPIResponse struct {
	TotalUsers int `json:"_total"`
	UserList []Users `json:"users"`
{'fraction_non_alphanumeric': 0.15939193257074052, 'fraction_numerical': 0.007375075255869958, 'mean_word_length': 3.886029411764706, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 11, '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': '990760', 'n_tokens_mistral': 2503, 'n_tokens_neox': 2401, 'n_words': 472}