-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
Jsonnet 이란?
JSON 을 확장한 템플릿 언어
- 오픈소스 (Apache 2.0)
- JSON 과 문법이 유사
- Reformatter, Linter 지원
- Editor & IDE 지원
- original implementation 과 go 언어 기반 implementation 이 있음
- JSON 과 Sonnet 의 합성어로 제이소넷으로 발음함
- Google 의 공식 제품은 아니며, 코드 소유권만 google 에게 있음
1. 객체지향적인 방식으로 중복 제거
input.jsonnet
{
corp1: {
name: "NAVER",
welcome: "Welcome to " + self.name + " Corp",
},
corp2: self.corp1 { name: "COUPANG" },
}output.json
{
"corp1": {
"name": "NAVER",
"welcome": "Welcome to NAVER Corp"
},
"corp2": {
"name": "COUPANG",
"welcome": "Welcome to COUPANG Corp"
}
}2. 함수 사용하기
input.jsonnet
local Corp(name='NAVER') = {
name: name,
welcome: 'Welcome to ' + name + ' Corp',
};
{
corp1: Corp(),
corp2: Corp('COUPANG'),
}output.json
{
"corp1": {
"name": "NAVER",
"welcome": "Welcome to NAVER Corp"
},
"corp2": {
"name": "COUPANG",
"welcome": "Welcome to COUPANG Corp"
}
}3. 기존 어플리케이션 및 커스텀 어플리케이션과 통합
input.jsonnet
local application = 'my-app';
local module = 'uwsgi_module';
local dir = '/var/www';
local permission = 644;
{
'uwsgi.ini': std.manifestIni({
sections: {
uwsgi: {
module: module,
pythonpath: dir,
socket: dir + '/uwsgi.sock',
'chmod-socket': permission,
callable: application,
logto: '/var/log/uwsgi/uwsgi.log',
},
},
}),
'init.sh': |||
#!/usr/bin/env bash
mkdir -p %(dir)s
touch %(dir)s/initialized
chmod %(perm)d %(dir)s/initialized
||| % {dir: dir, perm: permission},
'cassandra.conf': std.manifestYamlDoc({
cluster_name: application,
seed_provider: [
{
class_name: 'SimpleSeedProvider',
parameters: [{ seeds: '127.0.0.1' }],
},
],
}),
}uwsgi.ini
[uwsgi]
callable = my-app
chmod-socket = 644
logto = /var/log/uwsgi/uwsgi.log
module = uwsgi_module
pythonpath = /var/www
socket = /var/www/uwsgi.sockinit.sh
#!/usr/bin/env bash
mkdir -p /var/www
touch /var/www/initialized
chmod 644 /var/www/initializedcassandra.conf
"cluster_name": "my-app"
"seed_provider":
- "class_name": "SimpleSeedProvider"
"parameters":
- "seeds": "127.0.0.1"
참고
Reactions are currently unavailable