본문 바로가기

golang17

Formatting in golang golang은 C-style의 포맷팅을 지원한다. 하지만 좀 더 고수준의 언어이기 때문에 좀 더 다양한 타입에 대한 출력을 지원한다. 이에 golang에서의 출력 포맷을 정리해볼 필요를 느껴서 정리해 본다. 참고: https://pkg.go.dev/fmt General %vthe value in a default format when printing structs, the plus flag (%+v) adds field names %#va Go-syntax representation of the value %Ta Go-syntax representation of the type of the value %%a literal percent sign; consumes no value %v 인스턴스 출력 {1 .. 2023. 9. 3.
Internal package in golang Golang을 이용해서 개발하다가 흥미로운 개념을 발견했다. v1.4부터 추가된 개념으로, internal package라는 개념이다. 공식 홈페이지에 release 노트를 보면 다음과 같이 설명되어 있다. Internal packages Go's package system makes it easy to structure programs into components with clean boundaries, but there are only two forms of access: local (unexported) and global (exported). Sometimes one wishes to have components that are not exported, for instance to avoid ac.. 2023. 9. 3.
Go 언어를 활용한 분산 서비스 개발 프로토콜 버퍼 장점 type safety 보장 스키마 위반 방지 보일러플레이트 코드 감소: 인코딩/디코딩 메소드가 자동으로 만들어진다. 빠른 직렬화: JSON보다 직렬화가 6배나 빠르다. 하위 호환성 제공 → 마이크로서비스 같은 두 시스템 사이에서 통신하기 좋다. 로그 추가만 할 수 있는 레코드의 연속 순서가 있는 데이터를 저장, 공유, 처리할 때 사용 데이터베이스 복제, 분산 서비스 조율, 애플리케이션 상태 관리 등에 사용한다. 원리 여러 개의 세그먼트로 나눔: 무한한 용량의 디스크는 없기 때문 세그먼트: 저장 파일(store file) + 인덱스 파일(index file) 저장 파일: 레코드 데이터 저장 인덱스 파일: 레코드들의 인덱스를 메모리 맵 파일로 만들어 메모리 데이터를 다루는 속도로 빠르게 .. 2023. 7. 23.
실무에 바로 쓰는 Go 언어 핸즈온 가이드 1. 커맨드 라인 애플리케이션 작성 함수에서 read, write를 할 때 인자로 reader와 writer를 받아와서 하는 게 좋다. 직접 Stdin, Stdout 변수를 참조하면 유닛 테스트 작성이 매우 어렵다. 모든 성공적이지 않은 실행은 종료시 os.Exit()를 이용해서 0이 아닌 종료 코드를 반환해야 한다. 사용자 정의 에러를 잘 활용하자. var errPosArgsSpecified = errors.New("Positional arguments specified") ... c, err := parseArgs(os.Stderr, os.Args[1:]) if err != nil { if errors.Is(err, errPosArgSpecified) { fmt.Fprintln(os.Stdout, e.. 2023. 7. 12.