go

What are Go's rules for comparing bytes with runes?

梦想与她 提交于 2020-12-25 03:58:33
问题 I've discovered the following peculiarity: b := "a"[0] r := 'a' fmt.Println(b == r) // Does not compile, cannot compare byte and rune fmt.Println("a"[0] == 'a') // Compiles and prints "true" How does this work? 回答1: This is an example of untyped constants. From the docs: Untyped boolean, numeric, and string constants may be used as operands wherever it is legal to use an operand of boolean, numeric, or string type, respectively. Except for shift operations, if the operands of a binary

What are Go's rules for comparing bytes with runes?

痞子三分冷 提交于 2020-12-25 03:58:26
问题 I've discovered the following peculiarity: b := "a"[0] r := 'a' fmt.Println(b == r) // Does not compile, cannot compare byte and rune fmt.Println("a"[0] == 'a') // Compiles and prints "true" How does this work? 回答1: This is an example of untyped constants. From the docs: Untyped boolean, numeric, and string constants may be used as operands wherever it is legal to use an operand of boolean, numeric, or string type, respectively. Except for shift operations, if the operands of a binary

What are Go's rules for comparing bytes with runes?

∥☆過路亽.° 提交于 2020-12-25 03:58:23
问题 I've discovered the following peculiarity: b := "a"[0] r := 'a' fmt.Println(b == r) // Does not compile, cannot compare byte and rune fmt.Println("a"[0] == 'a') // Compiles and prints "true" How does this work? 回答1: This is an example of untyped constants. From the docs: Untyped boolean, numeric, and string constants may be used as operands wherever it is legal to use an operand of boolean, numeric, or string type, respectively. Except for shift operations, if the operands of a binary

Why are C# structs immutable?

丶灬走出姿态 提交于 2020-12-25 03:24:43
Compiler Error CS1612 Cannot modify the return value of 'expression' because it is not a variable class Transform { public Point p { get ; set ; } public Point p2; public void ShowV() { Console.WriteLine(p.X + " ... " + p.Y); } } [Test] public void TestChuck() { Transform t = new Transform(); t.p.X = 1 ; t.p2.X = 2 ; t.ShowV(); Console.Read(); } t.p = new Point(); 这个可以,set可以工作。 但是get出来的是value Why are C# structs immutable? 问题 I was just curious to know why structs, strings etc are immutable? What is the reason for making them immutable and rest of the objects as mutable. What are the things

How does golang's garbage collector work when compiled?

懵懂的女人 提交于 2020-12-25 02:06:51
问题 I'm trying to understand how does golang's garbage collector work when the golang code is compiled and I guess when using go run as well. I figure go run is a little more straight forward and just runs the garbage collector along with the .go files you are running. But is the garbage collector compiled into the binaries as well when compiling to an executable? 回答1: The compiled object files do not contain any garbage collector "code". When a program is run with go run , the go command will

go runtime debug 小技巧

依然范特西╮ 提交于 2020-12-24 15:49:01
前言 本意是打算研究一下go程序的启动流程,然后就去网上搜索了一下入门教程。结果令我有点沮丧,搜到的几乎所有文章开篇都是通过 GDB 调试, 然后就是不同平台下的汇编代码。。。 这令我很不开心, 虽然C/C++应用很广泛, 但是我对它真的没啥兴趣啊, 对它相关的调试工具就更加不感冒了, 虽然它可以调试go程序, 但是总感觉心里少了点什么, 难道 dlv 它不香嘛, 于是就有了今天这篇文章。 dlv命令行debug dlv的名头应该不用我多说, 所以我们直奔主题 1. 开始debug dlv debug test.go 执行上述命令后, 就会进入debug交互命令行界面, 在这个界面任何时候输入 h 都会打印帮助信息. 2. 增加函数断点 交互界面输入下面命令后,会在main包下的main函数打上一个断点 b main.main 3. 指定行断点 在test.go的文件第6行打上一个断点 b test.go:6 4. 开始执行 如上图所示, 我们继续执行时会发现 => 会停留在我们前面标记的断点处。这里的其他命令我们在本篇文章不做过多的介绍了, 我们尽量紧扣本篇的主题。 5. 打印调用栈 如上图所示, 我们通过dlv的调用栈可以看见调用main函数之前,还执行了asm_amd64.s(本次debug的机器为mac)的汇编代码和proc.go的main函数。 意外之喜,

Prometheus入门

最后都变了- 提交于 2020-12-24 15:12:07
什么是TSDB? TSDB(Time Series Database)时序列数据库,我们可以简单的理解为一个优化后用来处理时间序列数据的软件,并且数据中的数组是由时间进行索引的。 时间序列数据库的特点 大部分时间都是写入操作。 写入操作几乎是顺序添加,大多数时候数据到达后都以时间排序。 写操作很少写入很久之前的数据,也很少更新数据。大多数情况在数据被采集到数秒或者数分钟后就会被写入数据库。 删除操作一般为区块删除,选定开始的历史时间并指定后续的区块。很少单独删除某个时间或者分开的随机时间的数据。 基本数据大,一般超过内存大小。一般选取的只是其一小部分且没有规律,缓存几乎不起任何作用。 读操作是十分典型的升序或者降序的顺序读。 高并发的读操作十分常见。 常见的时间序列数据库 TSDB项目 官网 influxDB https://influxdata.com/ RRDtool http://oss.oetiker.ch/rrdtool/ Graphite http://graphiteapp.org/ OpenTSDB http://opentsdb.net/ Kdb+ http://kx.com/ Druid http://druid.io/ KairosDB http://kairosdb.github.io/ Prometheus https://prometheus.io/

以太坊的 Gas 机制

给你一囗甜甜゛ 提交于 2020-12-24 09:01:32
以太坊对智能合约的影响是深刻的,即使不用以太坊,只要做智能合约开发,就避免不了要学一下以太坊。而学习以太坊的第一天就肯定会碰到的概念就是 Gas ,这个就是咱们今天的主角,理解了 Gas 机制也就基本理解的智能合约的工作原理了。文章中首先介绍以太坊的账户和交易,以便介绍清楚智能合约工作的基本上下文,或者说让大家理解 Gas 使用的场景,接下来聊聊 Gas 的工作原理,让大家理解为啥已经有了以太币还要有 Gas ,最后深入到细节聊聊 gasPrice 和 gasLimit 这些交易参数的实际作用。 账户和交易 先进入第一部分,聊聊以太坊账户的分类,以及通过在各个账户间发交易都能完成哪些工作。 以太坊账户其实是分两类的。一类是普通账户,也被称为外部拥有账户,因为账户的拥有者在以太坊系统本身之外,是自然人。普通账户就类似于比特币账户了,两个普通账户之间可以发交易,但是交易的功能就基本局限于转账了。但是以太坊上还能发一种特殊的交易,叫做合约创建交易,这种交易的特点就是只有发送方,没有接受方,同时发送交易的时候也伴随着有代码上传到区块链。这种交易一旦发出,就会在以太坊系统上创建一个新的账户。这就是我们要介绍的第二类账户了,叫做合约账户。合约账户跟普通账户的区别是,合约账户是以太坊系统所拥有的账户,或者说账户的拥有者是机器,而不是自然人。另外,合约账户最大的特点就是内置代码,你肯定能猜到

How to convert from an encoding to UTF-8 in Go?

萝らか妹 提交于 2020-12-24 08:41:31
问题 I'm working on a project where I need to convert text from an encoding (for example Windows-1256 Arabic) to UTF-8. How do I do this in Go? 回答1: You can use the encoding package, which includes support for Windows-1256 via the package golang.org/x/text/encoding/charmap (in the example below, import this package and use charmap.Windows1256 instead of japanese.ShiftJIS ). Here's a short example which encodes a japanese UTF-8 string to ShiftJIS encoding and then decodes the ShiftJIS string back

实验六

房东的猫 提交于 2020-12-24 08:37:07
1.编程实现:输入两个英文名字串,比较两个串的串长和串的大小,按要求输出结果。(比如,输入的两个名字串:Tom 与 Charli,输出结果为: 较长的串是 Charli, 较大的串是:Tom) 2.编程实现:输入一个长串 str1(比如“my heart will go on”),再输入一个短串str2(比如“ear”),判断在长串中是否有短串,比输出结果(按以上的情况查询,输出结果是在 str1 中有 str2) 3.编程实现:输入一行英文句子,按空格分出若干个单词,每一行只输出一个单词。 4.编写程序:输入一个字符串,分别统计字符串中大写字母和小写字母的个数。例如,给字符串 SS 输入:AaaaBBb123CCccccd,则输出结果应为:upper=5,lower=9. 5.编写程序:输入一个字符串(比如“abccdfefdf”),输入一个字符(比如‘d’),在串中查找并删除该字符; (1)若没找到,就输出提示信息“未找到此字符” (2)若找到,则提示“找到此字符,要删除吗?”,等待用户输入回答,若回答‘Y’则将其删除后并输出串,比如上结果为:abccfeff 6.编写程序找出一组单词中最小单词和最大单词。用户输入单词后,程序根据字典顺序决定排在最前面和最后面的单词。当用户输入 4 个字母的单词时,程序停止读入。假设所有单词都不超过 20 个字母。程序会话如下: Enter