Go Doc unexpectedly indents/groups functions. What causes this?

WBOY
Release: 2024-02-05 22:24:11
forward
590 people have browsed it

Go Doc 意外地缩进/分组函数。是什么原因造成的?

Question content

go doc is indenting/creating a group without me telling it on purpose.

Here is a screenshot of my browser showing the issue. The four parse functions should not be indented:

What causes this behavior?

I tried searching the go docs for indentation/sections/grouping but I didn't find anything except feature requests. I'm sure the answer to my question is somewhere in the documentation, but I can't find it because I don't have the right vocabulary.

I'm relatively new to go and go doc, so I assumed the answer was simple, but I overlooked it.

This is an excerpt of my code. If I need to share more code, please let me know.

status.go

package synop

// status codes returned when parsing blocks.
type status int64

const (
    valid status = iota
    no_data
    // code omitted
)

// other functions omitted
Copy after login

cloudwind_block.go

package synop

import (
    "strings"
)

/*
Extract cloud cover from the cloud-wind block, Cxxxx.
Cloud, C, is the first digit of the block. Cloud over is given in [okta]:
*/
func ParseCloud(block string) (okta int, s Status) {
    slice := [2]int{0, 1}
    return parseIfValid(block, slice, str2int)
}

/*
Extract wind direction from from the cloud-wind block, xDDxxx.
Direction, DD, are the second and third digits.
*/
func ParseDir(block string) (dir string, s Status) {
    slice := [2]int{1, 3}
    return parseIfValid(block, slice, getDir)
}

// Other functions omitted
Copy after login

I have another file blocks.go which has almost the same structure as status.go and it does not cause this behavior. I also don't know if the problem is caused by the previous type status or something in the cloudwind_block.go file.

I use // for single-line documents and /* */ for multi-line documents. I tried occasionally to make it consistent, but as expected, it didn't work.


Correct Answer


The reason for grouping and indentation is that these functions are considered "constructors" of the type they are grouped/indented.

https://www.php.cn/link/31c49b512f199bc6f8734034a87dd9fa (If you scroll down a little, you will see this):

This example also shows top-level functions that return type T or pointer *T, possibly with additional error results, methods shown along with type T and its type, Assume they are constructors of T.

The above is the detailed content of Go Doc unexpectedly indents/groups functions. What causes this?. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template