如何在Tarantool Cartridge角色的`init`函数中获取自定义选项? [英] How I can to get custom options in the `init` function of the Tarantool Cartridge role?

查看:56
本文介绍了如何在Tarantool Cartridge角色的`init`函数中获取自定义选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Tarantool弹药筒角色文件具有功能 init .

A Tarantool Cartridge role file has a function init.

我想从 instance.yml 文件获取我的自定义选项.但是 opts 变量没有该变量.

I want to get my custom options from the instance.yml file. But the opts variable doesn't have it.

我该怎么做?

推荐答案

墨盒具有一个内置模块,称为"argparse".它解析了一些配置源并将它们组合在一起:

Cartridge has a built-in module called "argparse". It parses a few sources of configuration and combines them together:

  • instances.yml或/etc/tarantool/conf.d
  • 中的文件
  • 命令行参数
  • 以TARANTOOL_开头的环境变量

墨盒使用此模块来获取各种配置信息,例如端口号或允许的最大内存使用量.但是,只要不与内置参数发生冲突,它就不会阻止您在这些文件中放入所需的任何内容.

Cartridge uses this module to get various pieces of configuration like the port numbers or maximum allowed memory usage. But it doesn't stop you from putting anything you like in those files, as long as it doesn't clash with built-in parameters.

这就是您在init()中应该拥有的内容:

Here's what you chould have in your init():

local argparse = require('cartridge.argparse')

-- ...

local function init()
    local args = argparse.parse()

    log.info("My parameter: %s", args.my_parameter) -- use anything you want in place of my_parameter
end

这篇关于如何在Tarantool Cartridge角色的`init`函数中获取自定义选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆