...

Package pkg

import "cmd/go/internal/doc/testdata"
Overview
Index
Examples

Overview ▾

Package comment.

Example

Package example.

Code:

fmt.Println("Package example output")

Output:

Package example output

Example (Multiline)

Multiline example.

Code:

fmt.Println("Multiline\nexample\noutput")

Output:

Multiline
example
output

Example (Playable)

Playable example.

Code:

fmt.Println("Playable example output")

Output:

Playable example output

Constants

Comment about block of constants.

const (
    // Comment before ConstOne.
    ConstOne = 1
    ConstTwo = 2 // Comment on line with ConstTwo.

)

Const block where first entry is unexported.

const (
    ConstFive
    ConstSix
)
const (
    ConstLeft2 uint64
    _, ConstRight3
    ConstLeft4, ConstRight4
)
const (
    ConstGroup1 unexportedType = iota
    ConstGroup2
    ConstGroup3
)

For case matching.

const CaseMatch = 1
const Casematch = 2
const (
    Duplicate = iota
)

Comment about exported constant.

const ExportedConstant = 1

Constants tied to unexportedType.

const (
    ExportedTypedConstant_unexported unexportedType = iota
)
const MultiLineConst = `
    MultiLineString1
    MultiLineString2
    MultiLineString3
`

Variables

Comment about block of variables.

var (
    // Comment before VarOne.
    VarOne = 1
    VarTwo = 2 // Comment on line with VarTwo.

)
var ExportedVarOfUnExported unexportedType

Comment about exported variable.

var ExportedVariable = 1
var LongLine = newLongLine(
    "someArgument1",
    "someArgument2",
    "someArgument3",
    "someArgument4",
    "someArgument5",
    "someArgument6",
    "someArgument7",
    "someArgument8",
)
var MultiLineVar = map[struct {
    MultiLineField1 string
    MultiLineField2 uint64
}]struct {
    MultiLineField3 error
    MultiLineField2 error
}{
    {"FieldVal1", 1}: {},
    {"FieldVal2", 2}: {},
    {"FieldVal3", 3}: {},
}

Var block where first entry is unexported.

var (
    VarFive = 5
)

func ExportedFormattedDoc

func ExportedFormattedDoc(a int) bool

Comment about exported function with formatting.

Example

fmt.Println(FormattedDoc())

Text after pre-formatted block.

func ExportedFunc

func ExportedFunc(a int) bool

Comment about exported function.

Example

Function example.

Code:

fmt.Println("Function example output")

Output:

Function example output

Example (Two)

Function example two.

Code:

fmt.Println("Function example two output")

Output:

Function example two output

func MultiLineFunc

func MultiLineFunc(x interface {
    MultiLineMethod1() int
    MultiLineMethod2() int
    MultiLineMethod3() int
}) (r struct {
    MultiLineField1 int
    MultiLineField2 int
    MultiLineField3 int
})

func ReturnUnexported

func ReturnUnexported() unexportedType

type ExportedComparableInterface

Comment about exported interface with comparable.

type ExportedComparableInterface interface {
    comparable       // Comment on line with comparable.
    ExportedMethod() // Comment on line with exported method.
    // contains filtered or unexported methods
}

type ExportedComparableOnlyInterface

ExportedComparableOnlyInterface has only comparable and exported method (no unexported).

type ExportedComparableOnlyInterface interface {
    comparable       // Comment on line with comparable.
    ExportedMethod() // Comment on line with exported method.
}

type ExportedFormattedType

type ExportedFormattedType struct {
    // Comment before exported field with formatting.
    //
    // Example
    //
    //	a.ExportedField = 123
    //
    // Text after pre-formatted block.
    //ignore:directive
    ExportedField int
}

type ExportedInterface

Comment about exported interface.

type ExportedInterface interface {
    // Comment before exported method.
    //
    //	// Code block showing how to use ExportedMethod
    //	func DoSomething() error {
    //		ExportedMethod()
    //		return nil
    //	}
    //
    ExportedMethod() // Comment on line with exported method.

    io.Reader // Comment on line with embedded Reader.
    error     // Comment on line with embedded error.
    // contains filtered or unexported methods
}

type ExportedStructOneField

type ExportedStructOneField struct {
    OnlyField int // the only field
}

type ExportedType

Comment about exported type.

type ExportedType struct {
    // Comment before exported field.
    ExportedField int // Comment on line with exported field.

    ExportedEmbeddedType            // Comment on line with exported embedded field.
    *ExportedEmbeddedType           // Comment on line with exported embedded *field.
    *qualified.ExportedEmbeddedType // Comment on line with exported embedded *selector.field.

    io.Reader // Comment on line with embedded Reader.
    // contains filtered or unexported fields
}
const ConstGroup4 ExportedType = ExportedType{}

Constants tied to ExportedType. (The type is a struct so this isn't valid Go, but it parses and that's all we need.)

const (
    ExportedTypedConstant ExportedType = iota
)

Example

Type example.

Code:

fmt.Println("Type example output")

Output:

Type example output

func ExportedTypeConstructor

func ExportedTypeConstructor() *ExportedType

Comment about constructor for exported type.

func ReturnExported

func ReturnExported() ExportedType

func (ExportedType) ExportedMethod

func (ExportedType) ExportedMethod(a int) bool

Comment about exported method.

Example

Method example.

Code:

fmt.Println("Method example output")

Output:

Method example output

func (ExportedType) Uncommented

func (ExportedType) Uncommented(a int) bool

type SimpleConstraint

type SimpleConstraint interface {
    ~int | ~float64
}

type StructConstraint

type StructConstraint interface {
    struct{ F int }
}

type T1

type T1 = T2

type T2

type T2 int

type TildeConstraint

type TildeConstraint interface {
    ~int
}

Bugs