Skip to content

Instantly share code, notes, and snippets.

@gkumarau
Last active January 18, 2019 01:28
Show Gist options
  • Save gkumarau/2d85fb59cbd3892c1f9689051cd37123 to your computer and use it in GitHub Desktop.
Save gkumarau/2d85fb59cbd3892c1f9689051cd37123 to your computer and use it in GitHub Desktop.
A simple example to demonstrate use of local variables in Jsonnet.
local host = '10.0.0.120'; // Standard local variable ends with semicolon(;).
local http_port = 8080;
{
local db_port = 3128, // A local variable next to JSON fields ends with comma(,).
app_protocol:: 'http', // A special hidden variable next to fields use (::) instead of (=) or (:).
environment_config: {
app: {
name: 'Sample app',
url: $.app_protocol + '://' + host + ':' + http_port + 'app/'
},
database: {
name: "mysql database",
username: "user",
password: "password",
host: host,
port: db_port,
},
rest_api: $.app_protocol + '://' + host + ':' + http_port + '/v2/api/'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment