generator

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2026 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package generator writes a Go SDK package from a service's definitions, the way Pandora's generator-go-sdk writes go-azure-sdk: it reads nothing but the definitions, and every decision it makes about the API was already made by the importer.

One package per server (BaseItemDto is everywhere, so per-tag packages would all import one another), laid out by tag in file names:

client.go                          Client and New
client_test.go                     the canned server the tests share
doc.go                             the package documentation
<tag>_method_<operation>.go        one per operation: the method, its
                                   <Name>OperationResponse, its
                                   <Name>OperationOptions, and for list
                                   operations a <Name>Complete pager
<tag>_method_<operation>_test.go   the operation's test (tests.go)
<tag>_model_<model>.go             one per model
<tag>_constants.go                 the tag's enums

Requests go through a base client, named in Options.ClientImport: pandorest's own (the client package), which this package's tests build and run a generated package against, or one a repository keeps of its own, with what the README says generated code calls.

Index

Constants

View Source
const Header = "// Code generated by pandorest; DO NOT EDIT.\n"

Header starts every generated file but doc.go; Generated is how to tell a generated file from one written by hand.

Variables

This section is empty.

Functions

func Check

func Check(svc *definitions.Service, dir string) (int, error)

Check verifies that the package in dir has a method on Client for every operation in the definitions (and a Complete method for every list), and returns how many operations it found.

func Generate

func Generate(svc *definitions.Service, opts Options) (int, error)

Generate writes the package and removes generated files it no longer produces. It returns the number of files written.

func Generated

func Generated(src []byte) bool

Generated reports whether src is a file pandorest generated, which is how a stale one is recognised for removal and a hand-written one beside it left alone: every generated file starts with the header but the package's doc.go, which starts by saying pandorest generated it.

func Render

func Render(svc *definitions.Service, opts Options) (map[string][]byte, error)

Render produces every file of the package, formatted, by name.

Types

type Options

type Options struct {
	// Dir is the package directory.
	Dir string
	// Definitions is the definitions directory, named in the package doc.
	Definitions string
	// Version is the version the document's file is named by, which the
	// package declares as DocumentVersion; empty declares none.
	Version string
	// ClientImport is the import path of the base client the package sends
	// its requests through.
	ClientImport string
	// Client, when set, is the source of client.go after its APIVersion
	// constant, in place of the default (see config.Service.Client).
	Client string
	// ClientService, when set, names the client.Service in the package
	// that the default client.go makes its client from.
	ClientService string
	// Credential and NewDoc word the default client.go's New in the
	// service's own way (see config.Service).
	Credential string
	NewDoc     string
	// Notes is a paragraph added to the package documentation.
	Notes string
}

Options says where a service's package goes, where it came from and what it is built on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL