mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
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
This commit is contained in:
37
fn/api.go
Normal file
37
fn/api.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user