C.W.K.
Stream
Lesson 07 of 08 · published

Array of table — 반복 구조 항목

~10 min · toml, arrays-of-tables

Level 0평문
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

[[name]] 이중 대괄호 형태

Array of table 이 진짜 config 파일 고통 해결: '여러 필드 가진 구조화된 것들 리스트, 한 번에 하나씩 읽거나 편집하고 싶음'. 문법은 이중 대괄호: [[products]]. 파일의 모든 [[products]] block 이 products 배열에 한 요소 추가.

언제 잡나

  • 여러 필드 가진 항목 배열.
  • 개별 주석, 편집, grep 하고 싶은 항목.
  • Inline-table 배열이 너무 길어 읽기 어려운 곳.

[[]] vs [] 구분

[server] server table (단수) 열어. [[plugins]] 가 plugins 배열에 한 요소 추가. 각 [[plugins]] 가 자체 self-contained block; 소스 순서 = 배열 순서.

원칙: 의심되면, 'N 개 중 하나' 로 읽히는 구조는 이름으로 키 매겨진 table 의 table 아니라 array of table 이어야. 배열이 순서 보존; 리뷰어가 각 항목에 댓글 가능; 새 entry 가 깨끗하게 추가. YAML 과 비교 — 같은 아이디어, 덜 신뢰성 있는 diff.

Code

Array of table — 세 plugin·toml
[[plugins]]
name = "auth"
version = "1.2"
enabled = true

[[plugins]]
name = "rate-limit"
version = "0.4"
enabled = true
config = { window_sec = 60, max = 100 }

[[plugins]]
name = "experimental"
version = "0.1"
enabled = false
# perf regression 랜드까지 비활성화
# (#142 참고)
등가 inline-table 형태 (필드 많을 때 못생김)·toml
plugins = [
  { name = "auth",         version = "1.2", enabled = true },
  { name = "rate-limit",   version = "0.4", enabled = true,  config = { window_sec = 60, max = 100 } },
  { name = "experimental", version = "0.1", enabled = false },
]
# 2-3 짧은 필드엔 inline 형태; 항목 더 클 땐 [[plugins]].
중첩 array of table (Hugo 메뉴 패턴)·toml
[[menu.main]]
name = "Home"
url = "/"
weight = 1

[[menu.main]]
name = "Posts"
url = "/posts"
weight = 2

[[menu.main]]
name = "About"
url = "/about"
weight = 3

External links

Exercise

YAML list-of-object (CI job 리스트, webhook 리스트, route 리스트) 를 TOML array of table 로 변환. 파일을 tomllib.load 로 통과시키고 파싱된 모양이 dict 의 list 와 일치 확인. 두 형태에서 'entry 하나 추가' commit diff — TOML 의 노이즈 없는 diff 이김 봐야.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.