Convert examples/ directory to testable examples for pkg.go.dev integration

Summary

I propose to convert most of the examples from examples/ directory into testable examples. This would automatically display runnable, verified examples on https://pkg.go.dev/gitlab.com/gitlab-org/api/client-go#pkg-examples.

Benefits

  • pkg.go.dev would show collapsible, copy-paste-ready examples
  • go test ./... would run and verify them, catching API changes or breakage.

Example of converting applicationsExample

  1. Add example_application_test.go.
Contents
package gitlab_test

import (
	"log"

	gitlab "gitlab.com/gitlab-org/api/client-go"
)

func ExampleApplicationsService() {
	git, err := gitlab.NewClient("yourtokengoeshere")
	if err != nil {
		log.Fatal(err)
	}

	// Create an application
	opts := &gitlab.CreateApplicationOptions{
		Name:        gitlab.Ptr("Travis"),
		RedirectURI: gitlab.Ptr("http://example.org"),
		Scopes:      gitlab.Ptr("api"),
	}
	created, _, err := git.Applications.CreateApplication(opts)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Last created application : %v", created)

	// List all applications
	applications, _, err := git.Applications.ListApplications(&gitlab.ListApplicationsOptions{})
	if err != nil {
		log.Fatal(err)
	}

	for _, app := range applications {
		log.Printf("Found app : %v", app)
	}

	// Delete an application
	resp, err := git.Applications.DeleteApplication(created.ID)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("Status code response : %d", resp.StatusCode)
}
  1. Remove examples/applications.go
  2. Run pkgsite locally and open http://localhost:8080/gitlab.com/gitlab-org/api/client-go#pkg-examples

image

http://localhost:8080/gitlab.com/gitlab-org/api/client-go#example-ApplicationsService:

Screenshot_2026-01-09_at_13.55.29

Edited Jan 09, 2026 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading