go

云原生|KubeVela

不想你离开。 提交于 2021-01-29 09:55:23
在互联网与云计算技术发展的日新月异过去五年中,应用研发人员对效率与敏捷的极致追求,终于把业界带进了一个崭新的云原生时代。 而云原生理念的迅速普及,火了 Docker,红了 Kubernetes ,也间接让一个编程语言成为了如今服务端的“当家花旦”。 不消多讲,这位在云原生领域里正红的发紫的“角儿”,就是 Golang。 不过,正如同 “PHP 不一定是最好的编程语言”一样,Go 语言本身也不是“万能钥匙”。Go 语言之所以能够乘上云原生这趟高速列车,究其原因,更多是与它如下几个特质密切相关: 语法简单,容易上手 。云原生社区是一个对开源和贡献者非常看重的生态,这就使得很少需要纠结于语法细节的 Go 语言迅速成为了这个社区的“不二之选”。否则的话,云原生 CNCF 社区里大量项目都得忙着讨论这个指针那个引用,什么 Kubernetes CRD 之类的创新设计估计都得凉。 golang.org 库非常丰富 。咱们现代软件开发行业,讲究的就是“面向 library” 编程,谁没事儿都不会手撸一个 HTTP 框架或者并发库。开箱即用的库越多,咱研发效率就越高。在这一点上,Go 语言不仅有先天优势,而且雪球越滚越大,已然是云原生一霸了。 部署简单 。Go 语言项目开发完了,一个静态文件就可以运行了,特别适合直接扔在 Docker 里跑。大家可以想象一下如果 Kubernetes 是

Catch buffered stdout output of exec.Command

北城以北 提交于 2021-01-29 09:53:23
问题 I'm trying to catch output of external program. Example: #include <stdio.h> #include <unistd.h> #include <stddef.h> int main() { int i = 0; while(i < 10) { printf("i = %i\n", i++); usleep(2000000); } return 0; } And here is my main.go: package main import ( "bufio" "io" "log" "os/exec" ) func reecho(closer io.ReadCloser) { reader := bufio.NewReader(closer) for { s, e := reader.ReadString('\n') if e != nil { log.Println(e) break } log.Println(s) } } func main() { cmd := exec.Command(".

Converting negative numbers

五迷三道 提交于 2021-01-29 09:50:38
问题 When converting a negative number to an unsigned integer and later adding that value it results in subtracting. a := (uint8)(10) b := (int8)(-8) fmt.Println(a + (uint8)(b)) // result: 2 Is this an idiomatic approach or should it be done more explicitly? 回答1: Since the type is unsigned it is an overflow: uint8(b) is 248 , so a + uint8(b) is 10+248=258=256+2 => 2 my question is more about how to subtract from unsigned integers when the value (sometimes you want to add and sometimes subtract) is

Remove a field from a struct, transform a struct

守給你的承諾、 提交于 2021-01-29 09:41:59
问题 From the Google Drive API I get a struct type File. This struct is almost the same as the struct I would like to insert into BigQuery. The File struct contains an "AppProperties" field that is incompatible with BigQuery: AppProperties map[string]string `json:"appProperties,omitempty"` So the end result that I would like to have is the same struct, with the AppProperties field removed. So basically the question is "how to remove a field from a struct" but that does not make sense as the struct

multiple definition when using cgo

此生再无相见时 提交于 2021-01-29 09:24:12
问题 package main /* int add(int a, int b) { return a + b; } */ import "C" import "fmt" func main() {} func Test1() { fmt.Println(C.add(1, 3)) } //export Test2 func Test2() { } Compile the programe: dingrui@dingrui-PC:~/Projects/gotest/array$ go build -o libtest.so -buildmode=c-shared main.go # command-line-arguments /tmp/go-build043762604/b001/_x002.o: In function `add': ./main.go:5: multiple definition of `add' /tmp/go-build043762604/b001/_x001.o:/tmp/go-build/main.go:5: first defined here

Referencing a Go module that is local [duplicate]

随声附和 提交于 2021-01-29 09:14:55
问题 This question already has answers here : How to use a module that is outside of “GOPATH” in another module? (2 answers) Closed 1 year ago . I've been unsuccessful in importing a package from a local project (a Go module). Here is a brief of what I'm trying: I created a Go module package like so: $ cd $ mkdir mymodule $ cd mymodule $ go mod init github.com/Company/mymodule Then I added hello.go under the mymodule with a little function // mymodule/hello.go package mymodule func sayHello()

如果宁静是Oracle,那万茜,张雨绮,黄圣依 是什么?

风格不统一 提交于 2021-01-29 08:59:31
和姐姐们浪起来~ 嗯!这两天在看乘风破浪的姐姐(被逼) =_= 。。。好吧,其实我自己也看进去了。于是就有这样一个奇思妙想,如果把姐姐们比作计算机领域的 技术 or 工具,会是怎么样?于是自己就 yy 了一番。 宁静:Oracle,宁静以致远,江湖地位犹在。在大型企业里,通常拥有庞大的资金能力,所以它们会选择用钱购买解决方案,而不是自己雇佣人员使用 MySQL 去维护。在姐姐中,每人都有一个采访视频。主持人问现在圈内艺人分为一线,二线和三线,你觉得自己是几线?这个问题很犀利,大多数人可能会谦虚一番,宁静直言:我一直是一线。将静姐比作 oracle,当仁不让。 张雨绮:PHP,宇宙第一强无敌,舍我其谁。袁隆平曾经感慨:我这辈子最大的遗憾,就是让你们吃饱了撑着。于是,由于 PHP 入门门槛低,上手快,被吃瓜群众公认为语言界的 TOP1。而我们绮绮子,就更牛逼了,整个一个铁憨憨。 不过其实呢,绮绮子傻大姐,这次真的改变了我之前对其的印象(额,不对,我好像之前都没印象,毕竟我不咋看综艺)。虽说智商偶尔不在线,但她自己给自己创造一个世界,内心清晰而明朗。如同 PHP,内里乾坤,我自知。 万茜:Python,姐姐们的团宠。在一堆美女中,她像个帅气的男孩子,让每个姐姐感觉不到压力和竞争。不管你司是传统开发,大数据,又或者机器学习。嗯,你都会需要我。总而言之 “业务能力很强”。 万茜在开始表演时

Type conversion of a string read from stdin to int is giving me a 0

半世苍凉 提交于 2021-01-29 08:25:24
问题 Code: reader := bufio.NewReader(os.Stdin) fmt.Print("Enter a number") input,_ := reader.ReadString('\n') fmt.Printf("Type of the entered value is %T\n",input) fmt.Println(input) out,_ := strconv.Atoi(input) fmt.Printf("Type now is: %T\n", out) fmt.Printf("Value now is %d\n",out) fmt.Println(out) Complete beginner to Golang. I was trying to solve one of the problems from r/dailyprogrammer. I took the snippet to read the input from SO, as well as the strconv.Atoi function. The examples for this

How to safely load a hash, and convert a value to a boolean if it exists

醉酒当歌 提交于 2021-01-29 08:02:28
问题 I have a redis hash that has a key "has_ended" that I want to convert to a boolean value. someMap, _ := rv.redis.HGetAll(key).Result() // returns map[string]interface{} hasEnded := someMap["has_ended"] If the key "has_ended" isn't present in the map and I try to convert it to a boolean it will crash. How can I write this safely? 回答1: Assuming that you are using the popular github.com/go-redis/redis package, the return value from HGetAll(key).Result() is a map[string]string (doc). The

Go: build error when compiling unit tests (I'm trying to mock influxdb types)

一世执手 提交于 2021-01-29 08:00:50
问题 I'm just starting with go language. My mini-project successfully reads data from InfluxDB. Problem: when I import my package (which uses InfluxDB) into my unit test package, the build fails. "Production" code: package data import client "github.com/influxdata/influxdb1-client/v2" func FunctionToTest() {} // To make import necessary, unused for now func createClient() (client.Client, error) { return client.NewHTTPClient(client.HTTPConfig{Addr: addr}) } Unit test: package data_test import ( "..