jsonnet,就这么神奇

既然要玩kube-prometheus,

jsonnet,也附带着玩玩啦。。

https://jsonnet.org/learning/tutorial.html

我用的是Golang来玩的,不是C++版本的。

https://github.com/google/go-jsonnet

example.jsonnet

// A regular definition.
local house_rum = 'Banks Rum';

{
  // A definition next to fields.
  local pour = 1.5,

  Daiquiri: {
    ingredients: [
      { kind: house_rum, qty: pour },
      { kind: 'Lime', qty: 1 },
      { kind: 'Simple Syrup', qty: 0.5 },
    ],
    served: 'Straight Up',
  },
  Mojito: {
    ingredients: [
      {
        kind: 'Mint',
        action: 'muddle',
        qty: 6,
        unit: 'leaves',
      },
      { kind: house_rum, qty: pour },
      { kind: 'Lime', qty: 0.5 },
      { kind: 'Simple Syrup', qty: 0.5 },
      { kind: 'Soda', qty: 3 },
    ],
    garnish: 'Lime wedge',
    served: 'Over crushed ice',
  },
}

  

命令:

jsonnet.exe example.jsonnet

输出

扫描二维码关注公众号,回复: 9972508 查看本文章
{
   "Daiquiri": {
      "ingredients": [
         {
            "kind": "Banks Rum",
            "qty": 1.5
         },
         {
            "kind": "Lime",
            "qty": 1
         },
         {
            "kind": "Simple Syrup",
            "qty": 0.5
         }
      ],
      "served": "Straight Up"
   },
   "Mojito": {
      "garnish": "Lime wedge",
      "ingredients": [
         {
            "action": "muddle",
            "kind": "Mint",
            "qty": 6,
            "unit": "leaves"
         },
         {
            "kind": "Banks Rum",
            "qty": 1.5
         },
         {
            "kind": "Lime",
            "qty": 0.5
         },
         {
            "kind": "Simple Syrup",
            "qty": 0.5
         },
         {
            "kind": "Soda",
            "qty": 3
         }
      ],
      "served": "Over crushed ice"
   }
}

  

猜你喜欢

转载自www.cnblogs.com/aguncn/p/12527263.html