{"id":"496a017e-317a-42eb-880e-ff710ebd0638","shortId":"zGgfLT","kind":"skill","title":"go-style-core","tagline":"Use when working with Go formatting, line length, nesting, naked returns, semicolons, or core style principles. Also use when a style question isn't covered by a more specific skill, even if the user doesn't reference a specific style rule. Does not cover domain-specific patterns","description":"# Go Style Core Principles\n\n## Style Principles (Priority Order)\n\nWhen writing readable Go code, apply these principles in order of importance:\n\n### Priority Order\n\n1. **Clarity** — Can a reader understand the code without extra context?\n2. **Simplicity** — Is this the simplest way to accomplish the goal?\n3. **Concision** — Does every line earn its place?\n4. **Maintainability** — Will this be easy to modify later?\n5. **Consistency** — Does it match surrounding code and project conventions?\n\n> Read [references/PRINCIPLES.md](references/PRINCIPLES.md) when resolving conflicts between clarity, simplicity, and concision, or when you need concrete examples of how each principle applies in real Go code.\n\n---\n\n## Formatting\n\nRun `gofmt` — no exceptions. There is **no rigid line length limit**, but Uber suggests a soft limit of 99 characters. Break by semantics, not length — refactor rather than just wrap.\n\n> Read [references/FORMATTING.md](references/FORMATTING.md) when configuring gofmt, deciding on line breaks, applying MixedCaps rules, or resolving local consistency questions.\n\n---\n\n## Reduce Nesting\n\nHandle error cases and special conditions first. Return early or continue the loop to keep the \"happy path\" unindented.\n\n```go\n// Bad: Deeply nested\nfor _, v := range data {\n    if v.F1 == 1 {\n        v = process(v)\n        if err := v.Call(); err == nil {\n            v.Send()\n        } else {\n            return err\n        }\n    } else {\n        log.Printf(\"Invalid v: %v\", v)\n    }\n}\n\n// Good: Flat structure with early returns\nfor _, v := range data {\n    if v.F1 != 1 {\n        log.Printf(\"Invalid v: %v\", v)\n        continue\n    }\n\n    v = process(v)\n    if err := v.Call(); err != nil {\n        return err\n    }\n    v.Send()\n}\n```\n\n### Unnecessary Else\n\nIf a variable is set in both branches of an if, use default + override pattern.\n\n```go\n// Bad: Setting in both branches\nvar a int\nif b {\n    a = 100\n} else {\n    a = 10\n}\n\n// Good: Default + override\na := 10\nif b {\n    a = 100\n}\n```\n\n---\n\n## Naked Returns\n\nA `return` statement without arguments returns the named return values. This is\nknown as a \"naked\" return.\n\n```go\nfunc split(sum int) (x, y int) {\n    x = sum * 4 / 9\n    y = sum - x\n    return // returns x, y\n}\n```\n\n### Guidelines for Naked Returns\n\n- **OK in small functions**: Naked returns are fine in functions that are just a\n  handful of lines\n- **Be explicit in medium+ functions**: Once a function grows to medium size, be\n  explicit with return values for clarity\n- **Don't name results just for naked returns**: Clarity of documentation is\n  always more important than saving a line or two\n\n```go\n// Good: Small function, naked return is clear\nfunc minMax(a, b int) (min, max int) {\n    if a < b {\n        min, max = a, b\n    } else {\n        min, max = b, a\n    }\n    return\n}\n\n// Good: Larger function, explicit return\nfunc processData(data []byte) (result []byte, err error) {\n    result = make([]byte, 0, len(data))\n\n    for _, b := range data {\n        if b == 0 {\n            return nil, errors.New(\"null byte in data\")\n        }\n        result = append(result, transform(b))\n    }\n\n    return result, nil // explicit: clearer in longer functions\n}\n```\n\nSee **go-documentation** for guidance on Named Result Parameters.\n\n---\n\n## Semicolons\n\nGo's lexer automatically inserts semicolons after any line whose last token is\nan identifier, literal, or one of: `break continue fallthrough return ++ -- ) }`.\n\nThis means **opening braces must be on the same line** as the control structure:\n\n```go\n// Good: brace on same line\nif i < f() {\n    g()\n}\n\n// Bad: brace on next line — lexer inserts semicolon after f()\nif i < f()  // wrong!\n{           // wrong!\n    g()\n}\n```\n\nIdiomatic Go only has explicit semicolons in `for` loop clauses and to separate\nmultiple statements on a single line.\n\n---\n\n## Quick Reference\n\n| Principle | Key Question |\n|-----------|--------------|\n| Clarity | Can a reader understand what and why? |\n| Simplicity | Is this the simplest approach? |\n| Concision | Is the signal-to-noise ratio high? |\n| Maintainability | Can this be safely modified later? |\n| Consistency | Does this match surrounding code? |\n\n## Related Skills\n\n- **Naming conventions**: See [go-naming](../go-naming/SKILL.md) when applying MixedCaps, choosing identifier names, or resolving naming debates\n- **Error flow**: See [go-error-handling](../go-error-handling/SKILL.md) when structuring error-first guard clauses or reducing nesting via early returns\n- **Documentation**: See [go-documentation](../go-documentation/SKILL.md) when writing doc comments, named return parameters, or package-level docs\n- **Linting enforcement**: See [go-linting](../go-linting/SKILL.md) when automating style checks with golangci-lint or configuring CI\n- **Code review**: See [go-code-review](../go-code-review/SKILL.md) when applying style principles during a systematic code review\n- **Logging style**: See [go-logging](../go-logging/SKILL.md) when reviewing logging practices, choosing between log and slog, or structuring log output","tags":["style","core","golang","skills","cxuu","agent-skills","ai-agent","ai-assistant","claude","claude-code","codex","cursor"],"capabilities":["skill","source-cxuu","skill-go-style-core","topic-agent-skills","topic-ai-agent","topic-ai-assistant","topic-claude","topic-claude-code","topic-codex","topic-cursor","topic-golang","topic-llm"],"categories":["golang-skills"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/cxuu/golang-skills/go-style-core","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add cxuu/golang-skills","source_repo":"https://github.com/cxuu/golang-skills","install_from":"skills.sh"}},"qualityScore":"0.491","qualityRationale":"deterministic score 0.49 from registry signals: · indexed on github topic:agent-skills · 82 github stars · SKILL.md body (5,062 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-02T12:55:19.048Z","embedding":null,"createdAt":"2026-04-18T22:13:21.158Z","updatedAt":"2026-05-02T12:55:19.048Z","lastSeenAt":"2026-05-02T12:55:19.048Z","tsv":"'/go-code-review/skill.md':712 '/go-documentation/skill.md':674 '/go-error-handling/skill.md':655 '/go-linting/skill.md':693 '/go-logging/skill.md':728 '/go-naming/skill.md':637 '0':465,474 '1':75,230,261 '10':311,316 '100':308,320 '2':86 '3':97 '4':105,350 '5':114 '9':351 '99':169 'accomplish':94 'also':21 'alway':411 'append':483 'appli':66,145,191,639,714 'approach':606 'argument':327 'autom':695 'automat':509 'b':306,318,431,438,442,446,469,473,486 'bad':221,297,553 'brace':532,545,554 'branch':288,301 'break':171,190,525 'byte':457,459,464,479 'case':203 'charact':170 'check':697 'choos':641,733 'ci':704 'clariti':76,131,398,407,593 'claus':578,662 'clear':427 'clearer':491 'code':65,82,120,149,628,705,710,720 'comment':678 'concis':98,134,607 'concret':139 'condit':206 'configur':185,703 'conflict':129 'consist':115,197,623 'context':85 'continu':211,267,526 'control':541 'convent':123,632 'core':4,18,55 'cover':29,48 'data':227,258,456,467,471,481 'debat':647 'decid':187 'deepli':222 'default':293,313 'doc':677,686 'document':409,498,669,673 'doesn':39 'domain':50 'domain-specif':49 'earli':209,253,667 'earn':102 'easi':110 'els':240,243,280,309,443 'enforc':688 'err':235,237,242,272,274,277,460 'error':202,461,648,653,659 'error-first':658 'errors.new':477 'even':35 'everi':100 'exampl':140 'except':154 'explicit':381,393,452,490,573 'extra':84 'f':551,562,565 'fallthrough':527 'fine':370 'first':207,660 'flat':250 'flow':649 'format':10,150 'func':341,428,454 'function':366,372,384,387,423,451,494 'g':552,568 'go':2,9,53,64,148,220,296,340,420,497,506,543,570,635,652,672,691,709,726 'go-code-review':708 'go-document':496,671 'go-error-handl':651 'go-lint':690 'go-log':725 'go-nam':634 'go-style-cor':1 'goal':96 'gofmt':152,186 'golangci':700 'golangci-lint':699 'good':249,312,421,449,544 'grow':388 'guard':661 'guidanc':500 'guidelin':359 'hand':377 'handl':201,654 'happi':217 'high':615 'identifi':520,642 'idiomat':569 'import':72,413 'insert':510,559 'int':304,344,347,432,435 'invalid':245,263 'isn':27 'keep':215 'key':591 'known':335 'larger':450 'last':516 'later':113,622 'len':466 'length':12,160,175 'level':685 'lexer':508,558 'limit':161,167 'line':11,101,159,189,379,417,514,538,548,557,587 'lint':687,692,701 'liter':521 'local':196 'log':722,727,731,735,740 'log.printf':244,262 'longer':493 'loop':213,577 'maintain':106,616 'make':463 'match':118,626 'max':434,440,445 'mean':530 'medium':383,390 'min':433,439,444 'minmax':429 'mixedcap':192,640 'modifi':112,621 'multipl':582 'must':533 'nake':14,321,338,361,367,405,424 'name':330,401,502,631,636,643,646,679 'need':138 'nest':13,200,223,665 'next':556 'nil':238,275,476,489 'nois':613 'null':478 'ok':363 'one':523 'open':531 'order':60,70,74 'output':741 'overrid':294,314 'packag':684 'package-level':683 'paramet':504,681 'path':218 'pattern':52,295 'place':104 'practic':732 'principl':20,56,58,68,144,590,716 'prioriti':59,73 'process':232,269 'processdata':455 'project':122 'question':26,198,592 'quick':588 'rang':226,257,470 'rather':177 'ratio':614 'read':124,181 'readabl':63 'reader':79,596 'real':147 'reduc':199,664 'refactor':176 'refer':41,589 'references/formatting.md':182,183 'references/principles.md':125,126 'relat':629 'resolv':128,195,645 'result':402,458,462,482,484,488,503 'return':15,208,241,254,276,322,324,328,331,339,355,356,362,368,395,406,425,448,453,475,487,528,668,680 'review':706,711,721,730 'rigid':158 'rule':45,193 'run':151 'safe':620 'save':415 'see':495,633,650,670,689,707,724 'semant':173 'semicolon':16,505,511,560,574 'separ':581 'set':285,298 'signal':611 'signal-to-nois':610 'simplest':91,605 'simplic':87,132,601 'singl':586 'size':391 'skill':34,630 'skill-go-style-core' 'slog':737 'small':365,422 'soft':166 'source-cxuu' 'special':205 'specif':33,43,51 'split':342 'statement':325,583 'structur':251,542,657,739 'style':3,19,25,44,54,57,696,715,723 'suggest':164 'sum':343,349,353 'surround':119,627 'systemat':719 'token':517 'topic-agent-skills' 'topic-ai-agent' 'topic-ai-assistant' 'topic-claude' 'topic-claude-code' 'topic-codex' 'topic-cursor' 'topic-golang' 'topic-llm' 'transform':485 'two':419 'uber':163 'understand':80,597 'unind':219 'unnecessari':279 'use':5,22,292 'user':38 'v':225,231,233,246,247,248,256,264,265,266,268,270 'v.call':236,273 'v.f1':229,260 'v.send':239,278 'valu':332,396 'var':302 'variabl':283 'via':666 'way':92 'whose':515 'without':83,326 'work':7 'wrap':180 'write':62,676 'wrong':566,567 'x':345,348,354,357 'y':346,352,358","prices":[{"id":"3efbc714-78b1-48b7-af08-95eab7660132","listingId":"496a017e-317a-42eb-880e-ff710ebd0638","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"cxuu","category":"golang-skills","install_from":"skills.sh"},"createdAt":"2026-04-18T22:13:21.158Z"}],"sources":[{"listingId":"496a017e-317a-42eb-880e-ff710ebd0638","source":"github","sourceId":"cxuu/golang-skills/go-style-core","sourceUrl":"https://github.com/cxuu/golang-skills/tree/main/skills/go-style-core","isPrimary":false,"firstSeenAt":"2026-04-18T22:13:21.158Z","lastSeenAt":"2026-05-02T12:55:19.048Z"}],"details":{"listingId":"496a017e-317a-42eb-880e-ff710ebd0638","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"cxuu","slug":"go-style-core","github":{"repo":"cxuu/golang-skills","stars":82,"topics":["agent-skills","ai-agent","ai-assistant","claude","claude-code","codex","cursor","go","golang","llm"],"license":"apache-2.0","html_url":"https://github.com/cxuu/golang-skills","pushed_at":"2026-03-15T19:32:10Z","description":"AI Agent Skills for idiomatic, production-ready Go code, distilled from Google, Uber, Community","skill_md_sha":"045d2fc3b322a067140adc4e1b7ba388240c4ba5","skill_md_path":"skills/go-style-core/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/cxuu/golang-skills/tree/main/skills/go-style-core"},"layout":"multi","source":"github","category":"golang-skills","frontmatter":{"name":"go-style-core","license":"Apache-2.0","description":"Use when working with Go formatting, line length, nesting, naked returns, semicolons, or core style principles. Also use when a style question isn't covered by a more specific skill, even if the user doesn't reference a specific style rule. Does not cover domain-specific patterns like error handling, naming, or testing (see specialized skills). Acts as fallback when no more specific style skill applies."},"skills_sh_url":"https://skills.sh/cxuu/golang-skills/go-style-core"},"updatedAt":"2026-05-02T12:55:19.048Z"}}