diff --git a/Makefile b/Makefile index 4ca4ee1..984b2c8 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ deploy/theme: deploy/contents: $(MD_FILES) $(BZL) run //content/cmd/content -- deploy \ - --input $(PWD)/contents \ + --dir $(PWD)/contents \ --domain k9books.myshopify.com \ --key $(MARKDOWN_APP_KEY) \ --secret $(MARKDOWN_APP_SECRET) \ @@ -21,7 +21,7 @@ deploy/contents: $(MD_FILES) download/contents: $(MD_FILES) $(BZL) run //content/cmd/content -- download \ - --output $(PWD)/contents \ + --dir $(PWD)/contents \ --domain k9books.myshopify.com \ --key $(MARKDOWN_APP_KEY) \ --secret $(MARKDOWN_APP_SECRET) \ diff --git a/WORKSPACE b/WORKSPACE index 2a1b53b..a36ba08 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1178,8 +1178,8 @@ go_repository( go_repository( name = "in_gopkg_yaml_v2", importpath = "gopkg.in/yaml.v2", - sum = "h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=", - version = "v2.3.0", + sum = "h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=", + version = "v2.4.0", ) go_repository( diff --git a/config.yml b/config.yml index 6546104..c7d585b 100644 --- a/config.yml +++ b/config.yml @@ -2,3 +2,9 @@ development: password: ${THEME_APP_SECRET} theme_id: ${THEME_ID} store: k9books.myshopify.com +content: + domain: k9books.myshopify.com + key: ${MARKDOWN_APP_KEY} + secret: ${MARKDOWN_APP_SECRET} + token: ${MARKDOWN_APP_SECRET} + dir: ${PWD}/contents diff --git a/content/cmd/content/BUILD.bazel b/content/cmd/content/BUILD.bazel index acfa7cb..bc58551 100644 --- a/content/cmd/content/BUILD.bazel +++ b/content/cmd/content/BUILD.bazel @@ -8,6 +8,7 @@ go_library( deps = [ "//content:go_default_library", "@com_github_spf13_cobra//:go_default_library", + "@in_gopkg_yaml_v2//:go_default_library", ], ) diff --git a/content/cmd/content/main.go b/content/cmd/content/main.go index 19de200..67c44fb 100644 --- a/content/cmd/content/main.go +++ b/content/cmd/content/main.go @@ -2,12 +2,14 @@ package main import ( "fmt" + "io/ioutil" "log" "os" "github.com/kogai/k9bookshelf/content" "github.com/spf13/cobra" + "gopkg.in/yaml.v2" ) var rootCmd = &cobra.Command{ @@ -18,15 +20,68 @@ var rootCmd = &cobra.Command{ }, } +type configTy struct { + Content struct { + Domain *string `yaml:"domain,omitempty"` + Key *string `yaml:"key,omitempty"` + Secret *string `yaml:"secret,omitempty"` + Token *string `yaml:"token,omitempty"` + Dir *string `yaml:"dir,omitempty"` + } `yaml:"content,omitempty"` +} + var deployCmd = &cobra.Command{ Use: "deploy", Short: "Upload contents to store", Run: func(cmd *cobra.Command, args []string) { - input := cmd.Flag("input").Value.String() - shopDomain := cmd.Flag("domain").Value.String() - appKey := cmd.Flag("key").Value.String() - appSecret := cmd.Flag("secret").Value.String() - shopToken := cmd.Flag("token").Value.String() + var input, shopDomain, appKey, appSecret, shopToken string + + config := cmd.Flag("config").Value.String() + if config != "" { + buf, err := ioutil.ReadFile(config) + if err != nil { + log.Fatalln(err) + } + expanded := os.ExpandEnv(string(buf)) + var conf configTy + err = yaml.Unmarshal([]byte(expanded), &conf) + if err != nil { + log.Fatalln(err) + } + + if conf.Content.Domain != nil { + shopDomain = *conf.Content.Domain + } else { + shopDomain = cmd.Flag("domain").Value.String() + } + if conf.Content.Key != nil { + appKey = *conf.Content.Key + } else { + appKey = cmd.Flag("key").Value.String() + } + if conf.Content.Secret != nil { + appSecret = *conf.Content.Secret + } else { + appSecret = cmd.Flag("secret").Value.String() + } + if conf.Content.Token != nil { + shopToken = *conf.Content.Token + } else { + shopToken = cmd.Flag("token").Value.String() + } + if conf.Content.Dir != nil { + input = *conf.Content.Dir + } else { + input = cmd.Flag("dir").Value.String() + } + } else { + shopDomain = cmd.Flag("domain").Value.String() + appKey = cmd.Flag("key").Value.String() + appSecret = cmd.Flag("secret").Value.String() + shopToken = cmd.Flag("token").Value.String() + input = cmd.Flag("dir").Value.String() + } + if shopDomain == "" || appKey == "" || appSecret == "" || shopToken == "" { log.Fatalln(fmt.Sprintf("One of required parameter is empty, shopDomain='%s' appKey='%s' appSecret='%s' shopToken='%s'", shopDomain, appKey, appSecret, shopToken)) } @@ -41,11 +96,54 @@ var downloadCmd = &cobra.Command{ Use: "download", Short: "Download contents from store", Run: func(cmd *cobra.Command, args []string) { - output := cmd.Flag("output").Value.String() - shopDomain := cmd.Flag("domain").Value.String() - appKey := cmd.Flag("key").Value.String() - appSecret := cmd.Flag("secret").Value.String() - shopToken := cmd.Flag("token").Value.String() + var output, shopDomain, appKey, appSecret, shopToken string + + config := cmd.Flag("config").Value.String() + if config != "" { + buf, err := ioutil.ReadFile(config) + if err != nil { + log.Fatalln(err) + } + expanded := os.ExpandEnv(string(buf)) + var conf configTy + err = yaml.Unmarshal([]byte(expanded), &conf) + if err != nil { + log.Fatalln(err) + } + + if conf.Content.Domain != nil { + shopDomain = *conf.Content.Domain + } else { + shopDomain = cmd.Flag("domain").Value.String() + } + if conf.Content.Key != nil { + appKey = *conf.Content.Key + } else { + appKey = cmd.Flag("key").Value.String() + } + if conf.Content.Secret != nil { + appSecret = *conf.Content.Secret + } else { + appSecret = cmd.Flag("secret").Value.String() + } + if conf.Content.Token != nil { + shopToken = *conf.Content.Token + } else { + shopToken = cmd.Flag("token").Value.String() + } + if conf.Content.Dir != nil { + output = *conf.Content.Dir + } else { + output = cmd.Flag("dir").Value.String() + } + } else { + shopDomain = cmd.Flag("domain").Value.String() + appKey = cmd.Flag("key").Value.String() + appSecret = cmd.Flag("secret").Value.String() + shopToken = cmd.Flag("token").Value.String() + output = cmd.Flag("dir").Value.String() + } + if shopDomain == "" || appKey == "" || appSecret == "" || shopToken == "" { log.Fatalln(fmt.Sprintf("One of required parameter is empty, shopDomain='%s' appKey='%s' appSecret='%s' shopToken='%s'", shopDomain, appKey, appSecret, shopToken)) } @@ -62,17 +160,19 @@ func main() { log.Fatalln(err) } - downloadCmd.PersistentFlags().StringP("output", "o", fmt.Sprintf("%s", cwd), "output directory") + downloadCmd.PersistentFlags().StringP("dir", "d", fmt.Sprintf("%s", cwd), "directory where contents exists") downloadCmd.PersistentFlags().String("domain", "", "ShopDomain of your shop ex:your-shop.myshopify.com") downloadCmd.PersistentFlags().String("key", "", "Key of Admin API") downloadCmd.PersistentFlags().String("secret", "", "Secret of Admin API") downloadCmd.PersistentFlags().String("token", "", "AccessToken for Admin API generally same as secret if using Private App.") + downloadCmd.PersistentFlags().String("config", "", "configuration file which includes api key and so on") - deployCmd.PersistentFlags().StringP("input", "i", fmt.Sprintf("%s", cwd), "input directory") + deployCmd.PersistentFlags().StringP("dir", "d", fmt.Sprintf("%s", cwd), "directory where contents exists") deployCmd.PersistentFlags().String("domain", "", "ShopDomain of your shop ex:your-shop.myshopify.com") deployCmd.PersistentFlags().String("key", "", "Key of Admin API") deployCmd.PersistentFlags().String("secret", "", "Secret of Admin API") deployCmd.PersistentFlags().String("token", "", "AccessToken for Admin API generally same as secret if using Private App.") + deployCmd.PersistentFlags().String("config", "", "configuration file which includes api key and so on") rootCmd.AddCommand(downloadCmd) rootCmd.AddCommand(deployCmd) diff --git "a/contents/blogs/development/\345\225\206\345\223\201\343\203\207\343\203\274\343\202\277\343\202\204\343\203\226\343\203\255\343\202\260\343\201\252\343\201\251\343\202\222markdown\343\201\247\346\233\264\346\226\260\345\207\272\346\235\245\343\202\213\343\202\210\343\201\206\343\201\253\343\201\231\343\202\213.md" "b/contents/blogs/development/\345\225\206\345\223\201\343\203\207\343\203\274\343\202\277\343\202\204\343\203\226\343\203\255\343\202\260\343\201\252\343\201\251\343\202\222markdown\343\201\247\346\233\264\346\226\260\345\207\272\346\235\245\343\202\213\343\202\210\343\201\206\343\201\253\343\201\231\343\202\213.md" index aa94613..5d98532 100644 --- "a/contents/blogs/development/\345\225\206\345\223\201\343\203\207\343\203\274\343\202\277\343\202\204\343\203\226\343\203\255\343\202\260\343\201\252\343\201\251\343\202\222markdown\343\201\247\346\233\264\346\226\260\345\207\272\346\235\245\343\202\213\343\202\210\343\201\206\343\201\253\343\201\231\343\202\213.md" +++ "b/contents/blogs/development/\345\225\206\345\223\201\343\203\207\343\203\274\343\202\277\343\202\204\343\203\226\343\203\255\343\202\260\343\201\252\343\201\251\343\202\222markdown\343\201\247\346\233\264\346\226\260\345\207\272\346\235\245\343\202\213\343\202\210\343\201\206\343\201\253\343\201\231\343\202\213.md" @@ -12,7 +12,7 @@ 手元でコマンドを実行すると、ショップの管理画面のコンテンツが更新されている様子です。 -デモ動画 +![デモ動画](https://cdn.shopify.com/s/files/1/0512/0091/7703/files/2020-12-03_20.37.21_480x480.gif?v=1606995566) ## Shopifyでのコンテンツの編集について @@ -84,7 +84,7 @@ Shopify関係ないですね。 バイナリを [Releaseページ](https://github.com/kogai/k9bookshelf/releases) に置いておくので、良かったら試してみて下さい。 ------- +--- 次回は [ShoheiTai](https://qiita.com/ShoheiTai) さんの「Shopifyアプリの選定・運用ノウハウとか」です。 お楽しみに! diff --git "a/contents/blogs/development/\346\264\213\346\233\270\345\272\227\343\201\256\345\247\213\343\202\201\346\226\271.md" "b/contents/blogs/development/\346\264\213\346\233\270\345\272\227\343\201\256\345\247\213\343\202\201\346\226\271.md" index 2e939ee..f8a047f 100644 --- "a/contents/blogs/development/\346\264\213\346\233\270\345\272\227\343\201\256\345\247\213\343\202\201\346\226\271.md" +++ "b/contents/blogs/development/\346\264\213\346\233\270\345\272\227\343\201\256\345\247\213\343\202\201\346\226\271.md" @@ -4,7 +4,7 @@ 取次のオンラインサービスにアカウントを作成する -https://getstarted.ingramcontent.com +[https://getstarted.ingramcontent.com](https://getstarted.ingramcontent.com) ingramはアメリカの出版取次大手(トーハンみたいな感じ) @@ -16,14 +16,14 @@ ipageにアカウントを作成する 動画 -https://www.ingramcontent.com/retailers/ordering/ipage +[https://www.ingramcontent.com/retailers/ordering/ipage](https://www.ingramcontent.com/retailers/ordering/ipage) FAQ -https://www.ingramcontent.com/publishers/lp/introducingipage-faq +[https://www.ingramcontent.com/publishers/lp/introducingipage-faq](https://www.ingramcontent.com/publishers/lp/introducingipage-faq) 書誌情報がダウンロードできる 種類が多い -BISAC https://www2.archivists.org/groups/standards-committee/book-industry-standards-and-communications-bisac +BISAC [https://www2.archivists.org/groups/standards-committee/book-industry-standards-and-communications-bisac](https://www2.archivists.org/groups/standards-committee/book-industry-standards-and-communications-bisac) diff --git a/contents/products/distributed-services-with-go.md b/contents/products/distributed-services-with-go.md index 9de64ed..056f514 100644 --- a/contents/products/distributed-services-with-go.md +++ b/contents/products/distributed-services-with-go.md @@ -1,4 +1,5 @@ - Goでマイクロサービスの1サービス(ログサービス)を作っていく - 20年代のWeb開発入門として良いかも(UI層の話はないけど) - - もはや事業の最初期でも単一のサービスで構成されるアプリケーションはないと思う + + - もはや事業の最初期でも単一のサービスで構成されるアプリケーションはないと思う - 「分散システム」に期待して読み始めると、序盤は割合退屈かも diff --git a/go.mod b/go.mod index bcb36ad..819f97e 100644 --- a/go.mod +++ b/go.mod @@ -20,4 +20,5 @@ require ( golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect golang.org/x/tools v0.0.0-20201121010211-780cb80bd7fb // indirect gopkg.in/go-playground/assert.v1 v1.2.1 + gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index 9b87f9a..da54452 100644 --- a/go.sum +++ b/go.sum @@ -413,6 +413,8 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=