go

实验六

眉间皱痕 提交于 2020-12-29 00:59:31
1.编程实现:输入两个英文名字串,比较两个串的串长和串的大小,按要求输出结果。 (比如,输入的两个名字串:Tom 与 Charli,输出结果为: 较长的串是 Charli, 较 大的串是:Tom) #include<stdio.h> #include<stdlib.h> #include<string.h> #define STR_LEN 80 int main() { char s1[STR_LEN+1],s2[STR_LEN+1]; printf("first str:"); gets(s1); printf("second str:"); gets(s2); if(strlen(s1)>strlen(s2)){ printf("%s is the longer string.\n",s1); } else if(strlen(s1)<strlen(s2)){ printf("%s is the longer string.\n",s2); } else{ printf("%s and %s are same longer.\n",s1,s2); } if(strcmp(s1,s2)<0){ printf("%s is the largest string.\n",s2); } else if(strcmp(s1,s2)>0){ printf("%s is the

记一次 TCP 全队列溢出问题排查过程

半腔热情 提交于 2020-12-28 16:01:35
1. 前言 本文排查的问题是经典的TCP队列溢出问题,因TCP队列问题在操作系统层面没有明显的指标异常,容易被忽略,故把排查过程分享给大家。 2. 问题描述 A服务调用B服务接口超时,B服务主机IOWAIT高,具体超时情况分为两种: A服务的请求在B服务日志中可查到,但B服务的响应时间超过了A服务的等待超时时间3S。 A服务的请求在B服务日志中无法查到。 3. 问题分析 此种超时请求集中在很短的一段时间(通常在2分钟之内),过后便恢复正常,所以很难抓到问题现场分析原因,只能搭建测试环境,A服务持续请求B服务,在B服务主机上通过DD命令写入大量数据造成主机IOWAIT高,同时通过TCPDUMP在两端抓包分析。 部分服务超时日志: 服务A:Get http:// xxx &id=593930: net/http: request canceled (Client.Timeout exceeded while awaiting headers) 服务B: "GET xxx&id=593930 HTTP/1.1" 200 64 "-" "Go-http-client/1.1" "-" "-" 165000(单位微秒) 服务A发起请求3S后没有收到服务B响应,断开连接,服务B日志显示处理时长为0.165S,远低于3S,服务A侧看服务B的响应时间为网络传输时间

Codeforces 1099F

孤人 提交于 2020-12-28 08:04:56
题目链接: https://codeforces.com/problemset/problem/1099/F Mitya and Vasya are playing an interesting game. They have a rooted tree with $n$ vertices, and the vertices are indexed from $1$ to $n$. The root has index $1$. Every other vertex $i≥2$ has its parent $p_i$, and vertex $i$ is called a child of vertex $p_i$. There are some cookies in every vertex of the tree: there are $x_i$ cookies in vertex $i$. It takes exactly $t_i$ time for Mitya to eat one cookie in vertex $i$. There is also a chip, which is initially located in the root of the tree, and it takes $l_i$ time to move the chip along the

golang protobuf remove omitempty tag from generated json tags

青春壹個敷衍的年華 提交于 2020-12-28 07:04:45
问题 I am using google grpc with a json proxy. for some reason i need to remove the omitempty tags from the struct generated in the *.pb.go files. if i have a proto message like this message Status { int32 code = 1; string message = 2; } The generated struct looks like this type Status struct { Code int32 `protobuf:"varint,1,opt,name=code" json:"code,omitempty"` Message string `protobuf:"bytes,2,opt,name=message" json:"message,omitempty"` } But My need is to remove the omitempty tag from the

golang protobuf remove omitempty tag from generated json tags

浪子不回头ぞ 提交于 2020-12-28 06:56:28
问题 I am using google grpc with a json proxy. for some reason i need to remove the omitempty tags from the struct generated in the *.pb.go files. if i have a proto message like this message Status { int32 code = 1; string message = 2; } The generated struct looks like this type Status struct { Code int32 `protobuf:"varint,1,opt,name=code" json:"code,omitempty"` Message string `protobuf:"bytes,2,opt,name=message" json:"message,omitempty"` } But My need is to remove the omitempty tag from the

golang protobuf remove omitempty tag from generated json tags

烂漫一生 提交于 2020-12-28 06:50:27
问题 I am using google grpc with a json proxy. for some reason i need to remove the omitempty tags from the struct generated in the *.pb.go files. if i have a proto message like this message Status { int32 code = 1; string message = 2; } The generated struct looks like this type Status struct { Code int32 `protobuf:"varint,1,opt,name=code" json:"code,omitempty"` Message string `protobuf:"bytes,2,opt,name=message" json:"message,omitempty"` } But My need is to remove the omitempty tag from the

golang protobuf remove omitempty tag from generated json tags

我怕爱的太早我们不能终老 提交于 2020-12-28 06:47:31
问题 I am using google grpc with a json proxy. for some reason i need to remove the omitempty tags from the struct generated in the *.pb.go files. if i have a proto message like this message Status { int32 code = 1; string message = 2; } The generated struct looks like this type Status struct { Code int32 `protobuf:"varint,1,opt,name=code" json:"code,omitempty"` Message string `protobuf:"bytes,2,opt,name=message" json:"message,omitempty"` } But My need is to remove the omitempty tag from the

如何使用Go指定IP请求http(s)网址

旧街凉风 提交于 2020-12-28 02:54:22
我们公司产品是典型三层架构,前端是一个类似CDN的cache节点,后面挂着有N个proxy做高可用,proxy后面是真正的代码服务器,随着机器越来越多,偶尔会出现部分机器状态不一致而导致的问题,比较难以排查,比如:部分cache节点客户证书安装失败,导致客户反馈他们访问提示证书有问题,而我们无法重现。之前还遇到过,因为机房WAF更改规则,导致客户说访问网站提示域名未备案,于是我开发了这个小工具,开发后运维同事一使用,很快就找到了有问题的机房。 工具的使用非常简单,工具目录下新建一个requests.txt,填入如下信息: url:https://www.baidu.com/ user-agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36 header-output:1 body-output:1 cookie:BIDUPSID=xxxx; 202.108.22.5 180.101.49.11 双击exe文件即可。 简单介绍下工具的参数: url: 后面是需要请求的网址,这个参数是必填的 user-agent:可以自定义http Request UserAgent,可不填,默认是chrome的user

服务器端编程语言对比:C/C++, C#.NET, Java, Go, Rust

若如初见. 提交于 2020-12-28 01:23:30
对比指标 C/C++ C#.NET Java Go Rust 计算斐波那契数列第60个数字(循环实现) 计算斐波那契数列第10个数字(递归实现) uint16比特位的设置 uint16比特位的查找 自定义快速排序 自定义stack的pop/push 自定义链表的构建 自定义链表的查找 Protobuf消息编码 Protobuf消息解码 AES加密 AES解密 并发读写数据 格式化日志 申请48byte内存 自定义类型初始化 责任链方法调用 JSON编解码 内存直接拷贝 对象复制 字符串匹配 hashmap性能 自定义html解析 自定义html解析 获取当前时间戳 打印64k行日志 斐波那契数列三层调用处理(GRPC框架) 斐波那契数列三层调用处理(自定义框架) 来源: oschina 链接: https://my.oschina.net/u/4271269/blog/4845045

Go 编程模式:Go Generation

本秂侑毒 提交于 2020-12-27 08:49:04
在本篇文章中,我们将要学习一下Go语言的代码生成的玩法。Go语言代码生成主要还是用来解决编程泛型的问题,泛型编程主要解决的问题是因为静态类型语言有类型,所以,相关的算法或是对数据处理的程序会因为类型不同而需要复制一份,这样导致数据类型和算法功能耦合的问题。泛型编程可以解决这样的问题,就是说,在写代码的时候,不用关心处理数据的类型,只需要关心相当处理逻辑。泛型编程是静态语言中非常非常重要的特征,如果没有泛型,我们很难做到多态,也很难完成抽象,会导致我们的代码冗余量很大。 本文是全系列中第6 / 9篇: Go编程模式 Go编程模式:切片,接口,时间和性能 Go 编程模式:错误处理 Go 编程模式:Functional Options Go编程模式:委托和反转控制 Go编程模式:Map-Reduce Go 编程模式:Go Generation Go编程模式:修饰器 Go编程模式:Pipeline Go 编程模式:k8s Visitor 模式 « 上一篇文章 下一篇文章 » 目录 现实中的类比 Go语方的类型检查 Type Assert Reflection 它山之石 Go Generator 函数模板 函数生成脚本 生成代码 新版Filter 第三方工具 现实中的类比 举个现实当中的例子,用螺丝刀来做具比方,螺丝刀本来就是一个拧螺丝的动作,但是因为螺丝的类型太多,有平口的,有十字口的