Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Selyss committed Nov 22, 2023
1 parent 9660205 commit a9f291f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/assembuddy/requestTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,23 @@ type CLIOptions struct {
PrettyPrint bool
}

func fetchData(endpointURL string, prettyp bool) ([]Syscall, error) {
const (
syscallEndpoint = "https://api.syscall.sh/v1/syscalls"
conventionEndpoint = "https://api.syscall.sh/v1/conventions"
)

func fetchData(endpointURL string, prettyPrint bool) ([]Syscall, error) {
response, err := http.Get(endpointURL)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to fetch data: %w", err)
}
defer response.Body.Close()

body, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to read response body: %w", err)
}
if prettyp {
if prettyPrint {

fmt.Println(string(body))
os.Exit(0)
Expand All @@ -49,15 +54,15 @@ func fetchData(endpointURL string, prettyp bool) ([]Syscall, error) {
var systemCalls []Syscall
err = json.Unmarshal(body, &systemCalls)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to unmarshal JSON: %w", err)
}

return systemCalls, nil
}

func GetSyscallData(opts *CLIOptions) ([]Syscall, error) {
arch := opts.Arch
url := "https://api.syscall.sh/v1/syscalls"
url := syscallEndpoint
// if arch is x64, x86, arm, or arm64, concat to endpointURL
if arch == "x64" || arch == "x86" || arch == "arm" || arch == "arm64" {
url += "/" + arch
Expand All @@ -72,6 +77,5 @@ func GetSyscallData(opts *CLIOptions) ([]Syscall, error) {
}

func ArchInfo() ([]Syscall, error) {
url := "https://api.syscall.sh/v1/conventions"
return fetchData(url, true)
return fetchData(conventionEndpoint, true)
}

0 comments on commit a9f291f

Please sign in to comment.