From 76d93d97da34c3f83dd10d9757e1cb62e92780f0 Mon Sep 17 00:00:00 2001 From: seemywings Date: Sat, 21 Dec 2024 18:58:53 -0500 Subject: [PATCH] update goai --- cmd/http.go | 50 -------------------------------------------------- go.mod | 2 +- go.sum | 2 ++ 3 files changed, 3 insertions(+), 51 deletions(-) diff --git a/cmd/http.go b/cmd/http.go index 5663efc..7df98b7 100644 --- a/cmd/http.go +++ b/cmd/http.go @@ -1,15 +1,11 @@ package cmd import ( - "encoding/json" - "errors" "fmt" "io" - "log" "net/http" "os" "path/filepath" - "strconv" "strings" "time" ) @@ -19,52 +15,6 @@ var httpClient = &http.Client{ Timeout: time.Second * 60, } -func httpMakeRequest(request *http.Request, responseJson interface{}) { - - // Make the HTTP Request - resp, err := httpClient.Do(request) - catchErr(err) - - // Read the JSON Response Body - jsonString, err := io.ReadAll(resp.Body) - catchErr(err) - - // Check for HTTP Errors - httpCatchErr(resp, jsonString) - if verbose { - b, err := io.ReadAll(resp.Body) - if err != nil { - log.Fatalln(err) - } - fmt.Println("🌐 HTTP Response", b) - } - - // Unmarshal the JSON Response Body into provided responseJson - err = json.Unmarshal([]byte(jsonString), &responseJson) - catchErr(err) - if verbose { - trace() - fmt.Println("🌐 HTTP Response String", string(jsonString)) - fmt.Println("🌐 HTTP Response JSON", responseJson) - } - // Close the HTTP Response Body - defer resp.Body.Close() -} - -func httpCatchErr(resp *http.Response, jsonString []byte) { - // Check for HTTP Response Errors - if resp.StatusCode != 200 { - catchErr(errors.New("API Error: " + strconv.Itoa(resp.StatusCode) + "\n" + string(jsonString))) - } -} - -// func httpDumpRequest(r *http.Request) { -// // Dump the HTTP Request -// dump, err := httputil.DumpRequest(r, true) -// catchErr(err) -// fmt.Println("🌐 HTTP Request", string(dump)) -// } - // download file from url and save to local directory func httpDownloadFile(url string, filePath string) string { // Replace spaces with underscores diff --git a/go.mod b/go.mod index c899325..12906d9 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/alecthomas/chroma v0.10.0 github.com/bwmarrin/discordgo v0.28.1 github.com/pterm/pterm v0.12.80 - github.com/seemywingz/goai v0.0.0-20240428060229-cce9aefb4824 + github.com/seemywingz/goai v0.1.0 github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.19.0 ) diff --git a/go.sum b/go.sum index ac7936e..24e6383 100644 --- a/go.sum +++ b/go.sum @@ -95,6 +95,8 @@ github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6g github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= github.com/seemywingz/goai v0.0.0-20240428060229-cce9aefb4824 h1:FZ9AyP936PADg5iW86XCXWqgHxjpxpd23BBS0b+194c= github.com/seemywingz/goai v0.0.0-20240428060229-cce9aefb4824/go.mod h1:mxBUzpw6bdDPvYXX/zAAWqvCDCJOPFvTufwGisOWt+k= +github.com/seemywingz/goai v0.1.0 h1:nkAQpVjEZyTQQJWH+ScfFkdER5JxKFmVUKq/7TMwR/8= +github.com/seemywingz/goai v0.1.0/go.mod h1:mxBUzpw6bdDPvYXX/zAAWqvCDCJOPFvTufwGisOWt+k= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=