분류 전체보기 42

Building HTTP Services - Handler (Network programming with Go)

Go HTTP Server는 먼저 Server의 multiplexer가 있고, 이 client request 를 받는 것이다. Multiplexer 는 request 의 목적지를 결정한다. 그리고 처리할 수 있는 것으로 전달한다. 처리하는 곳이 Handler이다. Multiplexer 자체도 handler 인데, request를 가장 적절한 handler로 라우팅하는 역할을 한다. Handler가 요청을 전달받기 전에 middleware를 거치게 된다. Middleware는 handler의 behavior를 변경하거나 auxiliary task들을 수행한다. 예를 들면 logging, authentication, access control 등이 있다. srv := &http.Server { Addr: H..

Backend with Golang 2023.07.30

Using Matterjs & React to render to the DOM (Matterjs와 React를 사용하여 DOM element에 2d 물리엔진을 적용해보기)

Matter js 를 사용해서 움직이는 DOM element 를 만들어 보기로 했다. Matterjs 는 2d physics engine을 만들 수 있는 library 이다. Matterjs만 사용해서 그 안에 있는 render 기능을 쓰면 canvas element를 사용하게 된다. 이렇게 되었을 때 어떤 event가 있을 때 각 body의 style property를 쉽게 변경할 수 없다는 단점이 있다. https://stackoverflow.com/questions/63906218/using-matter-js-to-render-to-the-dom-or-react Using Matter.js to render to the DOM or React I want to render custom HTML el..

Frontend (React) 2023.07.26

[Concurrency-4] Concurrency Patterns in Go

Synchronization 이 가능한데 confinement 를 추구하는 이유가 뭘까? improved performance와 reduced cognitive load on developers를 이유로 들고 있다. Synchronization 이란 여기서 수행되는 시간들을 조정해서 multiple thread나 process 에서 하나의 데이터가 일치되는 것을 의미할 텐데, 이것은 비용이 들고, 이것을 쓰지 않고 피할 수 있다면 critical section 이 없어지고, synchronizing 하는데에 드는 비용을 쓰지 않아도 될 것이다. 그리고 synchronization을 적용해서 얻을 수 있는 여러 문제점들을 피할 수 있게 된다. 결과적으로 lexical scope 안에서 synchronous..

Backend with Golang 2023.06.17

[Concurrency-3] Go Channel의 사용

unidirectional channel의 경우 function parameter로 사용되는 경우가 많다. goroutine이 scheduled 되면, exit하는 것에 대한 보장이 되지 않는다. channel을 사용하면, code가 omitted되지 않고 잘 끝날 수 있는데, 이를 통해서 channel이 하는 게 blocking이라고 볼 수 있다. write가 된다면 그것이 빌때까지 기다린다는 것을 의미한다. 이때 Deadlock 이 잘 일어날 수 있는데, main goroutine에서 value가 placed되길 기다리고 있는데, 이게 일어나지 않으면 모든 goroutine 이 asleep되어 deadlock 이 일어나는 것이다. value, ok :=

Backend with Golang 2023.06.13

[Concurrency-2] Chapter 3 channel 전까지

Go는 model of concurrency 로 fork-join model를 따른다. fork라는 단어는 parent와 concurrently 하게 동작하기 위해서 child branch를 split off 할 수 있음을 의미한다. join이라는 것은 미래의 한 시점에 parent로 다시 branch가 join된다는 것을 의미한다. sayHello := func { fmt.Println("hello") } go sayHello() //continue doing other things main function 의 나머지 부분들은 빠르게 실행될 것이고, sayHello 함수가 실행될지 안될지는 undetermined이다. join point를 만드는 것이 중요하다. 그래서 race condition일 뿐인..

Backend with Golang 2023.06.12

[Concurrency-1] Concurrency가 왜 어려운가?

1. Race condition 공유된 자원을 두개이상의 operation이 실행되려고 할때, 그 순서가 보장되지 않게 되고, 가능한 여러개의 시나리오가 발생할 수 있다. 아무리 짧은 코드라도 큰 variability를 가지고 올 수 있는것이다. 2. Atomicity atomic이라는 걸 생각하면 context와 크게 연관되어 있다. 어떻게 scope를 정의하느냐에 따라서, atomic한지 안한지가 다르게 결정될 수 있다. the atomicity of an operation can change depending on the currently defined scope! atomic이라면 concurrent context 안에서는 safe하다는 것을 암시한다. 많은 statement들이 atomic 하지..

Backend with Golang 2023.05.28

MySQL - Transaction

Transaction - sequential group of statements, queries, or operations such as select, insert, update or delete to perform as a one signle work unit that can be committed or rolled back. - database 와 application 사이의 데이터 거래에 있어서 안전성을 높이기 위한 방법. 만약에 transaction 이 여러개의 modifications을 만든다면 두가지의 결과가 나타날 수 있다. transaction이 commit 되었을 때, 모든 modification이 성공하거나 transaction이 rollback 되었을 때, 모든 modification..

Backend with Golang 2023.05.09

Docker-compose.yml 파일 작성하기 (TBU)

Dockerfile - 이미지를 어셈블하기 위해 호출할 수 있는 명령이 포함된 텍스트 파일 - Dockerfile 에 빌드 관련 내용이 다 기재되어 있기 때문에 docker-compose.yml 에서 빌드 관련 내용을 기재할 필요 없이 dockerfile의 경로를 지정하기만 하면 된다. FROM: Base Image를 지정할 수 있다. easy to start by pulling an image from the Public Repo. RUN: 새로운 레이어에서 명령어 실행 하고 결과를 commit한다. 결과적으로 commit된 이미지는 그 다음스텝에서 사용된다. RUN command 형태나 RUN ["executable", "param1", "param2"] 이런식으로 실행할 수 있다. EXPOSE: E..

Backend with Golang 2023.05.09