Skip to content

Commit

Permalink
refactor requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Selyss committed Nov 19, 2023
1 parent 3c4624d commit a65ba18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ func main() {
fmt.Println("Searching for Syscall: ", opts.Syscall)
}
if opts.Arch != "" {
err, table := assembuddy.GetFromArchitecture(opts.Syscall)
err, table := assembuddy.GetArchData(opts.Arch)
if err != nil {
log.Fatalf("Error: %s", err)
log.Fatal(err)
}
fmt.Println(table)
}
}
18 changes: 13 additions & 5 deletions pkg/assembuddy/requestTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package assembuddy

import (
"encoding/json"
"errors"
"io"
"net/http"
)

type SystemCall struct {
type Syscall struct {
Arch string `json:"arch"`
Name string `json:"name"`
ReturnValue string `json:"return"`
Expand All @@ -19,7 +20,7 @@ type SystemCall struct {
Nr int `json:"nr"`
}

func fetchData(endpointURL string) ([]SystemCall, error) {
func fetchData(endpointURL string) ([]Syscall, error) {
response, err := http.Get(endpointURL)
if err != nil {
return nil, err
Expand All @@ -31,7 +32,7 @@ func fetchData(endpointURL string) ([]SystemCall, error) {
return nil, err
}

var systemCalls []SystemCall
var systemCalls []Syscall
err = json.Unmarshal(body, &systemCalls)
if err != nil {
return nil, err
Expand All @@ -40,6 +41,13 @@ func fetchData(endpointURL string) ([]SystemCall, error) {
return systemCalls, nil
}

func GetFromArchitecture(arch string) ([]string, error) {
return nil, nil
func GetArchData(arch string) ([]Syscall, error) {
url := "https://api.syscall.sh/v1/syscalls/"
// if arch is x64, x86, arm, or arm64, concat to endpointURL
if arch == "x64" || arch == "x86" || arch == "arm" || arch == "arm64" {
url += arch
} else {
return nil, errors.New("invalid architecture")
}
return fetchData(url)
}

0 comments on commit a65ba18

Please sign in to comment.