2019年3月30日土曜日

開発環境

プログラミング言語Go (ADDISON-WESLEY PROFESSIONAL COMPUTING SERIES) (Alan A.A. Donovan(著)、Brian W. Kernighan(著)、柴田 芳樹(翻訳)、丸善出版)の第4章(コンポジット型)、4.5(JSON)、練習問題4.10の解答を求めてみる。

コード

package main

import (
 "fmt"
 "log"
 "os"
 "time"

 "gopl.io/ch4/github"
)

func main() {
 // 日本語のコメント
 result, err := github.SearchIssues(os.Args[1:])
 if err != nil {
  log.Fatal(err)
 }
 term1 := []string{}
 term2 := []string{}
 term3 := []string{}
 now := time.Now().Unix()
 for _, item := range result.Items {
  t := item.CreatedAt
  y, m, d := t.Date()
  s := fmt.Sprintf("#%-5d %9.9s %.55s(%04d-%02d-%02d)\n",
   item.Number, item.User.Login, item.Title, y, m, d)
  if t.AddDate(0, 1, 0).Unix() > now {
   term1 = append(term1, s)
  } else if t.AddDate(1, 0, 0).Unix() > now {
   term2 = append(term2, s)
  } else {
   term3 = append(term3, s)
  }
 }
 desc := []string{"一ヶ月未満", "一年未満", "一年以上"}
 terms := [][]string{term1, term2, term3}
 for i, d := range desc {
  fmt.Println(d)
  for _, s := range terms[i] {
   fmt.Print(s)
  }
 }
}

入出力結果(cmd(コマンドプロンプト)、Terminal)

C:\Users\...>go run sample10.go repo:golang/go is:open json decoder
一ヶ月未満
#30701 LouAdrien encoding/json: ignore tag "-" not working on embedded s(2019-03-09)
一年未満
#29688   sheerun proposal: encoding/json: add InputOffset to json decode(2019-01-11)
#29686   sheerun json: Add InputOffset for stream byte offset access(2019-01-11)
#30301     zelch encoding/xml: option to treat unknown fields as an erro(2019-02-18)
#29035    jaswdr proposal: encoding/json: add error var to compare  the (2018-11-30)
#28923     mvdan encoding/json: speed up the decoding scanner(2018-11-22)
#28143 Carpetsmo proposal: encoding/json: add "readonly" tag(2018-10-11)
#26946    deuill encoding/json: clarify what happens when unmarshaling i(2018-08-12)
#28189     adnsv encoding/json: confusing errors when unmarshaling custo(2018-10-13)
#27179  lavalamp encoding/json: no way to preserve the order of map keys(2018-08-23)
#28941     mvdan cmd/compile: teach prove about slice expressions(2018-11-25)
#28952     mvdan cmd/compile: consider teaching prove about unexported i(2018-11-26)
#25426 josharian cmd/compile: revisit statement boundaries CL peformance(2018-05-16)
一年以上
#11046     kurin encoding/json: Decoder internally buffers full input(2015-06-03)
#12001 lukescott encoding/json: Marshaler/Unmarshaler not stream friendl(2015-08-03)
#16212 josharian encoding/json: do all reflect work before decoding(2016-06-29)
#5901        rsc encoding/json: allow override type marshaling(2013-07-17)
#14750 cyberphon encoding/json: parser ignores the case of member names(2016-03-10)
#22752  buyology proposal: encoding/json: add access to the underlying d(2017-11-15)
#7872  extempora encoding/json: Encoder internally buffers full output(2014-04-26)
#7213  davechene cmd/compile: escape analysis oddity(2014-01-27)
#20528  jvshahid net/http: connection reuse does not work happily with n(2017-05-30)
#17609 nathanjsw encoding/json: ambiguous fields are marshalled(2016-10-26)
#19636 josselin- encoding/base64: decoding is slow(2017-03-21)
#20754       rsc encoding/xml: unmarshal only processes first XML elemen(2017-06-22)
#22816 ganelon13 encoding/json: include field name in unmarshal error me(2017-11-20)
#21092  trotha01 encoding/json: unmarshal into slice reuses element data(2017-07-19)
#15808 randall77 cmd/compile: loads/constants not lifted out of loop(2016-05-24)
#5819  gopherbot encoding/gob: encoder should ignore embedded structs wi(2013-06-30)
#20206 markdryan encoding/base64: encoding is slow(2017-05-02)

C:\Users\...>

0 コメント:

コメントを投稿

関連コンテンツ