Files
fn-serverless/fn/api.go
Travis Reeder b827135200 Switch to go-swagger for client lib and checks for IRON_TOKEN (#406)
* wip - for review, using go-swagger client and checking for IRON_TOKEN and passing as auth header.

* wip - auth header

* add golang builder

* finish client builder

* change gh username

* fix git command

* update readme and small fixes

* some improvements

* using go-swagger

* fn new client

* revert swagger

* make fn routes and apps work with new client (go-swagger)

* some fixes in fn apps

* update functions_go
2017-01-24 08:08:40 -08:00

38 lines
759 B
Go

package main
import (
"os"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
fnclient "github.com/iron-io/functions_go/client"
"log"
"net/url"
)
func host() string {
apiURL := os.Getenv("API_URL")
if apiURL == "" {
apiURL = "http://localhost:8080"
}
u, err := url.Parse(apiURL)
if err != nil {
log.Fatalln("Couldn't parse API URL:", err)
}
return u.Host
}
func apiClient() *fnclient.Functions {
transport := httptransport.New(host(), "/v1", []string{"http"})
if os.Getenv("IRON_TOKEN") != "" {
transport.DefaultAuthentication = httptransport.BearerToken(os.Getenv("IRON_TOKEN"))
}
// create the API client, with the transport
client := fnclient.New(transport, strfmt.Default)
return client
}