Programming/JAVA, C++, Go, Rust(39)
-
backtrace 정보 출력
exception 발생 시 혹은 오류 발생 시 call stack 정보를 출력하고자 하는 경우가 발생합니다. 이럴때 C++에서 다음과 같이 코드를 작성할 수 있습니다.#include "back_trace.h"#include #include #include #include #include #include #include const uint32_t MAX_NUM_TRACE = 32;std::string BackTrace::get_backtrace() { void* callstack[MAX_NUM_TRACE]; int frames = backtrace(callstack, MAX_NUM_TRACE); char** messages = backtrace_symbols(callstack, frames..
2025.03.31 -
go get 오류 발생 시 대처
go get 시 다음과 같이 connection이 거절되는 오류가 발생할 수 있습니다. ✗ go get git.linecorp.com/VISION-PLATFORM/photato-server@v1.6.2 go: downloading git.yourcompany.com/organization/yourproject v1.0.0go: git.yourcompany.com/organization/yourproject@v1.0.0: verifying module: ... : reading https://sum.golang.org/lookup/git.yourcompany.com/.../yourpro..
2024.05.09 -
go profiler pprof 사용법
About pprof go 프로그램을 프로파일링 하여 CPU나 memroy, 혹은 go 프로그램이 사용하는 go routine 개수와 같은 여러 자원들에 대해 동적 분석 결과를 수행하는 툴 입니다. Usage Recording 사용법은 매우 간단합니다. go 언어의 시작 부분에서 다음의 고루틴을 실행한 후, 프로그램 종료 직전에 pprof를 닫으면 됩니다. // import _ "net/http/pprof" ... go func() { http.ListenAndServe(":6060", nil) }() ... f, err := os.Create("heap_usage_profile.mprof") if err != nil { logger.Fatalf("heap_usage_profile.mprof: %v", ..
2024.02.06 -
Study stuff for Golang
https://tour.golang.org/ http://golang.site/ https://nomadcoders.co/go-for-beginners Coding Convention https://golang.org/doc/effective_go https://dave.cheney.net/practical-go/presentations/qcon-china.html https://github.com/golang/go/wiki/CodeReviewComments Project Structure https://github.com/golang-standards/project-layout https://github.com/bxcodec/go-clean-arch https://github.com/katzien/go..
2023.07.24 -
Go test: table driven test with Parallel()
우리는 test driven test를 위해 Unit test 코드를 작성합니다. 이 때 하나의 unit test function을 여러가지 다양한 방식으로 test 하기 위해 여러 parameter들을 table로 만들어 사용합니다. 다음은 그 예입니다. func TestA(t *testing.T) { t.Parallel() testCases := []struct { name string value int }{ { name: "case 1", value: 1, }, { name: "case 2", value: 2, }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // test code here t.Log(tc.value) ..
2023.06.22 -
Go gotcha examples
예를들어 다음과 같은 대표적인 'Go gotcha'들이 존재합니다. variable shadowing Go 에서는 inner scope에서 같은 이름으로 변수를 선언할 수 있습니다. 이는 이전의 변수에 접근할 수 없게 만드는 소위 'shadowing' 역할을 수행합니다. func main() { a := 1 fmt.Println(a) if true { a := 2 fmt.Println(a) } fmt.Println(a) } 위 코드의 출력은 다음과 같습니다. 1 2 1 slices and arrays Go에서 slice와 array는 매우 유사한 type 입니다. slices는 arrays에 대한 references이며 동적인 길이를 갖습니다. 반면에 arrays는 고정된 길..
2023.06.22