Golang
-
gRPC (1)grpc 2023. 6. 4. 22:18
계기 본인은 server / client간의 양방향 통신을 위해서 NATS 라는 Protocol을 사용했다. NATS는 오픈 소스 메세징 시스템으로 publish / subscribe 방식, request / reply 방식 그리고 queue 을 사용한다. 장비를 관리하는 업무를 하다보니 각각의 client에 따로 명령을 전달해야 할 필요가 있었고 이에 사용하게 되었다. 사용방법이 매우 편리하고 빠르기 때문에 문제 없이 사용하고 있었는데 사용 간 type 에러 문제와 실시간성을 보장해야하는 기능이 필요할 때 양방향 스트링이 되지 않는 불편함이 생겼다. 이를 해결하기 위해 grpc를 찾아보게 되었다. gRPC란? gRPC는 Google에서 개발되었고 고성능 RPC 프레임워크이다. HTTP/2 에서 동작하며..
-
Golang Gin API Swagger 붙이기Golang 2022. 12. 16. 05:06
https://github.com/swaggo/swag#api-operation GitHub - swaggo/swag: Automatically generate RESTful API documentation with Swagger 2.0 for Go. Automatically generate RESTful API documentation with Swagger 2.0 for Go. - GitHub - swaggo/swag: Automatically generate RESTful API documentation with Swagger 2.0 for Go. github.com 계기 보통 GraphQL을 기본 api로 사용하고 있기 때문에 swagger에 필요성을 느끼지 못하고 있었는데 최근 다른 외부 서비스..
-
DataLoaderGraphql 2022. 10. 9. 13:50
기본적으로 graphQL에 대해 어느정도 알고 있다고 생각하고 작성하겠다. DataLoader란 graphQL에서 Resolver를 사용할 때 N+1 문제가 생긴다. N+1 문제란 요청은 한번만 했지만 Resolver에 의해 N번의 트랜젝션이 발생할 수 있는 것이다. 예를 들면, user, purchase, stuff 이 3개의 table이 있다고 가정해보고 gql 타입을 아래와 같이 정의했다고 가정하자. type User { id: String! name: String! email: String! purchases: [Purchase] # purchase를 조회하기 위한 Resolver가 있음 } type Purchase { id: String! total_price: Int! date: Time! s..
-
Golang에서 SMTP 로 mail 보내기 (gmail)Golang 2022. 9. 4. 18:24
App 사용을 위한 계정 생성하기 기존에는 google 로그인 시 사용하던 id / pwd로 mail을 보낼 수 있었지만 보안 정책이 변경되어 app 계정을 따로 생성해야 한다. 이제 smtp 계정을 설정할 때 내 mail주소와 화면에 나온 app 비밀번호를 사용하면 된다. code 작성 package gomail import ( "bytes" "encoding/json" "errors" "fmt" "html/template" "io/ioutil" "log" "net/smtp" "os" "path/filepath" ) func SendEmailSMTP(to []string, data interface{}, template string) (bool, error) { type credential struct..
-
Golang Server Base Code (graphQL, restAPI, mongoDB, postgresql)Golang 2022. 4. 22. 21:33
https://github.com/zzihyeon/golang-server GitHub - zzihyeon/golang-server: graphQL, restAPI, postgresql, mongoDB graphQL, restAPI, postgresql, mongoDB. Contribute to zzihyeon/golang-server development by creating an account on GitHub. github.com Golang 개발을 하고싶은데 처음 환경 setting이 어려운 사람들을 위해서 graphQL, restAPI, mongoDB, postgresql 관련 기본 setting을 한 base code를 push하였다.
-
Golang GraphQL 서버 #5 (타입 리졸버 추가하기)Golang 2022. 3. 22. 12:28
https://zzihyeon.tistory.com/43 Golang GraphQL 서버 #4 (커스텀 타입 매핑하기) https://zzihyeon.tistory.com/15 Golang GraphQL 서버 #3 zzihyeon.tistory.com/14 Golang graphQL Playground 사용법 zzihyeon.tistory.com/13 Golang GraphQL 서버 setting (gqlgen 사용) workspace directory.. zzihyeon.tistory.com 추가적으로 도움이 되는 기능 1. Type에 리졸버 추가하기 아래의 User struct에 대해서 school에 대한 Resolver를 추가하고 싶다면 어떻게 해야할까? type User { uid: Int64! ..
-
Golang GraphQL 서버 #4 (커스텀 타입 매핑하기)Golang 2022. 3. 22. 12:12
https://zzihyeon.tistory.com/15 Golang GraphQL 서버 #3 zzihyeon.tistory.com/14 Golang graphQL Playground 사용법 zzihyeon.tistory.com/13 Golang GraphQL 서버 setting (gqlgen 사용) workspace directory를 생성한다. mkdir DevBasic go mod 설정을 한다. go mod i.. zzihyeon.tistory.com 추가적으로 도움이 되는 기능 1. 커스텀 타입 매핑하기 (99designs/gqlgen: go generate based graphql server library (github.com)) 개발을 하다보면 Type을 int64, int32, int를 구..
-
Golang Postgresql SQLC 설정하기Golang 2022. 3. 21. 23:32
계기 SQL 문만 작성하면 자동으로 타입을 선언하고 메서드를 생성해주는 좋은 툴이 있어서 사용하게 되었다. 적용 단점: Postgresql sqlc 는 window에서 지원하지 않는다. 그래서 본인은 wsl(window subsystem for linux)를 사용하다가 너무 문제가 많아서 그냥 이 김에 맥북을 하나 장만했다. sqlc: kyleconroy/sqlc: Generate type-safe code from SQL (github.com) GitHub - kyleconroy/sqlc: Generate type-safe code from SQL Generate type-safe code from SQL. Contribute to kyleconroy/sqlc development by creating..