Doa's blog

소프트웨어와 투자를 연구합니다

[Golang] Goroutine과 Channel

Goroutine goroutine은 경량 스레드이다. (Green thread 혹은 light-weight thread 라고도 부른다) green threads are threads that are scheduled by a runtime library or virtual machine (VM) instead of natively by the underlying operating system (OS). - Wikipedia Channel channel은 데이터를 보내는 통로이다. 자료구조 queue의 목적으로 써도 문제가 없다. 버퍼 사이즈를 명시하지 않으면 사이즈가 0이다. ch1 := make(chan int) // 버퍼 사이즈가 0 ch2 := make(chan int, 1024) // 버퍼 사이즈가 1024 동작 방식 처음 goroutine을 사용하다보면 아래와 같은 에러를 자주 보게 된다.

[Golang] Stack과 Queue

Golang에서 Stack과 Queue 자료구조를 사용해보자. 다행히 Slice만으로도 두 가지 용도로 사용할 수 있다. Stack 코드 // push stack := []int{1, 2, 3} stack = append(stack, 4) stack = append(stack, 5, 6) fmt.Println(stack) // pop val, stack := stack[len(stack)-1], stack[:len(stack)-1] fmt.Println(stack, val) 결과 [1 2 3 4 5 6] [1 2 3 4 5] 6 Queue 코드 // enqueue queue := []int{1, 2, 3} queue = append(queue, 4) fmt.

[Golang] 포인터 리시버 vs 밸류 리시버

Value receiver와 Pointer receiver, 2가지가 receiver가 있다. 아래와 같은 구조체가 있다고 가정하고 type Person struct { Name string } Value receiver의 예 func (p Person) String() string { return p.Name + "!!!" } Pointer receiver의 예 func (p *Person) String() string { return p.Name + "!!!" } 두 가지 receiver를 언제 어떻게 사용해야하는지 헷갈려서 공부한 내용을 기록한다. 우선 아래의 원칙을 알아야 한다. 원칙1. 둘 중에 한 가지만 정의할 수 있다.

대한민국 사회적 문제들

가정 폭력을 당하는 아이들 부모로부터 받는 학대를 받는 아이들이 많이 있지만 조기에 발견하기가 어렵다. 폭력을 당한 주체가 어리고 남에게 도움을 구하기 어렵기 때문이다. 취업이 어려운 20/30대 취업이 어려운 이유는 채용하는 기업의 수가 줄어서이다. 좋은 학교를 졸업해도 아르바이트와 인턴, 비정규직 일자리에 전전하게 된다. 이는 혼인과 출산에 영향을 미처 더 큰 사회적 문제를 야기한다. 운영이 힘든 자영업 사장님 최저임금의 급격한 증가와 주 52시간 근무제 도입, COVID-19로 인한 방문객의 감소로 많은 자영업 사장님들은 이미 한계에 봉착했거나 힘들게 사업을 운영해나가고 있다.

왜 Go를 사용하는가

1. 간단하다. 25개 키워드. 끝. (https://golang.org/ref/spec#Keywords) Java 49개 (https://www.geeksforgeeks.org/list-of-all-java-keywords/) c++17 84개 (https://boycoding.tistory.com/140) => 배우기 쉽고 읽기도 쉽다. 2. 성능이 좋다 Java 대비 빠른 실행속도 및 훨씬 적은 메모리 사용 (https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/go.html) binary 빌드 & 배포가능. no runtime environment! => 서버 운영비용 감소 3. 훌륭한 생태계 docker, kubernetes, prometheus와 같은 유명한 SW존재 오픈소스도 활발하게 개발되고 있음 Google (https://github.com/google) Netflix (https://github.com/Netflix) Grab (https://github.com/grab) Uber (https://github.com/uber) Golang Korea (https://web.facebook.com/groups/golangko/) 관심도 증가 중(https://trends.

Code Format Test

코드 코드 포맷이 잘 적용되는지 테스트 해본다. package main import "fmt" func main() { fmt.Println("만나서 반갑습니다") } 리스트 리스트가 잘 되는지 확인해본다. 사과 바나나 포도 링크 링크가 잘 되는지 테스트해본다. 구글 네이버

처음 글

처음 글 hugo를 이용하여 처음으로 글 써본다.

Creating a New Theme

Introduction This tutorial will show you how to create a simple theme in Hugo. I assume that you are familiar with HTML, the bash command line, and that you are comfortable using Markdown to format content. I’ll explain how Hugo uses templates and how you can organize your templates to create a theme. I won’t cover using CSS to style your theme. We’ll start with creating a new site with a very basic template.

(Hu)go Template Primer

Hugo uses the excellent go html/template library for its template engine. It is an extremely lightweight engine that provides a very small amount of logic. In our experience that it is just the right amount of logic to be able to create a good static website. If you have used other template systems from different languages or frameworks you will find a lot of similarities in go templates. This document is a brief primer on using go templates.

Getting Started with Hugo

Step 1. Install Hugo Goto hugo releases and download the appropriate version for your os and architecture. Save it somewhere specific as we will be using it in the next step. More complete instructions are available at installing hugo Step 2. Build the Docs Hugo has its own example site which happens to also be the documentation site you are reading right now. Follow the following steps: Clone the hugo repository Go into the repo Run hugo in server mode and build the docs Open your browser to http://localhost:1313 Corresponding pseudo commands: