constforms

package
v0.36.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package constforms exercises the const shapes a `swagger:enum` member can take beyond a plain literal — the shapes that are invisible to a reader working on literal syntax alone, and which the go-swagger#3412 investigation surfaced one after the other:

  • `iota`, where only the first spec of the block carries a type and a value at all and every following spec inherits both implicitly;
  • constant expressions and references to earlier members (`1 << 3`, `LevelLow * 2`);
  • rune literals, whose constant is an integer (`'a'` is 97, not the three characters `'a'`);
  • `true` / `false`, which are predeclared identifiers rather than literals — Go has no boolean literal token;
  • raw and escaped strings, whose delimiters and escape sequences are part of the syntax, not of the value.

Values come from the type-checker, which has already evaluated every one of these exactly.

Index

Constants

View Source
const ForeignDay foreign.Weekday = 13

ForeignDay is declared HERE but typed with an imported type that happens to be called Weekday too. Membership is decided by type identity, not by name, so it is not a member of the enum above.

Variables

This section is empty.

Functions

This section is empty.

Types

type Byte

type Byte byte

Byte is a byte enum, whose members are written as rune literals.

swagger:enum Byte

const (
	ByteNUL Byte = 0
	ByteX   Byte = 'x'
)

type Label

type Label string

Label is a string enum in the raw and escaped literal forms.

swagger:enum Label

const (
	LabelRaw     Label = `raw`
	LabelEscaped Label = "a\tb"
)

type Letter

type Letter rune

Letter is a rune enum.

swagger:enum Letter

const (
	LetterA   Letter = 'a'
	LetterTab Letter = '\t'
)

type Level

type Level int

Level is built from a constant expression and a reference to an earlier member.

swagger:enum Level

const (
	LevelLow  Level = 1 << 3
	LevelHigh Level = LevelLow * 2
)

type Settings

type Settings struct {
	// The day of the week.
	Weekday Weekday `json:"weekday"`

	// The level.
	Level Level `json:"level"`

	// The letter.
	Letter Letter `json:"letter"`

	// The toggle.
	Toggle Toggle `json:"toggle"`

	// The label.
	Label Label `json:"label"`

	// The byte.
	Byte Byte `json:"byte"`
}

Settings carries one property per const form.

swagger:model Settings

type Toggle

type Toggle bool

Toggle is a bool enum.

swagger:enum Toggle

const (
	ToggleOn  Toggle = true
	ToggleOff Toggle = false
)

type Weekday

type Weekday int

Weekday is an iota enum.

swagger:enum Weekday

const (
	Sunday Weekday = iota
	Monday
	Tuesday
)

Directories

Path Synopsis
Package foreign declares a type sharing its name with an enum type of the parent package, so the membership test cannot be name-only.
Package foreign declares a type sharing its name with an enum type of the parent package, so the membership test cannot be name-only.

Jump to

Keyboard shortcuts

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