go

Read and merge two Yaml files

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-07 20:40:25
问题 Assuming we have two yaml files master.yaml someProperty: "someVaue" anotherProperty: "anotherValue" override.yaml someProperty: "overriddenVaue" Is it possible to unmarshall, merge, and then write those changes to a file without having to define a struct for every property in the yaml file? The master file has over 500 properties in it that are not at all important to the service at this point of execution, so ideally I'd be able to just unmarshal into a map, do a merge and write out in yaml

Read and merge two Yaml files

旧城冷巷雨未停 提交于 2021-02-07 20:38:20
问题 Assuming we have two yaml files master.yaml someProperty: "someVaue" anotherProperty: "anotherValue" override.yaml someProperty: "overriddenVaue" Is it possible to unmarshall, merge, and then write those changes to a file without having to define a struct for every property in the yaml file? The master file has over 500 properties in it that are not at all important to the service at this point of execution, so ideally I'd be able to just unmarshal into a map, do a merge and write out in yaml

Golang Build Constraints Random

我们两清 提交于 2021-02-07 20:36:14
问题 I have two go files with different build constraints in the header. constants_production.go: // +build production,!staging package main const ( URL = "production" ) constants_staging.go: // +build staging,!production package main const ( URL = "staging" ) main.go: package main func main() { fmt.Println(URL) } When I do a go install -tags "staging" , sometimes, it prints production ; Sometimes, it prints staging . Similarly, when I do go install -tags "production" ,... How do I get a

Golang Build Constraints Random

ⅰ亾dé卋堺 提交于 2021-02-07 20:34:53
问题 I have two go files with different build constraints in the header. constants_production.go: // +build production,!staging package main const ( URL = "production" ) constants_staging.go: // +build staging,!production package main const ( URL = "staging" ) main.go: package main func main() { fmt.Println(URL) } When I do a go install -tags "staging" , sometimes, it prints production ; Sometimes, it prints staging . Similarly, when I do go install -tags "production" ,... How do I get a

Why is time in Go printed differently in a struct?

断了今生、忘了曾经 提交于 2021-02-07 20:33:20
问题 I'm just starting out with Go, and in the first program I wrote I printed out a struct, which also showed {wall:0 ext:63533980800 loc:<nil>} Being puzzled over what that was it seemed to be a type time.Time() , and a google search brought me to this part of the Go source code in which the difference between the "wall clock" and the "monotonic clock" is explained in the comments. So to test it in isolation I created a new minimalistic program: package main import ( "fmt" "time" ) type

crypto/ssh ParsePublicKey “short read” error

ⅰ亾dé卋堺 提交于 2021-02-07 20:17:59
问题 In a program I am developing I need a way to add public keys into the authorized_keys file during development, so I am using command line arguments to do so. I have omitted most of the code, but if you would like to view all of the code, here is the repository, with the problem line being located in main.go on line 20. b, err := ioutil.ReadFile(os.Args[1]) if err != nil { log.Fatalf("Fatal error trying to read new public key file: %s", err) } newAuthorizedKey, err := ssh.ParsePublicKey(b) if

How to get environment variable PS1 by golang?

泄露秘密 提交于 2021-02-07 19:44:49
问题 PS1 is an environment variable for bash prompt. I can get this by echo $PS1 I try to use os.Getenv to get PS1 but returns nothing: package main import ( "fmt" "os" ) func main() { fmt.Println(os.Getenv("PS1")) } Why does this happen and how should I fix this? Thanks. 回答1: PS1 is probably not exported, meaning it won't show up in sub-processes of bash try export PS1 before you run your app you could also do PS1=$PS1 app to set it specifically in the sub process 来源: https://stackoverflow.com

Codeclimate test coverage formatter for Golang

只谈情不闲聊 提交于 2021-02-07 19:23:42
问题 Nowhere in Codeclimate docs written how to specify coverage formatter. But when I'm trying to send coverage to Codeclimate: ./cc-test-reporter before-build ./cc-test-reporter after-build It is failing: Error: could not find any viable formatter. available formatters: simplecov, lcov, coverage.py, clover, gocov, gcov, cobertura, jacoco I have gocov installed. Also I generated a report with goconv : gocov test -coverprofile=out And I tried to specify the report file to Codeclimate in various

Read a text file, replace its words, output to another text file

喜你入骨 提交于 2021-02-07 18:47:54
问题 So I am trying to make a program in GO to take a text file full of code and convert that into GO code and then save that file into a GO file or text file. I have been trying to figure out how to save the changes I made to the text file, but the only way I can see the changes is through a println statement because I am using strings.replace to search the string array that the text file is stored in and change each occurrence of a word that needs to be changed (ex. BEGIN -> { and END -> }). So

kubernetes client-go: convert labelselector to label string

ぃ、小莉子 提交于 2021-02-07 18:29:22
问题 In the kubernetes client-go API (or another library that uses it), is there a utility function to convert a k8s.io/apimachinery/pkg/apis/meta/v1/LabelSelector to a string to fill the field LabelSelector in k8s.io/apimachinery/pkg/apis/meta/v1/ListOptions ? I digged through the code of client-go but I can't find a function like that. The LabelSelector.Marshall() nor LabelSelector.String() give me that (unsurprisingly, because that's not their purpose, but I tried it anyway). Background I have