{"id":20136030,"url":"https://github.com/zkfmapf123/go-coding-convention","last_synced_at":"2026-03-19T14:04:17.547Z","repository":{"id":254860225,"uuid":"842881173","full_name":"zkfmapf123/go-coding-convention","owner":"zkfmapf123","description":"golang 코드 컨벤션","archived":false,"fork":false,"pushed_at":"2024-08-26T14:15:01.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-02T04:58:48.780Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zkfmapf123.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-15T09:52:27.000Z","updated_at":"2024-09-08T09:20:17.000Z","dependencies_parsed_at":"2024-08-26T16:57:01.583Z","dependency_job_id":null,"html_url":"https://github.com/zkfmapf123/go-coding-convention","commit_stats":null,"previous_names":["zkfmapf123/go-coding-convention"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zkfmapf123/go-coding-convention","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkfmapf123%2Fgo-coding-convention","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkfmapf123%2Fgo-coding-convention/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkfmapf123%2Fgo-coding-convention/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkfmapf123%2Fgo-coding-convention/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zkfmapf123","download_url":"https://codeload.github.com/zkfmapf123/go-coding-convention/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkfmapf123%2Fgo-coding-convention/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272013576,"owners_count":24858475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-25T02:00:12.092Z","response_time":1107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T21:17:30.011Z","updated_at":"2025-10-12T20:39:28.924Z","avatar_url":"https://github.com/zkfmapf123.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Convention \n\n## 폴더구조 (선택사항)\n\n- 서비스 / 필요에 따라 추가하거나, 제외해도 됨\n\n```sh\n## 라이브러리 / Tools\n|- cmd                  ## main applications\n|- internal             ## 내부에서만 사용하는 라이브러리 코드       \n|- pkg                  ## 외부 App에서 사용되어도 좋은 라이브러리 \n|- vendor               ## 종속성 파일 관리 go mod vendor\n\n## Service Codes\n|- api                  ## Swagger / JSON Schema / 프로토콜 정의 파일\n|- web                  ## 웹 컴포넌트 / SPA 템플릿 =\u003e 서버만 사용한다면 필요없음\n|- configs              ## 설정 파일 / 기본설정\n|- build                ## build 결과물\n|- infra                ## 인프라 파일 ( Terraform / Ansible / CDK )\n|- utils                ## util 함수\n\nMakefile                ## 빌드 / 분석에 필요한 스크립트\n```\n\n## Panic 잘 사용하기\n\n- panic 자체는 Runtime 환경에서 위험한 놈 process.exit(1)\n- panic을 발생시키는 함수라면 Prefix에 \u003cb\u003eMust\u003c/b\u003e 를 붙혀야 함\n- 굳이 활용한다면, recovery를 활용하는 것이 좋음\n- defer는 함수 초반에 위치하게 하자...\n- panic 과 fatal의 차이를 명확하게 하자\n    - panic : stacktrace + stderr -\u003e 디버깅에 유용\n    - fatal : output (간결) -\u003e 간결한 로그\n\n```go\n// 해당 방식으로 운용하면 서비스 자체는 죽지 않음\n// 다만 아래와 같이 실행이 보장되지 않음\n// recovery 를 하긴하지만 false를 뱉음 (return이 수행되지 않음)\nfunc calculator() bool {\n\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\tfmt.Println(\"에러는 발생했지만, 뭐 상관하지 않아...\")\n\t\t}\n\t}()\n\n\tfmt.Println(add(10, 20)) // 정상 동작\n\tfmt.Println(MustMin(20, 10)) // 에러 발생 \n    // ------------------- 여기서 동작이 끝남 ------------------- return false\n\tfmt.Println(MustMin(10, 20)) // 동작하지 않음 XXXXXX\n\n\treturn true\n}\n\nfunc add(v1, v2 int) int {\n\n\treturn v1 + v2\n}\n\nfunc MustMin(v1, v2 int) int {\n\n\tif v1 \u003c v2 {\n\t\tpanic(\"v2 bigger than v1\")\n\t}\n\n\treturn v1 - v2\n}\n```\n\n```go\n// 중간에 미들웨어 역할을 하는 기능을 추가\n// processSafeCall\nfunc calculator() bool {\n\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\tfmt.Println(\"에러는 발생했지만, 뭐 상관하지 않아...\")\n\t\t}\n\t}()\nll\n\tfmt.Println(add(10, 20))\n\tprocessSafeCall(func() {\n\t\tfmt.Println(MustMin(20, 10))\n\t})\n\n\tprocessSafeCall(func() {\n\t\tfmt.Println(MustMin(10, 20))\n\t})\n\n\treturn true\n}\n\nfunc processSafeCall(fn func()) {\n\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\tfmt.Println(\"recover panic : \", r)\n\t\t}\n\t}()\n\n\tfn()\n}\n\nfunc add(v1, v2 int) int {\n\n\treturn v1 + v2\n}\n\nfunc MustMin(v1, v2 int) int {\n\n\tif v1 \u003c v2 {\n\t\tpanic(\"v2 bigger than v1\")\n\t}\n\n\treturn v1 - v2\n}\n```\n\n## 에러 잘 활용하기\n\n- Error을 그냥 내도 좋지만, StackTrace를 나타내게 구성하는 것이 좋음\n\n### 그냥 에러를 내고싶은 경우\n\n```go\nerr := fmt.Errorf(\"%s world\", \"hello\")\nfmt.Println(err)\n```\n\n### Stack Trace를 사용하고 싶을 경우\n\n- errors.wrap 같은 경우, 계속 쌓이면 가독성은 떨어지지만, 제일 쉽게 구현이 가능하다.\n\n```go\n\n// Install\n// go get github.com/pkg/errors\n\nfunc Test_errWithStack(t *testing.T) {\n\n\terr := func() error {\n\t\treturn func() error {\n\t\t\terr := errors.Wrap(ErrRecordNotFound, \"err-1\")\n\t\t\terr = errors.Wrap(err, \"err-2\")\n\t\t\terr = errors.Wrap(err, \"err-3\")\n\t\t\terr = errors.Wrap(err, \"err-4\")\n\t\t\terr = errors.Wrap(err, \"err-5\")\n\t\t\terr = errors.Wrap(err, \"err-6\")\n\t\t\treturn err\n\t\t}()\n\t}()\n\n\tfmt.Printf(\"%+v\\n\", err)\n}\n```\n\n### 에러 네이밍 컨벤션\n\n- 소문자로 진행\n- 마침표 X\n- 에러는 최대한 선언해서 사용하자\n\n```go\nvar (\n\tErrRecordNotFound = errors.New(\"record not found\")\n\tErrUnknown        = errors.New(\"unknown error\")\n)\n```\n\n### 에러 로깅\n- 핸들로 내부에서 발생한 에러는 인터셉터 혹은 미들웨어에 의해 로깅처리 진행\n- \u003cb\u003e로깅은 최대한 다른 로직에 맡기자\u003c/b\u003e\n\n## Slice / Map 선언\n\n- slice / map 에 추가될 아이템은 최대한 len, cap 을 설정하자\n\n```go\nids := make([]string, len(users))\nfor i, v := range users {\n\tids[i] = v.id\n}\n```\n\n## Golang 에서의 파라미터 주입\n\n- Golang에서는 옵셔널 파라미터가 없기때문에, GRPC 패턴으로 넣어줘야 함...\n\n```go\nNewAESCipher(key, WithGCM(nonce))\nNewAESCipher(key, WithEncoding(euckr))\n```\n\n## Tools / Lint / Lib\n\n- \u003ca href=\"https://golangci-lint.run/\"\u003e golang-lint \u003c/a\u003e\n\n```sh\n    ## install\n    brew install golangci-lint\n    brew upgrade golangci-lint\n\n    ## run\n    golangci-lint run                   ## ...\n    golangci-lint run ./...             ## directories\n    golangci-lint run dir1 dir2/...     ## directory\n    golangci-lint run file.go           ## file\n\n    ## .vscode setting\n    .vscode/settings.json\n```\n\n- \u003ca href=\"https://go.dev/doc/effective_go\"\u003e Effective Go \u003c/a\u003e\n- \u003ca href=\"https://thanos.io/tip/contributing/coding-style-guide.md/#wrap-errors-for-more-context-dont-repeat-failed--there\"\u003e Thanos Golang Code Convention \u003c/a\u003e\n- \u003ca href=\"https://github.com/uber-go/guide/blob/master/style.md#function-grouping-and-ordering\"\u003e 우버 코딩 가이드 \u003c/a\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzkfmapf123%2Fgo-coding-convention","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzkfmapf123%2Fgo-coding-convention","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzkfmapf123%2Fgo-coding-convention/lists"}