Skip to content

Commit

Permalink
update goai
Browse files Browse the repository at this point in the history
  • Loading branch information
seemywingz committed Dec 21, 2024
1 parent 812a5f1 commit 76d93d9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 51 deletions.
50 changes: 0 additions & 50 deletions cmd/http.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package cmd

import (
"encoding/json"
"errors"
"fmt"
"io"
"log"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"time"
)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 76d93d9

Please sign in to comment.