go

Generating identical random numbers in sequence after time seed? (Running on my machine)

心已入冬 提交于 2021-01-20 07:51:07
问题 I'm trying to understand precisely why, when called from an external function, my time seeded random number generator returns sequences of identical numbers. Minimal working example of issue: package main import ( "fmt" "math/rand" "time" ) //Generates random int as function of range func getRand(Range int) int { s1 := rand.NewSource(time.Now().UnixNano()) r1 := rand.New(s1) return r1.Intn(Range) } //Print 100 random ints between 0 and 100 func main() { for i := 0; i < 100; i++ { fmt.Print

Java微服务选型Dubbo V.S SpringCloud

烈酒焚心 提交于 2021-01-20 03:07:09
点击上方“ JavaEdge ”,关注公众号 设为“ 星标 ”,好文章不错过! RPC框架主要组成 通信框架 通信协议 序列化和反序列化格式 1 分类 RPC框架主要分为: 1.1 绑定语言平台 1.1.1 Dubbo 国内最早开源的RPC框架,由阿里巴巴公司开发并于2011年末对外开源,仅支持Java 架构 Consumer 服务消费者 Provider 服务提供者 Registry 注册中心 Monitor是监控系统 交互流程 Consumer 通过 Registry 获取到 Provider 节点 再通过Dubbo的客户端SDK与Provider建立连接,并发起调用 Provider 通过Dubbo的服务端SDK接收到 Consumer 请求 处理后再把结果返回给Consumer 服务消费者、提供者都需引入Dubbo的SDK才来完成RPC调用,因为Dubbo是用Java实现,所以要求服务消费者、提供者也都必须用Java。 主要实现 默认采用Netty作为通信框架 除了支持私有的Dubbo协议外,还支持RMI、Hession、HTTP、Thrift 支持多种序列化格式,比如Dubbo、Hession、JSON、Kryo、FST 1.1.2 Motan 微博内部使用的RPC框架,于2016年对外开源,仅支持Java。 架构 与Dubbo类似,都要在Client端(服务消费者

OSChina 周三乱弹 —— 可惜他不是个毛茸茸的小王八蛋

亡梦爱人 提交于 2021-01-20 01:59:46
Osc乱弹歌单(2020)请戳( 这里 ) 【今日歌曲】 @ 豹王冰冰 : #今日歌曲推荐# 《Let Me Down Slowly》Cyan Kicks。If you wanna go then I'll be so lonely 《Let Me Down Slowly》- Cyan Kicks 手机党少年们想听歌,请使劲儿戳( 这里 ) @ HandsomeBoy丶 :终于又下雪了 又又又下雪了, 这种天气实在不想起床, 穿着全副武装的出门, 不然就冻死了。 “猫 我会想念大熊的 狗 我也是,还好有他,我们才能熬过这个冬天。” 对了, 出门记得戴口罩。 @ 开源中国首席膨胀怪 :前天出门有事,忘带口罩,去药店买,结果药店说戴口罩才能进来。靠。 戴口罩有用么? 给你们科普一下吧。 带了口罩就可以上地铁了, @ 苗哥 :地铁上那个全程呱呱呱的上海大妈终于下车了,从我上车到她下车,全程都听到她呱呱呱的打电话,全程不带停的,整个车厢都是她带来的噪音污染…… 噪音污染是挺烦的, 那感觉就像, “我是谁呀?我在那儿啊?我脑瓜子嗡嗡的” 地铁上算什么, 几十分钟就到站了, 马上就要春运了, 你火车上遇到这样的人能听一路。 所以多准备个耳机, 关键时候救你一命, 现在就算在公司也没啥意思 心都飞了, 现在是放假状态, @ NakiFu :爸妈今天已经到家了 还有二十几天才放假的我

Golang: Parse all templates in directory and subdirectories?

血红的双手。 提交于 2021-01-19 22:54:24
问题 This is my directory structure: app/ template/ layout/ base.tmpl index.tmpl template.ParseGlob("*/*.tmpl") parses index.tmpl but not base.tmpl in the layout subdirectory. Is there a way to parse all templates recursively? 回答1: Not without implementing your own function to do it, I've been using something like this func ParseTemplates() *template.Template { templ := template.New("") err := filepath.Walk("./views", func(path string, info os.FileInfo, err error) error { if strings.Contains(path,

unexpected semicolon or newline before else even though there is neither before else if

不羁的心 提交于 2021-01-19 22:04:11
问题 I'm trying to fix these errors in my golang code and if someone could help me with that, I'd appreciate it. Here is my code: http://play.golang.org/p/yELWfIdWz5 Although, the one that is troubling me the most is the first one on line 21 where the error says: syntax error: unexpected semicolon or newline before else. I can't find a semicolon or new line on or just before line 21 at all. Also, what do the errors on line 28 and 32 mean ( non-declaration statement outside function body )-- those

unexpected semicolon or newline before else even though there is neither before else if

时光毁灭记忆、已成空白 提交于 2021-01-19 22:02:26
问题 I'm trying to fix these errors in my golang code and if someone could help me with that, I'd appreciate it. Here is my code: http://play.golang.org/p/yELWfIdWz5 Although, the one that is troubling me the most is the first one on line 21 where the error says: syntax error: unexpected semicolon or newline before else. I can't find a semicolon or new line on or just before line 21 at all. Also, what do the errors on line 28 and 32 mean ( non-declaration statement outside function body )-- those

unexpected semicolon or newline before else even though there is neither before else if

倾然丶 夕夏残阳落幕 提交于 2021-01-19 22:01:31
问题 I'm trying to fix these errors in my golang code and if someone could help me with that, I'd appreciate it. Here is my code: http://play.golang.org/p/yELWfIdWz5 Although, the one that is troubling me the most is the first one on line 21 where the error says: syntax error: unexpected semicolon or newline before else. I can't find a semicolon or new line on or just before line 21 at all. Also, what do the errors on line 28 and 32 mean ( non-declaration statement outside function body )-- those

unexpected semicolon or newline before else even though there is neither before else if

China☆狼群 提交于 2021-01-19 21:59:58
问题 I'm trying to fix these errors in my golang code and if someone could help me with that, I'd appreciate it. Here is my code: http://play.golang.org/p/yELWfIdWz5 Although, the one that is troubling me the most is the first one on line 21 where the error says: syntax error: unexpected semicolon or newline before else. I can't find a semicolon or new line on or just before line 21 at all. Also, what do the errors on line 28 and 32 mean ( non-declaration statement outside function body )-- those

RTMP协议互联网教育课堂直播点播系统EasyDSS获取直播信息优化设计方案介绍

家住魔仙堡 提交于 2021-01-19 18:15:54
EasyDSS视频平台我们讲过很多,EasyDSS相较于其他视频平台的特点是可以直播也可以点播,支持将视频文件上传或者推流桌面录屏等,该特点在很多教育行业课堂直播上发挥了作用。EasyDSS直播列表页面如下: 该页面主要获取10行数据,如果正在处于直播状态中,则显示对应的信息,前端网页主要发送 /live/list 请求到 Go 后台接口,Go 层收到请求后,收集信息返回到前端。目前的设计如下: 该处逻辑的调用顺序为: 前端发送 post 请求,获取一页 10 个数据:/live/list; Go 层收到请求,从数据库层获取对应的 10 个数据; 因为 Go 层不知道每个直播间对应的直播状态,因此需要向 C 层发送 http 请求,获取对应的 10 个数据的信息; Go 层每个数据都会向 C 层发送一次 http 请求。 Go 层收到 C 层直播结果后,将数据处理后返回给前端。 以上设计,在用户量不多的情况,问题不大,但是在数据量大的时候有以下缺点: 前端发送1次 http 请求,获取10个数据,Go层就要发送10次http请求到C层。如果有10个前端,那么Go层就会发送100次请求到 C 层,导致 Go 层和 C 层的压力都会非常大; 多个前端存在的情况下,有可能查询很多相同的数据,导致 Go 层向 C 层的请求有很多冗余存在。 针对以上缺点对该模块进行结构上的重新设计,如下图:

Go判断结构体类型是否为空(nil)

人走茶凉 提交于 2021-01-19 15:56:02
目录 前言 正文 前言 使用任何编程语言都会遇到判空的问题,那么Golang如何判空呢?说真的,这种方式我还是很意外的。 正文 说到Golang的判空机制,确实刷新了我的认知,多少有些丑 ^_^,特别是对于自定义的结构体类型,并不是简单的与 nil 做比较。 直接上代码: package main import ( "fmt" ) type Person struct { Name string Age int } func main() { var one Person one.Name = "xiaoming" one.Age = 12 var two Person if one != (Person{}) { fmt.Println(one.Name, "的年龄是", one.Age) } else { fmt.Println("the person is nil") } if two != (Person{}) { fmt.Println(two.Name, "的年龄是", two.Age) } else { fmt.Println("the person is nil") } // if two != nil { // fmt.Println(two.Name, "的年龄是", two.Age) // } else { // fmt.Println("the