commit | 9c1b9014e7850042a69fe6ddc3104b78a0d195bf | [log] [tgz] |
---|---|---|
author | Matt Rutkowski <mrutkows@us.ibm.com> | Tue Feb 23 15:49:57 2021 -0600 |
committer | GitHub <noreply@github.com> | Tue Feb 23 15:49:57 2021 -0600 |
tree | 17c926e8f8eddfd886023d83a2574e345ccefe0a | |
parent | 17d556327cd39cb6d6854667fa75c35ef9f2e6f1 [diff] |
Migrate to Go Modules (#143) * Migrate to Go Modules * Migrate to Go Modules * Migrate to Go Modules * Migrate to Go Modules * Migrate to Go Modules * update README for go mod * Apply sugg. changes from Rodric * Apply sugg. changes from Rodric * Apply sugg. changes from Rodric
This project openwhisk-client-go
is a Go client library to access the Openwhisk API.
The Openwhisk Go Client library requires you to Download and install GoLang onto your local machine.
Note Go version 1.15 or higher is recommended
Make sure you select the package that fits your local environment, and set the GOPATH environment variable.
As the code is managed using GitHub, it is easiest to retrieve the code using the git clone
command.
If you just want to build the code and do not intend to be a Contributor, you can clone the latest code from the Apache repository:
git clone git@github.com:apache/openwhisk-client-go
You can also specify a release (tag), if you do not want the latest code, by using the --branch <tag>
flag. For example, you can clone the source code for the tagged 1.1.0 release
git clone --branch 1.1.0 git@github.com:apache/openwhisk-client-go
You can also pull the code from a fork of the repository. If you intend to become a Contributor to the project, read the section Contributing to the project below on how to setup a fork.
go build
Change into the cloned project directory and use the following command to build all packages:
$ go build -v ./...
or simply build just the whisk commands:
$ go build -v ./whisk
Note: There is no
main
function in this project as the./whish
packages are treated together as a client library.
go test
Open a terminal, change into the project directory and use the following command to run the unit tests:
$ go test -v ./... -tags=unit
You should see all the unit tests passed; if not, please log an issue for us.
This Go client library is used to access the OpenWhisk API, so please make sure you have an OpenWhisk service running somewhere available for you to run this library.
We use a configuration file called wskprop to specify all the parameters necessary for this Go client library to access the OpenWhisk services. Make sure you create or edit the file ~/.wskprops, and add the mandatory parameters APIHOST, APIVERSION, NAMESPACE and AUTH.
APIHOST
is the OpenWhisk API hostname (for example, openwhisk.ng.bluemix.net, 172.17.0.1, and so on).APIVERSION
is the version of OpenWhisk API to be used to access the OpenWhisk resources.NAMESPACE
is the OpenWhisk namespace used to specify the OpenWhisk resources about to be accessed.AUTH
is the authentication key used to authenticate the incoming requests to the OpenWhisk services.For more information regarding the REST API of OpenWhisk, please refer to OpenWhisk REST API.
import "github.com/apache/openwhisk-client-go/whisk"
Construct a new whisk client, then use various services to access different parts of the whisk api. For example to get the hello
action:
client, _ := whisk.NewClient(http.DefaultClient, nil)
action, resp, err := client.Actions.List("hello")
Some API methods have optional parameters that can be passed. For example, to list the first 30 actions, after the 30th action:
client, _ := whisk.NewClient(http.DefaultClient, nil)
options := &whisk.ActionListOptions{
Limit: 30,
Skip: 30,
}
actions, resp, err := client.Actions.List(options)
By default, this Go client library is automatically configured by the configuration file wskprop. The parameters of APIHOST, APIVERSION, NAMESPACE and AUTH will be used to access the OpenWhisk services.
In addition, it can also be configured by passing in a *whisk.Config
object as the second argument to whisk.New( ... )
. For example:
config := &whisk.Config{
Host: "openwhisk.ng.bluemix.net",
Version: "v1"
Namespace: "_",
AuthKey: "aaaaa-bbbbb-ccccc-ddddd-eeeee"
}
client, err := whisk.Newclient(http.DefaultClient, config)
You need to have an OpenWhisk service accessible, to run the following example.
import (
"net/http"
"net/url"
"github.com/apache/openwhisk-client-go/whisk"
)
func main() {
client, err := whisk.NewClient(http.DefaultClient, nil)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
options := &whisk.ActionListOptions{
Limit: 30,
Skip: 30,
}
actions, resp, err := client.Actions.List(options)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
fmt.Println("Returned with status: ", resp.Status)
fmt.Println("Returned actions: \n%+v", actions)
}
Then build it with the go tool:
$ go build
If the openWhisk service is available and your configuration is correct, you should receive the status and the actions with the above example.