docgen

Guides

Show a constant

Put the value of a constant in a sentence, so that the sentence stays true.

v2/machine/machine.go

const DefaultWait = 250 * time.Millisecond

docs/machines/guide-const.md

Before
The default wait is <!-- docgen:const pkg=machine name=DefaultWait --><!-- /docgen:const -->.
After
The default wait is <!-- docgen:const pkg=machine name=DefaultWait -->`250ms`<!-- /docgen:const -->.
Preview

The default wait is 250ms.

A value prints as Go prints it, so a time.Duration is 250ms, and a type with a String method prints its text.

Use print= to choose another form:

v2/machine/port.go

package machine

import "fmt"

// Port is a network port.
type Port uint16

// String returns the port as text.
func (p Port) String() string { return fmt.Sprintf("port %d", uint16(p)) }

// PortWeb is the port of the web server.
const PortWeb Port = 8080

// Listen is the port of a new Lamp.
var Listen = PortWeb

docs/machines/guide-const-print.md

Before
- Default: <!-- docgen:const pkg=machine name=Listen --><!-- /docgen:const -->
- `go`: <!-- docgen:const pkg=machine name=Listen print=go --><!-- /docgen:const -->
- `raw`: <!-- docgen:const pkg=machine name=Listen print=raw --><!-- /docgen:const -->
- `name`: <!-- docgen:const pkg=machine name=Listen print=name --><!-- /docgen:const -->
- `%06d`: <!-- docgen:const pkg=machine name=Listen print=%06d --><!-- /docgen:const -->
After
- Default: <!-- docgen:const pkg=machine name=Listen -->`port 8080`<!-- /docgen:const -->
- `go`: <!-- docgen:const pkg=machine name=Listen print=go -->`port 8080`<!-- /docgen:const -->
- `raw`: <!-- docgen:const pkg=machine name=Listen print=raw -->`8080`<!-- /docgen:const -->
- `name`: <!-- docgen:const pkg=machine name=Listen print=name -->`PortWeb`<!-- /docgen:const -->
- `%06d`: <!-- docgen:const pkg=machine name=Listen print=%06d -->`008080`<!-- /docgen:const -->
Preview
  • Default: port 8080
  • go: port 8080
  • raw: 8080
  • name: PortWeb
  • %06d: 008080

With code=false, the value has no backticks, such as 250ms.

For all options, see docgen:const.

Source: docs/guides/const.md