Files
fn-serverless/fn/client/api.go
2017-07-05 12:38:09 -07:00

39 lines
792 B
Go

package client
import (
"os"
"log"
"net/url"
fnclient "github.com/funcy/functions_go/client"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
)
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)
}
log.Println("trace: Host:", u.Host)
return u.Host
}
func APIClient() *fnclient.Functions {
transport := httptransport.New(Host(), "/v1", []string{"http"})
if os.Getenv("FN_TOKEN") != "" {
transport.DefaultAuthentication = httptransport.BearerToken(os.Getenv("FN_TOKEN"))
}
// create the API client, with the transport
client := fnclient.New(transport, strfmt.Default)
return client
}