Skip to content

REST & gRPC client to talk to the Wharf API, written in Go

License

Notifications You must be signed in to change notification settings

iver-wharf/wharf-api-client-go

Repository files navigation

Go-lang RPC client for Wharf

Codacy Badge Go Reference

A library to talk to Wharf via Wharf's main API written in Go.

Uses net/http to send HTTP requests and encoding/json to serialize/deserialize each message back and forth.

This project is for example used inside the providers to create projects into the database when importing from GitLab, GitHub, or Azure DevOps.

Compatibility

wharf-api-client-go wharf-api
v1 v0, v1, v2, v3, v4, and v51
v2 v5, and beyond

1: The PUT endpoints /api/project, /api/token, and /api/provider were removed in wharf-api v5.0.0.

Usage

$ go get github.com/iver-wharf/wharf-api-client-go/v2/pkg/wharfapi
package main

import (
	"fmt"
	"github.com/iver-wharf/wharf-api-client-go/v2/pkg/wharfapi"
)

func main() {
	client := wharfapi.Client{
		APIURL:     "https://example.wharf.com",
		AuthHeader: "Bearer some-auth-token",
	}

	project,err := client.GetProjectByID(125)

	if err != nil {
		fmt.Printf("Unable to find project\n")
	} else {
		fmt.Printf("Project #%d: %s\n", project.ProjectID, project.Name)
	}
}

Sample output

GET | PROJECT | 125
Project #125: MyProject

Linting

make deps # download linting dependencies

make lint

make lint-go # only lint Go code
make lint-md # only lint Markdown files

Some errors can be fixed automatically. Keep in mind that this updates the files in place.

make lint-fix

make lint-fix-go # only lint and fix Go files
make lint-fix-md # only lint and fix Markdown files

Maintained by Iver. Licensed under the MIT license.