본문 바로가기
반응형

Go lang3

go lang convert struct to interface{} go lang convert struct to interface{} p := Person{"John", 21} var v interface{} v = p go lang convert interface{} to struct type Person struct { name string age uint } func convToStruct(v interface{}) Person { p := v.(Person) return p } 2021. 8. 31.
Go 루틴 (goroutine) 1. Go rountine Go routine은 Go 런타임이 관리하는 Lightweight 논리적 (혹은 가상적) 쓰레드(1이다. Go에서 “go” 키워드를 사용하여 함수를 호출하면, 런타임시 새로운 go routine을 실행한다. go routine은 비동기적으로(asynchronously) 함수루틴을 실행하므로, 여러 코드를 동시에(Concurrently) 실행하는데 사용된다. 동시성을 제공하고 있다. go routine의 특징 - 비동기 - 동시성 (1 go routine은 OS 쓰레드보다 훨씬 가볍게 비동기 Concurrent 처리를 구현하기 위하여 만든 것으로, 기본적으로 Go 런타임이 자체 관리한다. Go 런타임 상에서 관리되는 작업단위인 여러 go routine들은 종종 하나의 OS 쓰레드.. 2021. 8. 23.
go 채널을 사용하는 좋은 예제 go channel을 사용하는 좋은 예제 이 코드에서는 go channel을 exit할 수 있는 예제가 포함되어 있습니다. 기본적인 예제 중 select 문을 사용해서 채널값을 받게 되면 루틴을 종료하는 예제입니다. 이 기본 go channel을 사용하는 design pattern 만 알고 있으면 대부분을 고 채널을 사용할 때 응용할 수 있습니다. var quit chan struct{} func startLoop() { quit := make(chan struct{}) go loop() } func stopLoop() { // As mentioned by Kaedys //close(quit) // permits signalling everyone havins such a `case 2021. 8. 19.
반응형