commit 19957a5adcd5436bd73ae1cf07098a952ffe8b01
parent 41a98cfe6012afc3bb02a027bdf04c8a9fa422ad
Author: Juan Roig <jaroig@outlook.com>
Date: Mon, 30 Oct 2023 01:00:50 -0400
switch to using http client instead of invoking static methods
Diffstat:
| M | main.go | | | 28 | ++++++++++++++++++---------- |
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/main.go b/main.go
@@ -7,8 +7,8 @@ import (
"net/http"
)
-func get_courses(token string, link string) []CanvasCourse {
- resp, err := http.Get(link)
+func get_courses(token string, link string, client http.Client) []CanvasCourse {
+ resp, err := client.Get(link)
if err != nil {
// handle error
}
@@ -25,8 +25,8 @@ func get_courses(token string, link string) []CanvasCourse {
return canvas_courses
}
-func get_aplus(token string, link string) string {
- resp, err := http.Get(link)
+func get_aplus(token string, link string, client http.Client) string {
+ resp, err := client.Get(link)
if err != nil {
// handle error
@@ -49,25 +49,31 @@ func get_course_ids(canvas_courses []CanvasCourse) []uint64 {
}
func main() {
+ client := http.Client{
+ CheckRedirect: func(req *http.Request, via []*http.Request) error {
+ fmt.Println("Redirected to:", req.URL)
+ return nil
+ },
+ }
// https://canvas.instructure.com/api/v1/courses?access_token={}&per_page=100", canvas_token
base_link := "https://floridapolytechnic.instructure.com/api/v1"
- token := "instructure api key"
+ token := "insert api key here"
//favorites := fmt.Sprintf("%s/users/self/favorites/courses?access_token=%s&per_page=100", base_link, token)
//all_courses := fmt.Sprintf("%s/courses?access_token=%s&per_page=100", base_link,token)
//var canvas_courses []CanvasCourse
- //canvas_courses = get_courses(token, favorites)
+ //canvas_courses = get_courses(token, favorites, client)
//var course_ids []uint64
//course_ids = get_course_ids(canvas_courses)
//selected := 1 // course_ids[selected]
aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, 7329, token) // 7329 always works
var aplus string
- aplus = get_aplus(token, aplus_link)
+ aplus = get_aplus(token, aplus_link, client)
fmt.Println(aplus)
- resp, err := http.Get(aplus)
+ resp, err := client.Get(aplus)
if err != nil {
// handle error
@@ -76,7 +82,9 @@ func main() {
//fmt.Println(resp)
defer resp.Body.Close()
- body, err := io.ReadAll(resp.Body)
+ //body, err := io.ReadAll(resp.Body)
+
+ //fmt.Println(string(body))
+ //fmt.Println(resp)
- fmt.Println(string(body))
}