"Gofmt"의 두 판 사이의 차이

 
(같은 사용자의 중간 판 8개는 보이지 않습니다)
12번째 줄: 12번째 줄:
* 기본적으로 gofmt는 다시 포맷된 소스를 표준 출력으로 인쇄한다.
* 기본적으로 gofmt는 다시 포맷된 소스를 표준 출력으로 인쇄한다.


==원본파일 유지==
<syntaxhighlight lang='console'>
<syntaxhighlight lang='console'>
root@localhost:~# cat hello.go
root@localhost:~# cat main.go
package main
import "fmt"
func main() {
    fmt.Println("hello world")
}
</syntaxhighlight>
<syntaxhighlight lang='console'>
root@localhost:~# cat main.go | gofmt
package main
package main
import "fmt"
import "fmt"
func main() {
func main() {
i := 0
        fmt.Println("hello world")
fmt.Println(i)
}
}
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='console'>
<syntaxhighlight lang='console'>
root@localhost:~# gofmt hello.go
root@localhost:~# gofmt main.go
package main
package main


28번째 줄: 38번째 줄:


func main() {
func main() {
        i := 0
         fmt.Println("hello world")
         fmt.Println(i)
}
}
</syntaxhighlight>
</syntaxhighlight>
==원본파일 변경==
<syntaxhighlight lang='console'>
<syntaxhighlight lang='console'>
root@localhost:~# gofmt -w hello.go
root@localhost:~# gofmt -w hello.go
46번째 줄: 57번째 줄:


==같이 보기==
==같이 보기==
{{z컬럼3|
* [[Go]]
* [[Go]]
* [[포매터]]
* [[포매터]]
* [[go fmt]]
* [[gofmt -d]]
* [[gofmt -l]]
* [[Go 코딩 컨벤션]]
* [[Go 코딩 컨벤션]]
* [[gofmt 재귀 적용]]
* [[gofmt 재귀 적용]]
}}


==참고==
==참고==
* https://pkg.go.dev/cmd/gofmt
* https://pkg.go.dev/cmd/gofmt


[[분류: Go]]
[[분류: Gofmt]]

2023년 1월 7일 (토) 16:13 기준 최신판

1 개요[ | ]

gofmt
gofmt 명령어, 고포맷 명령어
  • Go 소스코드의 형식(format)을 맞추는 프로그램, 명령어
  • 들여쓰기에는 탭을 사용하고 정렬에는 공백을 사용한다.
편집기가 고정폭 글꼴을 사용하고 있다고 가정한다.
  • 명시적 경로가 없으면 표준 입력을 처리한다.
  • 파일이 주어지면 해당 파일에서 작동합니다.
  • 디렉토리가 주어지면 해당 디렉토리의 모든 .go 파일에서 재귀적으로 작동한다.
단, 마침표로 시작하는 파일은 무시된다.
  • 기본적으로 gofmt는 다시 포맷된 소스를 표준 출력으로 인쇄한다.

2 원본파일 유지[ | ]

root@localhost:~# cat main.go
package main
import "fmt"
func main() {
    fmt.Println("hello world")
}
root@localhost:~# cat main.go | gofmt
package main

import "fmt"

func main() {
        fmt.Println("hello world")
}
root@localhost:~# gofmt main.go
package main

import "fmt"

func main() {
        fmt.Println("hello world")
}

3 원본파일 변경[ | ]

root@localhost:~# gofmt -w hello.go
root@localhost:~# cat hello.go
package main

import "fmt"

func main() {
        i := 0
        fmt.Println(i)
}

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}