전체 글
-
Go 언어 time.Timer#Reset() 완벽 가이드: 올바른 사용법 알아볼까요?Go 2024. 9. 19. 22:42
Go 언어 time.Timer#Reset() 완벽 가이드: 올바른 사용법 알아볼까요?Go 언어에서 time.Timer를 사용하고 계신가요? 매우 기본적인 요소인데도 올바르게 사용하는 것은 의외로 어렵습니다. 얼마 전에 직접 겪은 사례와 함께 그 올바른 사용법을 소개하려고 합니다.TL;DRtime.Timer#Stop() 후에는 time.Timer.C를 읽어서 남은 값을 버려야 할 때가 있습니다.ti := time.NewTimer(5 * time.Second)// ...if !ti.Stop() { time.Timer#Reset()은 타이머가 정지된 상태에서 호출해야 합니다.// ...if !ti.Stop() { 타이머에 대한 이러한 조작은 동시에 실행하면 안 됩니다.Stop()의 올바른 사용법앞서..
-
Go 언어에서 chan chan 즉, 채널을 채널로 주고받기Go 2024. 9. 19. 22:35
Go 언어에서 chan chan 즉, 채널을 채널로 주고받기Go 언어에서 채널을 채널로 주고받을 수 있다는 것, 알고 계신가요? 의외로 편리해서 몇 가지 사용 예를 소개하려고 합니다.사용 예 1: Request/Response 패턴채널은 일반적으로 단방향 데이터 전달을 하지만, 채널을 이중으로 사용하면 응답을 받을 수 있는데요. 예를 들어, 처리 결과의 error를 받고 싶다면 chan chan error를 사용할 수 있습니다.reqc := make(chan chan error) 요청을 보내는 쪽에서는 chan error를 만들어서 chan chan에 전송합니다. 이 채널로 결과가 돌아오며, 결과가 반환될 때까지 블록됩니다.ch := make(chan error)reqc 요청을 받는 쪽에서는 받은 채널..
-
Go 실행 파일에 ZIP으로 리소스 임베딩하기: 간단하게 알아볼까요?Go 2024. 9. 19. 22:24
Go 실행 파일에 ZIP으로 리소스 임베딩하기: 간단하게 알아볼까요?시작하며ZIP을 사용하여 실행 파일에 리소스를 임베딩하는 방법을 소개하려고 한데요. 실제로 Go의 archive/zip, zip 명령어, cat 명령어(확인을 위해 unzip 명령어도 함께)를 사용하여 리소스를 임베딩하는 예제를 설명해드리겠습니다.Go에서 리소스 임베딩Go로 애플리케이션을 개발할 때, CSS, JavaScript, 이미지, 템플릿 등의 리소스를 실행 파일과 별도로 배치하거나 실행 파일에 임베딩해야 합니다. 리소스를 임베딩하는 방법에는 코드 제너레이터를 사용하는 방법과 ZIP을 사용하는 방법이 있는데요.코드 제너레이터리소스 임베딩에서 자주 소개되는 방법은 코드 제너레이터를 사용하여 리소스를 Go 소스 코드로 변환하는 것입니..
-
Go 언어 fmt.Printf 완벽 가이드Go 2024. 9. 19. 22:12
Go 언어 fmt.Printf 완벽 가이드: 이제 두렵지않은 printf 사용법 알아볼까요?Go 언어를 사용하다 보면 fmt 패키지의 printf 계열 함수들을 자주 만나게 한데요. 이번에는 Fprintf, Printf, Sprintf 함수들의 포맷 지정 방법에 대해 자세히 알아보겠습니다.모든 타입에 사용할 수 있는 verb%v값을 기본 형식으로 출력합니다.기본 타입의 경우타입verb논리값 (bool)%t부호 있는 정수 (int, int8 등)%d부호 없는 정수 (uint, uint8 등)%d부동소수점수 (float64 등)%g복소수 (complex128 등)%g문자열 (string)%s채널 (chan)%p포인터 (pointer)%ppackage mainimport ( "fmt")func main(..
-
Go로 CUI 툴을 쉽고 편하게! gocui 사용기Go 2024. 9. 19. 21:56
Go로 CUI 툴을 쉽고 편하게! gocui 사용기안녕하세요. 요즘 Go로 CUI·CLI 툴을 만드는 것에 푹 빠져 있는데요. CUI 툴을 만들 때 사용하고 있는 라이브러리로 gocui라는 것이 있습니다.어떤 건가요?터미널 상에서 HTML의 폼(form)처럼 입력 인터페이스를 간단하게 만들 수 있습니다. 버튼이나 체크박스 등도 준비해두었는데요.사용 방법[_demos Github 예제](https://github.com/skanehira/gocui-component/tree/master/_demos에 있는 select 샘플을 바탕으로 설명해보겠습니다.func main() { gui, err := gocui.NewGui(gocui.Output256) if err != nil { pan..
-
Rust 강좌 5 - 안전하고 효율적인 Hyper로 HTTP 요청 처리하기Rust 2024. 9. 19. 09:18
Rust 강좌 5 - 안전하고 효율적인 Hyper로 HTTP 요청 처리하기안녕하세요! 오늘은 Rust의 대표적인 HTTP 라이브러리인 hyper를 알아볼 텐데요. Rust의 HTTP 라이브러리 생태계는 1.0 이전까지는 변화가 많았지만, 이제는 hyper가 많은 Rust 개발자들의 사랑을 받는 대표 라이브러리로 자리 잡았습니다. 이 장에서는 hyper를 클라이언트로 사용하는 방법에 집중해 볼까 합니다. 이 라이브러리는 서버 구현도 포함하고 있지만, 대부분의 개발자들은 서버를 직접 만드는 것보다는, 이미 만들어진 서버의 API를 소비하는 경우가 많습니다. 그러면, hyper가 어떻게 우리에게 도움을 줄 수 있을까요?1. 기본적인 요청 보내기우선, Cargo.toml 파일에 의존성을 추가해 보겠습니다.[de..
-
Next.js 14에서 JWT를 안전하게 관리하는 방법: Express 백엔드와의 통합Javascript 2024. 9. 19. 09:11
Next.js 14에서 JWT를 안전하게 관리하는 방법: Express 백엔드와의 통합Next.js 14 프로젝트에서 JWT를 어떻게 관리하는 것이 가장 좋은 방법일지 고민이 많으실 텐데요. 특히 App Router를 사용하면서, 서버 컴포넌트는 Local Storage에 접근할 수 없기 때문에 JWT를 안전하게 다루는 방법에 대해 혼란스러울 수 있습니다. 오늘은 이 문제를 해결하기 위한 다양한 방법을 살펴보고, Express 백엔드와 어떻게 통합할 수 있는지 알아보겠습니다.1. HTTPOnly 쿠키를 사용하자가장 많이 추천되는 방법은 HTTPOnly 쿠키를 사용하는 것입니다. HTTPOnly 쿠키는 클라이언트에서 JavaScript로 접근할 수 없기 때문에, 보안적으로 안전한 선택입니다. 특히 JWT와..
-
Next.js에서 Vite로 전환: 왜 많은 개발자들이 Next.js를 떠나고 있을까?Javascript 2024. 9. 19. 09:04
Next.js에서 Vite로 전환: 왜 많은 개발자들이 Next.js를 떠나고 있을까?최근 들어 많은 개발자들이 Next.js에서 Vite로 전환하고 있다는 소식을 자주 접하게 됩니다. 특히, Next.js의 앱 라우터(App Router)와 서버 컴포넌트(React Server Components, RSC) 도입 이후 기대와 달리 여러 가지 문제들이 드러나면서, 일부 개발자들은 더 나은 성능과 사용성을 제공하는 Vite로 돌아서고 있죠. 이번 글에서는 Vite로의 전환 이유와 Next.js가 직면한 문제들을 깊이 있게 살펴보겠습니다.1. 개발 서버의 성능 문제가장 많이 제기된 문제는 Next.js의 개발 서버 속도입니다. 많은 개발자들이 Next.js의 Turbopack을 사용함에도 불구하고, 개발 서..