コンテンツにスキップ

YAML & プロジェクト構造

プロジェクトレイアウト、YAML定義ファイル、命名規則について説明します。

myapp/
├── .wippy.yaml # ランタイム設定
├── wippy.lock # ソースディレクトリ設定
├── .wippy/ # インストール済みモジュール
└── src/ # アプリケーションソース
├── _index.yaml # エントリ定義
├── api/
│ ├── _index.yaml
│ └── *.lua
└── workers/
├── _index.yaml
└── *.lua
YAML定義は起動時にレジストリにロードされます。レジストリが真のソースであり、YAMLファイルはそれを設定する一つの方法です。エントリは他のソースから来ることも、プログラムで作成することもできます。

versionnamespaceを持つYAMLファイルは有効です:

version: "1.0"
namespace: app.api
entries:
- name: get_user
kind: function.lua
meta:
comment: IDでユーザーを取得
source: file://get_user.lua
method: handler
modules:
- sql
- json
- name: get_user.endpoint
kind: http.endpoint
meta:
comment: ユーザーAPIエンドポイント
method: GET
path: /users/{id}
func: get_user
フィールド必須説明
versionはいスキーマバージョン(現在は"1.0"
namespaceはいこのファイルのエントリ名前空間
entriesはいエントリ定義の配列

意味的な区切りにはドット(.)を、単語の区切りにはアンダースコア(_)を使用します:

# 関数とそのエンドポイント
- name: get_user # 関数
- name: get_user.endpoint # そのHTTPエンドポイント
# 同じ関数に対する複数のエンドポイント
- name: list_orders
- name: list_orders.endpoint.get
- name: list_orders.endpoint.post
# ルーター
- name: api.public # パブリックAPIルーター
- name: api.admin # 管理者用APIルーター
パターン: base_name.variant - ドットは意味的な部分を区切り、アンダースコアはその部分内の単語を区切ります。

名前空間はドット区切りの識別子です:

app
app.api
app.api.v2
app.workers

エントリのフルIDは名前空間と名前を組み合わせます:app.api:get_user

wippy.lockファイルはWippyが定義をロードする場所を定義します:

directories:
modules: .wippy
src: ./src

WippyはこれらのディレクトリからYAMLファイルを再帰的にスキャンします。

各エントリはentries配列内に定義します。プロパティはルートレベルにあります(data:ラッパーなし):

entries:
- name: hello
kind: function.lua
meta:
comment: Hello Worldを返す
source: file://hello.lua
method: handler
modules:
- http
- json
- name: hello.endpoint
kind: http.endpoint
meta:
comment: Helloエンドポイント
method: GET
path: /hello
func: hello

UI向けの情報にはmetaを使用します:

- name: payment_handler
kind: function.lua
meta:
title: 決済プロセッサ
comment: Stripe決済を処理
source: file://payment.lua

規則:meta.titlemeta.commentは管理UIで適切にレンダリングされます。

アプリケーションレベルの設定にはregistry.entry種別を使用します:

- name: config
kind: registry.entry
meta:
title: アプリケーション設定
type: application
environment: production
features:
dark_mode: true
beta_access: false
種別目的
registry.entry汎用データ
function.lua呼び出し可能なLua関数
process.lua長時間実行プロセス
http.serviceHTTPサーバー
http.routerルートグループ
http.endpointHTTPハンドラ
process.hostプロセススーパーバイザ

完全なリファレンスはエントリ種別ガイドを参照してください。

プロジェクトルートのランタイム設定:

logger:
encoding: json
host:
worker_count: 16
http:
address: :8080

すべてのオプションについては設定ガイドを参照してください。

ソースディレクトリを定義します:

directories:
modules: .wippy
src: ./src

エントリはフルIDまたは相対名で参照できます:

# フルID(名前空間をまたぐ場合)
- name: main.router
kind: http.router
endpoints:
- app.api:get_user.endpoint
- app.api:list_orders.endpoint
# 同じ名前空間内 - 名前だけで参照
- name: get_user.endpoint
kind: http.endpoint
func: get_user
myapp/
├── .wippy.yaml
├── wippy.lock
└── src/
├── _index.yaml # namespace: app
├── api/
│ ├── _index.yaml # namespace: app.api
│ ├── users.lua
│ └── orders.lua
├── lib/
│ ├── _index.yaml # namespace: app.lib
│ └── database.lua
└── workers/
├── _index.yaml # namespace: app.workers
└── email_sender.lua