@kyanny's blog

My thoughts, my life. Views/opinions are my own.

2020-08-25から1日間の記事一覧

Go で chomp (末尾の改行文字を取り除く)

strings.TrimSuffix() を使う。 strings.TrimSuffix(s, "\n") s := " hello, world!\n" fmt.Printf("%#v\n", strings.TrimSuffix(s, "\n")) //=> " hello, world!" https://golang.org/pkg/strings/#TrimSuffix TrimRight() も \n だけを取り除くのであれば…

Go: json struct 大文字小文字

JSON and Go - The Go Blog The json package only accesses the exported fields of struct types (those that begin with an uppercase letter). Therefore only the the exported fields of a struct will be present in the JSON output. json.Marshal: …