go

Cannot deploy sample GOLang application to Heroku

心已入冬 提交于 2021-02-07 07:32:11
问题 I tried deploying the sample GO application to Heroku listed here But when I run the command: git push heroku master I get the following error: Counting objects: 28, done. Compressing objects: 100% (21/21), done. Writing objects: 100% (28/28), 3.08 KiB, done. Total 28 (delta 6), reused 0 (delta 0) ! Heroku push rejected, no Cedar-supported app detected To git@heroku.com:mysterious-refuge-1227.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs

转 C++11 并发指南std::condition_variable详解

让人想犯罪 __ 提交于 2021-02-07 06:34:49
之前看过,但是一直没有怎么用就忘了,转一篇别人的文字记录下来 本文将介绍 C++11 标准中 <condition_variable> 头文件里面的类和相关函数。 <condition_variable > 头文件主要包含了与条件变量相关的类和函数。相关的类包括 std::condition_variable 和 std::condition_variable_any,还有枚举类型std::cv_status。另外还包括函数 std::notify_all_at_thread_exit(),下面分别介绍一下以上几种类型。 std::condition_variable 类介绍 std::condition_variable 是条件变量,更多有关条件变量的定义参考 维基百科 。 Linux 下使用 Pthread 库中的 pthread_cond_*() 函数提供了与条件变量相关的功能, Windows 则参考 MSDN 。 当 std::condition_variable 对象的某个 wait 函数被调用的时候,它使用 std::unique_lock(通过 std::mutex) 来锁住当前线程。当前线程会一直被阻塞,直到另外一个线程在相同的 std::condition_variable 对象上调用了 notification 函数来唤醒当前线程。 std:

How to pass data struct as parameter in golang

南楼画角 提交于 2021-02-07 06:05:46
问题 XML to Json package main import ( "encoding/json" "encoding/xml" "fmt" ) type Persons struct { Person []struct { Name string Age int } } type Places struct { Place []struct { Name string Country string } } type Parks struct { Park struct { Name []string Capacity []int } } const personXml = ` <Persons> <Person><Name>Koti</Name><Age>30</Age></Person> <Person><Name>Kanna</Name><Age>29</Age></Person> </Persons> ` const placeXml = ` <Places> <Place><Name>Chennai</Name><Country>India</Country><

How to use the kubernetes go-client to get the same Pod status info that kubectl gives

时光毁灭记忆、已成空白 提交于 2021-02-07 05:43:05
问题 Using the kubernetes go-client ( k8s.io/client-go/kubernetes ), I know how to get pod.Status and I find the pod.Status.Phase useful (docs). For example, I can output the Pod Status Phase of all Pods using this: ... api := clientset.CoreV1() pods, err := api.Pods("").List(metav1.ListOptions{}) for i, pod := range pods.Items { podstatusPhase := string(pod.Status.Phase) podCreationTime := pod.GetCreationTimestamp() age := time.Since(podCreationTime.Time).Round(time.Second) podInfo := fmt.Sprintf

Golang calling CUDA library

柔情痞子 提交于 2021-02-07 05:42:23
问题 I am trying to call a CUDA function from my Go code. I have the following three files. test.h: int test_add(void); test.cu: __global__ void add(int *a, int *b, int *c){ *c = *a + *b; } int test_add(void) { int a, b, c; // host copies of a, b, c int *d_a, *d_b, *d_c; // device copies of a, b, c int size = sizeof(int); // Allocate space for device copies of a, b, c cudaMalloc((void **)&d_a, size); cudaMalloc((void **)&d_b, size); cudaMalloc((void **)&d_c, size); // Setup input values a = 2; b =

Golang, a proper way to rewind file pointer

北城以北 提交于 2021-02-07 05:07:38
问题 package main import ( "bufio" "encoding/csv" "fmt" "io" "log" "os" ) func main() { data, err := os.Open("cc.csv") defer data.Close() if err != nil { log.Fatal(err) } s := bufio.NewScanner(data) for s.Scan() { fmt.Println(s.Text()) if err := s.Err(); err != nil { panic(err) } } // Is it a proper way? data.Seek(0, 0) r := csv.NewReader(data) for { if record, err := r.Read(); err == io.EOF { break } else if err != nil { log.Fatal(err) } else { fmt.Println(record) } } } I use two readers here to

Golang, a proper way to rewind file pointer

做~自己de王妃 提交于 2021-02-07 05:07:34
问题 package main import ( "bufio" "encoding/csv" "fmt" "io" "log" "os" ) func main() { data, err := os.Open("cc.csv") defer data.Close() if err != nil { log.Fatal(err) } s := bufio.NewScanner(data) for s.Scan() { fmt.Println(s.Text()) if err := s.Err(); err != nil { panic(err) } } // Is it a proper way? data.Seek(0, 0) r := csv.NewReader(data) for { if record, err := r.Read(); err == io.EOF { break } else if err != nil { log.Fatal(err) } else { fmt.Println(record) } } } I use two readers here to

Golang, a proper way to rewind file pointer

故事扮演 提交于 2021-02-07 05:06:23
问题 package main import ( "bufio" "encoding/csv" "fmt" "io" "log" "os" ) func main() { data, err := os.Open("cc.csv") defer data.Close() if err != nil { log.Fatal(err) } s := bufio.NewScanner(data) for s.Scan() { fmt.Println(s.Text()) if err := s.Err(); err != nil { panic(err) } } // Is it a proper way? data.Seek(0, 0) r := csv.NewReader(data) for { if record, err := r.Read(); err == io.EOF { break } else if err != nil { log.Fatal(err) } else { fmt.Println(record) } } } I use two readers here to

Why write bytes to files is slow for Go, compared with C

别来无恙 提交于 2021-02-07 04:19:26
问题 I just found that write bytes to files is slow for Go. I want to create a 10mb file. Go takes almost 1 min to do it, but it is less than 5 seconds in C. This is Go code: package main import ( "fmt" "os" ) func main() { f, _ := os.Create("./src/test/test.txt") count := int(1.024e7) for i := 0; i < count; i++ { f.Write([]byte{byte('a' + i%24)}) } f.Close() fmt.Println("ok") } And C: #include <stdio.h> int main() { FILE *fp=fopen("data.txt","w"); int size=1.024e7; for(int i=0;i<size;i++) putc('a

Why write bytes to files is slow for Go, compared with C

时光总嘲笑我的痴心妄想 提交于 2021-02-07 04:17:13
问题 I just found that write bytes to files is slow for Go. I want to create a 10mb file. Go takes almost 1 min to do it, but it is less than 5 seconds in C. This is Go code: package main import ( "fmt" "os" ) func main() { f, _ := os.Create("./src/test/test.txt") count := int(1.024e7) for i := 0; i < count; i++ { f.Write([]byte{byte('a' + i%24)}) } f.Close() fmt.Println("ok") } And C: #include <stdio.h> int main() { FILE *fp=fopen("data.txt","w"); int size=1.024e7; for(int i=0;i<size;i++) putc('a