An HTTP client to interact with the SonarQube API from Go. It uses a service structure similar to that of go-github.
Most code is generated by the code in sonarqube-gen
, using webservices.json
as source of truth for the API endpoints. This is one of the first iterations of generating the API. It only supports
JSON return types and skips some endpoints that need special handling of the return values.
See https://pkg.go.dev/github.com/shijl0925/go-sonarqube/sonarqube for supported endpoints.
go get github.com/shijl0925/go-sonarqube
Use sonarqube.NewClient
to create a new client. It needs a SonarQube baseUrl and username / password or token, and optionally accepts
an existing *http.Client
.
After creating the client, create a new request from one of the endpoint-specific packages, i.e.
projects.SearchRequest
from github.com/shijl0925/go-sonarqube/sonarqube/projects
. If an endpoint supports paging,
you need to supply ppaging.Params
as well, though in that case it might be easier to use the All
variant of the
function. The example below, for instance, uses client.Projects.SearchAll(req)
instead of client.Projects.Search(req, paging)
.
The page size for automatic paging is currently set to 100
, but might be configurable later.
package main
import (
"context"
"fmt"
"log"
)
func main() {
ctx := context.Background()
baseUrl := "https://next.sonarqube.com/sonarqube"
client := sonarqube.NewClient(baseUrl, "", "", nil)
req := projects.SearchRequest{}
res, err := client.Projects.SearchAll(ctx, req)
if err != nil {
log.Fatalf("could not search projects: %+v", err)
}
fmt.Printf("%+v\n", res)
}