TOML

Rust编程基础

时光总嘲笑我的痴心妄想 提交于 2020-02-26 11:14:51
编者注 由于需要一个编写库的语言,要求执行速度非常快,能够完整跨平台使用。由于商业项目对稳定性要求高,则尽量增加稳定性。其中的主要选择为C++20与Rust语言,但是由于C++20的语言特性并未在主流编译器上完整实现,且VC与Gcc等割裂也不是一天两天。则确认学习Rust语言。作为学习重点。至于为什么不选择Go,主要问题是Go的Gc无法控制,导致作为第三方库的运行失控。Dart由于无法创建动态连接库,落选。 Rust Rust介绍 https://www.rust-lang.org/ Rust:一个赋予有所构建可靠有效软件的开发语言。 为什么使用Rust? 性能 - Rust具有非常快的内存效能:没有运行时和垃圾回收,能够为关键性能服务提供支持,能够运行在嵌入式设备,能够轻松和其他语言集成 可靠 - Rust的丰富类型系统和所有权模型保证了内存安全性和线程安全性,并使您能够在编译时消除许多类的错误 生产 - Rust拥有出色的文档,友好的编译器和有用的错误消息,以及一流的工具-集成的软件包管理器和构建工具,具有自动完成和类型检查的智能多编辑器支持,自动格式化程序等 Rust构建 在2018年,Rust社区决定改善一些不同领域的编程体验(请参见2018路线图)。对于这些,您可以找到许多高质量的板条箱和一些很棒的入门指南。 Command Line - 借助Rust强大的生态系统

Telegraf tail with grok pattern error

旧时模样 提交于 2019-12-23 05:43:09
问题 I am using Telegraf to get logs information from Apache NiFi, for this task I am using this config: [[inputs.tail]] ## files to tail. files = ["/var/log/nifi/nifi-app.log"] ## Read file from beginning. from_beginning = true #name_override = "nifi_app" ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md data_format = "grok" grok_patterns = [ "%{DATE:date} %{TIME:time} %{WORD:EventType} \[%{GREEDYDATA:NifiTask} %{NOTSPACE:Thread}\] %{NOTSPACE:NifiEventType} %

Use variable language specific strings in hugo config file

女生的网名这么多〃 提交于 2019-12-11 04:26:57
问题 My goal is to build a multilingual site using hugo. For this I would like to: not touch the theme file have a config file which defines the overall structure for all languages (config.toml) have a "string" file for all languages So for example, I would have a config.toml file like this: [params.navigation] brand = "out-website" [params.navigation.links] about = $ABOUT_NAME services = $SERVICES_NAME team = $TEAM_NAME impressum = $IMPRESSUM_NAME a english language file: ABOUT_NAME=About

Deserialize TOML string to enum using config-rs

倖福魔咒の 提交于 2019-12-10 18:54:37
问题 I'm using config-rs to load the configuration from a TOML file and I want to deserialize a string to an enum. I tried to solve it using the deserialize_with feature of serde_derive but I don't know how to return a suitable Error to satisfy the function signature. How can I achieve it? My dependencies: config = "0.7" serde_derive = "1.0" serde = "1.0" toml = "0.4" Example code where it's intended to deserialize the enum RotationPolicyType : extern crate config; extern crate serde; #[macro_use]

(Go) How to use toml files?

自古美人都是妖i 提交于 2019-12-03 15:18:33
As title, I want to know how to use toml files from golang. Before that, I show my toml examples. Is it right? [datatitle] enable = true userids = [ "12345", "67890" ] [datatitle.12345] prop1 = 30 prop2 = 10 [datatitle.67890] prop1 = 30 prop2 = 10 And then, I want to set these data as type of struct. As a result I want to access child element as below. datatitle["12345"].prop1 datatitle["67890"].prop2 Thanks in advance! First get BurntSushi's toml parser: go get github.com/BurntSushi/toml BurntSushi parses toml and maps it to structs, which is what you want. Then execute the following example

Deserializing TOML into vector of enum with values

人走茶凉 提交于 2019-12-01 08:13:39
I'm trying to read a TOML file to create a struct that contains a vector of enums with associated values. Here's the sample code: extern crate serde; #[macro_use] extern crate serde_derive; extern crate toml; use std::fs::File; use std::io::Read; #[derive(Debug, Deserialize, PartialEq)] struct Actor { name: String, actions: Vec<Actions>, } #[derive(Debug, Deserialize, PartialEq)] enum Actions { Wait(usize), Move { x: usize, y: usize }, } fn main() { let input_file = "./sample_actor.toml"; let mut file = File::open(input_file).unwrap(); let mut file_content = String::new(); let _bytes_read =

Deserializing TOML into vector of enum with values

穿精又带淫゛_ 提交于 2019-12-01 07:42:35
问题 I'm trying to read a TOML file to create a struct that contains a vector of enums with associated values. Here's the sample code: extern crate serde; #[macro_use] extern crate serde_derive; extern crate toml; use std::fs::File; use std::io::Read; #[derive(Debug, Deserialize, PartialEq)] struct Actor { name: String, actions: Vec<Actions>, } #[derive(Debug, Deserialize, PartialEq)] enum Actions { Wait(usize), Move { x: usize, y: usize }, } fn main() { let input_file = "./sample_actor.toml"; let

给博客增加豆瓣观影和阅读

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 12:13:32
第一步 进入这个网站注册账号 布克牧为 ,填写豆瓣id,豆瓣id是9位数字,到豆瓣官网找即可 第二步 同步数据 第三步 使用,查看API说明 https://github.com/iMuFeng/bmdb/blob/master/README.md 把密钥换成自己的就行了 第三步 添加到自己得博客,我是用hugo搭建得blog,以hugo为例,添加两个menu,指向到生成的html就行 [[menu.main]] name = "观影" url = "/movie/" weight = 5 [[menu.main]] name = "阅读" url = "/book/" weight = 6 效果 总结 1.发现一个问题,豆瓣取消评价后,同步数据,观影数据还在,已反馈给作者,等待作者修复。</br> 2.另外使用chrome同步数据时,同步请求会出现canned问题,建议使用edge或其他浏览器。 来源: https://my.oschina.net/u/4218037/blog/3110687

golang同时使用命令行参数和配置文件

扶醉桌前 提交于 2019-11-29 03:42:46
golang同时使用命令行参数和配置文件 [toc] 之前使用过 spring-boot 框架,在配置参数传递上可以使用配置文件--applications.yml,也可以使用命令行参数来覆盖,用起来非常方便。那么golang有没有类似功能呢?经过一番研究发现并没有杀手级的第三方package,因此就有以下自己捣鼓出来的方法。 Config type Config struct{ Username string Password string } func (c *Config)Parse(){ flag.StringVar(&c.Username,"username",c.Username,"the username for login") flag.StringVar(&c.Password,"password",c.Password,"the password for login") flag.Parse() } func NewConfig() *Config{ return &Config{ Username:"default_user", Password:"default_password", } } 使用 package main import ( "os" "github.com/BurntSushi/toml" ) var config *Config func