The Octane Go library provides programmatic access to the Octane API for Go applications.
First, obtain an API key from within the Octane portal, and set it in your environment:
export OCTANE_API_KEY="<insert_octane_api_key_here>"Then, from within your application, import the module and create a client:
package main
import (
"os"
"github.com/getoctane/octane-go"
)
func main() {
client := octane.NewClient(os.Getenv("OCTANE_API_KEY"))
// ...
}Update your project's go.mod to include the new import, and vendor the dependencies:
go mod tidy && go mod vendorThe following demo applications found in the examples/ directory display how to use the Octane Go library in real-world settings:
- antler-db-cloud-shop - Enable your customers to self-service various cloud resources
- customer-hours-tracker - Track hours spent working on freelance projects
The Client type (returned by octane.NewClient("<token>"))
provides programmatic access to the Octane API.
The Customers namespace on a Client instance provides the ability to
make calls to the Octane Customers API.
customerName := "r2d2"
args := octane.CreateCustomerArgs{
Name: customerName,
MeasurementMappings: []octane.CustomerMeasurementMappingInputArgs{
{
Label: "customer_name",
ValueRegex: customerName,
},
},
}
customer, resp, err := client.Customers.Create(args)customerName := "r2d2"
args := octane.CreateSubscriptionArgs{
PricePlanName: "droidplan",
}
subscription, resp, err := client.Customers.CreateSubscription(customerName, args)The Meters namespace on a Client instance provides the ability to
make calls to the Octane Meters API.
meterName := "droidrepairs"
args := octane.MeterInputArgs{
Name: meterName,
MeterType: "COUNTER",
IsIncremental: true,
ExpectedLabels: []string{"customer_name"},
}
meter, resp, err := client.Meters.Create(args)The PricePlans namespace on a Client instance provides the ability to
make calls to the Octane Price Plans API.
pricePlanName := "droidplan"
pricePlanRate := 10000 // $100.00
meterName := "droidrepairs"
args := octane.CreatePricePlanArgs{
Name: pricePlanName,
Period: "month",
MeteredComponents: []octane.MeteredComponentInputArgs{
{
MeterName: meterName,
PriceScheme: &octane.PriceSchemeInputArgs{
Prices: []octane.PriceInputArgs{
{
Price: float64(pricePlanRate),
},
},
SchemeType: "FLAT",
},
},
},
}
pricePlan, resp, err := client.PricePlans.Create(args)The Measurements namespace on a Client instance provides the ability to
make calls to the Octane Measurements API.
meterName := "droidrepairs"
customerName := "r2d2"
args := octane.Measurement{
MeterName: meterName,
Value: 1,
Labels: map[string]string{
"customer_name": customerName,
},
}
measurement, resp, err := client.Measurements.Create(args)In the root of this repo, download required dependencies:
go mod vendorTo regenerate files in internal/swagger/ from latest
Octane OpenAPI spec, run the following (requires Docker):
make codegenThese files should then be checked into git:
git add internal/swagger/Contributions are welcome!
Prior to submitting a pull request, please check the list of open issues. If there is not an existing issue related to your changes, please open a new issue to first discuss your thoughts with the project maintainers.
