레이블이 generic인 게시물을 표시합니다. 모든 게시물 표시
레이블이 generic인 게시물을 표시합니다. 모든 게시물 표시

golangci-lint

# vim 에서 golang generic(1.18)를 사용하는데 lint 에러가 많이 발생한다.
# vim > vim-go > golint 를 사용하고 있고 golint 바이너리는 업데이트 해도 다음과 같은 메시지가 발생한다.
golint ./...
main.go:12:8: expected ';', found '|' (and 4 more errors)

# vim > ale > gofmt 도 다음과 같은 에러 메시지를 발생한다.
gofmt .
main.go:12:8: expected ';', found '|'
main.go:12:10: illegal character U+007E '~'
main.go:16:2: expected '}', found 'return'
main.go:20:2: expected declaration, found result

https://github.com/golang/lint 가보니 2021년에 deprecated 돼 관리가 안되고 있었다.
# gofmt 바이너리는 2018년에 생성된것을 사용하고 있었다.
type gofmt
gofmt is /Users/ysoftman/workspace/gopath/bin/gofmt --> 2018년도
gofmt is /opt/homebrew/bin/gofmt --> ../Cellar/go/1.22.1/bin/gofmt

# golint 는 삭제하고
rm -f $(which golint)

# 2018년도 gofmt 삭제
rm -f /Users/ysoftman/workspace/gopath/bin/gofmt

# 대안으로 https://github.com/golangci/golangci-lint 를 사용하면 된다.
golangci-lint run ./...

# vim-go 설정을 변경
let g:go_metalinter_enabled = ['vet', 'golangci-lint', 'errcheck']

# ale go linter 도 변경
let g:ale_linters = {
\ 'python': ['flake8', 'pylint'],
\ 'javascript': ['eslint'],
\ 'go': ['golangci-lint', 'gofmt']
\}


golang issues

go programming 을 하다가 발견한 이슈들을 정리해 본다.

# map의 struct field 값 설정 못하는 문제
발견시점: 2014-12
해결시점: 2024-05 go1.22.1 에서 아직 발생함
Go 언어 map의 값이 struct 형일대 struct 의 field 값 설정 못하는 문제가 있다.
현재로선 struct 대신 *struct 으로 선언해서 사용한 경우에만 struct field 를 설정 할 수 있다.
testcode: https://github.com/ysoftman/test_code/blob/master/golang/struct_map/struct_map.go
관련 이슈: 
https://code.google.com/p/go/issues/detail?id=3117
http://egypt.silverkeytech.com/blogs/third-world/2013/8/you-cannot-assign-a-struct-field-off-map-directly

# generic struct type 파라메터의 filed 액세스 안되는 문제
발견시점: 2024-05 (2024-05 현재 아직 해결 안됨)
해결시점: 2024-05 go1.22.1 에서 아직 발생함
generic type 이 struct 일때 field 에 접근하지 못하는 문제가 있다.
https://tip.golang.org/doc/go1.18 에서 다음과 같이 제한을 풀기로 했지만..
The Go compiler does not support accessing a struct field x.f where x is of type parameter type even if all types in the type parameter’s type set have a field f. We may remove this restriction in a future release.