Skip to content

TypeSpec Go QuickStart

JiaqiZhang-Dev edited this page Feb 27, 2025 · 6 revisions

Before you Start

Go Azure SDK Design Guidelines is the overall design guideline of sdk. Make sure you are familiar with concepts such as "ServiceClient" and "Packages".

Make sure you are familiar with Git and Go Packages.

Generate SDK

Module folder in SDK repository

For service, it is usually your service name in REST API specifications. For instance, if the TypeSpec is under specification/storage, the service would normally be storage.

For package, please refer to Azure SDK Module Design in Go Guideline. For example, if the service name is storage, the package should be armstorage or azstorage.(Use arm for management-plane packages, and az for all other packages.)

☑️ Namespace is decided by SDK arch board.

After service and module, the output-dir would be <sdk-repository-dir>/sdk/<service>/<module>. This is where the SDK code should be generated when you call npx tsp compile.

Use SDK Automation from REST API specifications

☑️ It is recommended to configure TypeSpec package on REST API specifications. Please refer to these guidelines.

Particularly, here is a sample for tspconfig.yaml. Please make sure service-dir, package-dir, module (for typespec-go) is correctly configured.

  • "parameters.service-dir.default" would be sdk/<service>
  • "options.@azure-tools/typespec-go.package-dir" would be <package>

After configuration is completed, making a draft pull request on azure-rest-api-specs repository would automatically trigger SDK generation for all configured SDKs. The automation will create new pull request on azure-sdk-for-go repository. One can fork it for further development.

Go specific options for tspconfig.yaml

  • service-dir: Default as sdk/<service>. If your service is a management-plane service, like specification/azurefleet/AzureFleet.Management, the service dir needs to be sdk/resourcemanager/computefleet.
  • package-dir: Default as <package>.
  • module: Default as "github.com/Azure/azure-sdk-for-go/{service-dir}/{package-dir}".
  • generate-examples: Default as true. Generates sample codes with the SDK..
  • generate-fakes: Default as true. Generates test codes with the SDK..
  • fix-const-stuttering: Default as true. Fix stuttering for const types and values.
  • head-as-boolean: Default as true. HEAD requests will return a boolean value based on the HTTP status code.
  • service-name: Used for ARM libraries. It is the name of the service. It will appear in the README.md and other places that refers to the service.

Clone this wiki locally