Skip to content

Commit

Permalink
updated readme, added proxyURL return value to CreateAPI GoFireProx r…
Browse files Browse the repository at this point in the history
…eceiver method
  • Loading branch information
mr-pmillz committed May 10, 2023
1 parent 0797d57 commit f39916d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,50 @@

This is a port of FireProx to Golang

## Installation

```shell
go install -v github.com/mr-pmillz/gofireprox/cmd/gofireprox@latest
```

## gofireprox as library

Integrate gofireprox with other go programs

```go
package main

import (
"github.com/mr-pmillz/gofireprox"
)

func main() {
// <snippet> generate random region psuedo code </snippet>
region := generateRandomRegion()
fpClient, err := gofireprox.NewFireProx(&gofireprox.FireProxOptions{
AccessKey: "CHANGEME",
SecretAccessKey: "CHANGEME",
SessionToken: "",
Region: region,
Command: "create",
APIID: "",
URL: "https://ifconfig.me",
})
if err != nil {
panic(err)
}
APIID, proxyURL, err := fpClient.CreateAPI()
if err != nil {
panic(err)
}
// use the proxyURL for your requests as you would normally with an http.Client. See FireProx Docs for headers etc. X-My-X-Forwarded-For: etc...
// DoWork...
// Delete API
fpClient.DeleteAPI(APIID)
}

```

## Credits ##

- Mike Felch ([ustayready](https://twitter.com/ustayready)) - [FireProx](https://github.com/ustayready/fireprox)
2 changes: 1 addition & 1 deletion cmd/gofireprox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func main() {
}
fmt.Printf("Deleting %s => %s\n", fp.Options.APIID, success)
case "create":
if _, err = fp.CreateAPI(); err != nil {
if _, _, err = fp.CreateAPI(); err != nil {
log.Fatal(err)
}
case "update":
Expand Down
12 changes: 6 additions & 6 deletions gofireprox.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,30 +311,30 @@ func (fp *FireProx) DeleteAPI(apiID string) bool {
}

// CreateAPI ...
func (fp *FireProx) CreateAPI() (string, error) {
func (fp *FireProx) CreateAPI() (string, string, error) {
fmt.Printf("Creating => %s...\n", fp.Options.URL)
tmplInfo, err := fp.newTemplateInfo()
if err != nil {
return "", err
return "", "", err
}

irAPI, err := fp.getTemplate(tmplInfo)
if err != nil {
return "", err
return "", "", err
}
resp, err := fp.Client.ImportRestApi(context.TODO(), irAPI)
if err != nil {
return "", err
return "", "", err
}

_, proxyURL, err := fp.createDeployment(resp.Id)
if err != nil {
return "", err
return "", "", err
}
// apiID string, name string, createdAT string, targetURL string, proxyURL string
fp.storeAPI(aws.ToString(resp.Id), tmplInfo.Title, resp.CreatedDate.String(), fp.Options.URL, proxyURL)

return aws.ToString(resp.Id), nil
return aws.ToString(resp.Id), proxyURL, nil
}

// UpdateAPI ...
Expand Down

0 comments on commit f39916d

Please sign in to comment.