Mar 2, 2024 - 제로부터 시작하는 러스트 백엔드 프로그래밍 1

러스트를 알게 된 시점은 StackOverflow(stackoverflow.com)에서 설문조사 중
현재 사용하는 언어 중, 내년에도 사용하고 싶은언어는? 이라고 질문을,
스택오버플로우 가입자 중 65,000명 에게 물어봤을 때 86.1 퍼센트를 차지한 언어가 Rust 였기 때문입니다.

러스트는 안전하고, 빠르고, 병렬성에 초점을 둔 시스템 프로그래밍 언어이다.

  • Rust 공식문서

러스트는 다른 언어에 존재하는 고충을 해결하면서 더욱 적은 단점으로 확실하게 러스트가 다른언어보다 한 발 앞서해 해준다.

  • 스택오버플로우 Rust Top 컨트리뷰터 Jake Goulding

라는 유명한 이야기가 있을 정도로 Rust 는 매우 핫한 언어입니다. ‘제로부터 시작하는 러스트 백엔드 프로그래밍’ 라는 책의 옮긴이 김모세님도, 머리말에서 ‘안전하고’, ‘병렬적이며’,’실용적인’ 언어로 설계되었다고 적혀있다.

이 책에서는 러스트가 API 개발을 위한 생상적인 언어가 될 수 있는지에 대한 의문을, 할 수 있다는 설명을 하면서 어떤 생산적인 라이브러리를 사용하면되는지 알려줍니다.

이 책은 툴링부터 시작하여, 도커를 거쳐 테스트 방법까지 고민하는 책입니다. 기초 문법을 배울려면 Rust in action 을 보는 게 조금 더 좋을 거 같고, (러스트 프로그래밍 공식 가이드는 아직 못봤기 때문에 본 책을 추천합니다.) 어느정도 배운 러스트를 실무에 사용하거나 실용적인 부분에 대해 학습할때 매우 좋은 책이라고 생각합니다.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

자세한 설명법이나 doc 에 대해서는 첨부를 통해 사이트를 알려줘, 사이트의 가이드를 통해 설치를 진행했습니다.

bymin@homeui-MacBookPro rust % curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

/Users/bymin/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

/Users/bymin/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

/Users/bymin/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

/Users/bymin/.profile
/Users/bymin/.zshenv

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


default host triple: x86_64-apple-darwin
default toolchain: stable (default)
profile: default
modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
> 3

로 설치 후 ,

bymin@homeui-MacBookPro ~ % rustc --version
rustc 1.76.0 (07dca489a 2024-02-04)

2월 4일 버전으로 설치가 되는 것을 확인할 수 있었습니다.

IntelliJ rust 책에서 알려준 가이드로 접속하면 RustLover 라는 사이트로 이동이 됩니다. 젯브레인을 자주 사용하므로, RustLover(RR) 을 설치합니다.

이 책에서는 웹 프레임워크를 actix-web 을 사용하고, 주석을 통해서 모든 소스를 받을 수 있습니다.
https://github.com/LukeMathWalker/zero-to-production 로 pork 받아, 소스를 보면서 진행을 따라가는 것도 좋을 듯했습니다.

https://actix.rs 에 가서 기본 샘플을 그대로 따라하고, doc 을 한번 읽는 것이 좋을듯합니다.

use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, HttpRequest};

#[get("/")]
async fn hello() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
}

#[post("/echo")]
async fn echo(req_body: String) -> impl Responder {
HttpResponse::Ok().body(req_body)
}

async fn manual_hello() -> impl Responder {
HttpResponse::Ok().body("Hey there!")
}

async fn greet(req: HttpRequest) -> impl Responder {
let name = req.match_info().get("name").unwrap_or("World");
format!("hello {}!", &name)
}

#[tokio::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new().route("/", web::get().to(greet))
.route("/{name}", web::get().to(greet))
})
.bind("127.0.0.1:8000")?
.run().await
}

위의 소스는 예제 소스와, 책의 소스를 혼합하여 서버를 구동하였습니다.

문서 상 Cargo.toml 의 상세내용을 추가해야합니다.

[package]
name = "zero2prod"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-web = "4"
tokio = { version = "1.36.0", features = ["rt", "rt-multi-thread", "macros"] }

책 내용과는 조금 다르게 변경되었지만, 정상적으로 동작됩니다.

Jan 8, 2024 - Gradle 6.x to 8.x 업그레이드 가이드

Gradle 6.x에서 8.x로의 업그레이드 시, 여러 변경 사항이 있습니다.

아래는 주요 변경 내용입니다:

1. 의존성 관리 변경

1.1 compileimplementation

Gradle 8.x에서는 compileimplementation으로 변경되었습니다.

이전:

compile 'group:artifact:version'

변경 후:

implementation 'group:artifact:version'

1.2 api → implementation (옵션)

Gradle 5.x 이상에서 도입된 api는 그룹 간 의존성을 전파시키는 역할을 했습니다. 8.x에서는 이를 implementation으로 대체하였습니다.

이전:

compile 'group:artifact:version'

변경 후:

implementation 'group:artifact:version'

2. 테스트 의존성 변경

2.1 testCompile → testImplementation

테스트 의존성을 선언할 때 testCompile은 testImplementation으로 변경되었습니다.

이전:

testCompile 'group:artifact:version'

변경 후:

testImplementation 'group:artifact:version'

3. 기타

3.1 compileOnly는 그대로 유지

Gradle 8.x에서도 compileOnly는 변경되지 않았습니다.

Jan 7, 2024 - jenv를 사용하여 여러 Java 버전 관리하기

1. jenv 설치:

Homebrew를 이용하여 jenv를 설치합니다.

brew install jenv

Homebrew를 사용하지 않는 경우, jenv GitHub 페이지에서 설치 방법을 확인하세요.

2. Java 버전 추가:

이미 설치된 Java 버전들을 jenv에 추가합니다.

jenv add /Library/Java/JavaVirtualMachines/<Java 버전>/Contents/Home

예: Java 11 추가

jenv add /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home

3. 전역(default) 버전 설정:

기본적으로 사용할 Java 버전을 설정합니다.

jenv global 11.0

‘11.0’은 설치한 Java 버전에 맞춰 수정합니다.

4. 로컬 프로젝트 설정 (선택 사항):

특정 프로젝트에만 특정 Java 버전을 사용하려면 프로젝트 폴더로 이동하여 아래 명령을 실행합니다.

jenv local 11.0

5. Java 버전 확인:

설정이 제대로 되었는지 확인하기 위해 다음 명령을 사용합니다.

java -version

jenv로 Java 버전 변경 시 권한 문제 해결:

Java 버전 변경 시 “Permission denied” 오류가 발생하는 경우, 권한 문제를 해결하기 위해 다음 명령을 실행합니다.

sudo chown -R $(whoami) ~/.jenv

다시 Java 버전 설정:

이제 Java 버전을 다시 설정할 수 있습니다.

jenv local 11.0

Java 버전 확인:

변경된 Java 버전이 표시되는지 확인합니다.

java -version

위 단계를 따라 진행하면 jenv를 사용하여 여러 Java 버전을 효과적으로 관리하고, 프로젝트별로 다른 버전을 사용할 수 있습니다.