[Go] 문서화
Updated:
개요
- 주석을 통해 패키지 문서화 가능
go doc
명령어를 통해 출력
예제
- 표준 라이브러리
- fmt 패키지
$ go doc fmt package fmt // import "fmt" Package fmt implements formatted I/O with functions analogous to C's printf and scanf. The format 'verbs' are derived from C's but are simpler. ... func Append(b []byte, a ...any) []byte func Appendf(b []byte, format string, a ...any) []byte ...
- fmt 패키지의 Println 함수
$ go doc fmt.Println package fmt // import "fmt" func Println(a ...any) (n int, err error) Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
- fmt 패키지
- 사용자 모듈
- 코드
// package calculate implements functions for the four arithmetic operations package calculate // Add returns the sum of two numbers func Add(x, y int) int { return x + y } // Subtract returns the subtract of two numbers func Subtract(x, y int) int { return x + y } // Multiply returns the multiply of two numbers func Multiply(x, y int) int { return x * y } // Division returns the division of two numbers func Division(x, y float64) float64 { return x / y }
- 실행 결과(패키지)
$ go doc calculate package calculate // import "test/calculate" package calculate implements functions for the four arithmetic operations func Add(x, y int) int func Division(x, y int) int func Multiply(x, y int) int func Subtract(x, y int) int
- 실행 결과(함수)
$ go doc calculate.Add package calculate // import "test/calculate" func Add(x, y int) int Add returns the sum of two numbers
- 코드