본문 바로가기

golang17

Go google style guide - overview & guide Golang의 google style guide 문서를 번역해 보았다. 아무래도 Golang 언어를 만든 기업이니 google guide를 따르는게 좋지 않을까 하는 판단에서 uber guide 등 다른 가이드보다 구글 가이드를 참고하고자 한다. 참고 문서: https://google.github.io/styleguide/go/index About Go style guide는 readable하고 idiomatic한 go를 작성하는 가장 좋은 접근법을 작성해 두었다. Document 대상 Normative Canonical Style Guide 모두 Yes Yes Style Decisions 가독성 멘토 Yes No Best Practices 관심있는 모두 No No 정의 Canonical: 모든 코드가 .. 2023. 11. 19.
Go garbage collection golang에서 garbage collection이 일어나는 시점과 작동 원리에 대해 알아보고 정리해두고자 한다. [참고 문서] https://tip.golang.org/doc/gc-guide https://changhoi.kim/posts/go/go-gc/ A Guide to the Go Garbage Collector - The Go Programming Language Documentation A Guide to the Go Garbage Collector A Guide to the Go Garbage Collector Introduction This guide is intended to aid advanced Go users in better understanding their applicatio.. 2023. 10. 30.
[TIL] Go buffer read golang 개발하다가 buffer 관련해서 몰랐던 사실을 알게되어 정리해 둔다. Context 입력으로 이미지를 받고, 해당 이미지에 대한 정보를 불러온 후, 원본 이미지를 그대로 다음 middleware로 전달하는 코드가 있다. var buffer bytes.Buffer _, err := io.Copy(&buffer, src) if err != nil { return err } img, _, err := image.Decode(buffer) if err != nil { return err } // 이후 buffer 그대로 사용 Problem 이미지가 다음 미들웨어로 들어오지 않아서 에러가 발생했다. 확인해 보니 image.Decode(buffer)에서 buffer를 모두 읽어와서 발생한 에러다. fu.. 2023. 10. 27.
Go convention 정리 Golang으로 코드를 작성할 때 알아두면 좋은 convention을 정리해두고자 한다. 참고 자료 https://github.com/golang/go/wiki/CodeReviewComments Comment 주석은 full sentence로 달도록 하자. // Request represents a request to run a command. type Request struct { ... // Encode writes the JSON encoding of req to w. func Encode(w io.Writer, req *Request) { ... Contexts context는 security credential, deadline, cancelation 등을 담을 수 있다. 함수의 첫 번째 인자로.. 2023. 10. 3.