Skip to content

pitwch/go-also-cloud-wrapper

Repository files navigation

GitHub release CI Release Go Report Card GoDoc codecov GitHub license

ALSO Cloud Marketplace API Golang Wrapper

Golang Wrapper for ALSO Cloud Marketplace API

alt text

Swagger Specs for ALSO Cloud Marketplace Simple API are here: https://app.swaggerhub.com/apis/MarketplaceSimpleAPI/MarketplaceSimpleAPI/1.0.0

Installation

$ go get github.com/pitwch/go-also-cloud-wrapper/alsocloud

Configuration

Configuration Examples Type Note
Marketplace https://marketplace.also.ch string URL Marketplace (Country specific)
apiUser demo@example.com string Username for Cloud Marketplace
apiPassword 1234 string Password for Cloud Marketplace
options &also.Options{Timeout: 30} *also.Options Options (see Chapter Options)

Example:

import (
  also "github.com/pitwch/go-also-cloud-wrapper/alsocloud"
)

var alsocloud, err = also.NewClient(
	"https://marketplace.also.ch",
	"demo@example.com",
	"1234",
	&also.Options{Log: true, Timeout: 30},
)

Options

Options are optional:

Option Example Note
APIPrefix /SimpleAPI/SimpleAPIService.svc/rest API - Prefix; Default = /SimpleAPI/SimpleAPIService.svc/rest
LoginEndpoint GetSessionToken Endpoint for Login; Default = GetSessionToken
UserAgent go-also-cloud-wrapper User Agent; Default = go-also-cloud-wrapper
Timeout 15 Timeout in seconds
VerifySSL true Check if SSL is valid
Log true Activates Log Output; Default = false
Client urlfetch.Client(ctx) 1 HTTP-Client; Default = http.DefaultClient

1: urlfetch is used for Google App Engine Standard Instances but can be replaced by any HTTP-Client

Methods

The wrapper supports all HTTP methods for interacting with the ALSO Cloud Marketplace API:

Available Methods:

  • Post(ctx, endpoint, data) - POST requests (creating resources)
  • Get(ctx, endpoint, params) - GET requests (fetching data with query parameters)
  • Put(ctx, endpoint, data) - PUT requests (updating resources)
  • Patch(ctx, endpoint, data) - PATCH requests (partial updates)
  • Delete(ctx, endpoint, data) - DELETE requests (removing resources)

Parameters:

Parameter Type Note
ctx context.Context Context for request cancellation and deadlines
endpoint string Endpoint ALSO Cloud Marketplace; f.ex. GetCompany, GetUser...
data interface{} Data (automatic conversion to JSON)
params url.Values URL query parameters (for GET requests)

Full Example

Get Company

import (
  also "github.com/pitwch/go-also-cloud-wrapper/alsocloud"
)

//Create client
var alsocloud, err = also.NewClient(
	alsocloud.Switzerland,			//Using predefined Constant Switzerland.  
	"demo@example.com",			//Plain URL would be possible "https://marketplace.also.ch"
	"1234",
	&also.Options{Log: true, Timeout: 30},
)

//Create context
ctx := context.Background()

//Query
res, _, _, err := alsocloud.Post(ctx, "GetCompany", nil)

	buf := new(bytes.Buffer)
	buf.ReadFrom(res)
	resp := buf.String()
	fmt.Printf(resp, err)
	defer res.Close()
	
	//returns {"ParentAccountId": 1234,"AccountId": 1234,"AccountState": "Active","CompanyName": "Demo"...

Testing

The tests require valid ALSO Cloud credentials to run. Set the following environment variables:

Local Testing:

# Windows (PowerShell)
$env:ALSO_CLOUDUSER="your-username@example.com"
$env:ALSO_CLOUDPW="your-password"
go test ./...

# Linux/macOS
export ALSO_CLOUDUSER="your-username@example.com"
export ALSO_CLOUDPW="your-password"
go test ./...

GitHub Actions:

For CI/CD pipelines, store credentials as GitHub Secrets:

  1. Navigate to SettingsSecrets and variablesActions
  2. Add two repository secrets:
    • ALSO_CLOUDUSER: Your ALSO Cloud username
    • ALSO_CLOUDPW: Your ALSO Cloud password

The GitHub workflow will automatically use these secrets as environment variables during test execution.


For a full list of options check GoDoc.