diff --git a/LICENSE b/LICENSE index bfac567..ea1d6f0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Yusuke Komatsu +Copyright (c) 2023 Yusuke Komatsu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 9a3d675..45d4484 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # easyindex-cli +`easyindex-cli` makes super easy to use Google Index API and IndexNow API!! + +![Demo](demo.gif) + +## index + - [preinstall](#preinstall) - [required](#required) - [install](#install) @@ -15,6 +21,7 @@ - [set quota](#set-quota-1) - [use csv](#use-csv) - [Google \& IndexNow](#google--indexnow) + - [Use as Golang package](#use-as-golang-package) - [Parameters](#parameters) - [common](#common) - [Google indexing API](#google-indexing-api) @@ -196,6 +203,10 @@ easyindex-cli publish --csv index.csv easyindex-cli.exe publish --csv index.csv ``` +### Use as Golang package + +ref. [core package](https://github.com/usk81/easyindex) + ## Parameters ### common diff --git a/commands/publish.go b/commands/publish.go index 22dbb5c..e464525 100644 --- a/commands/publish.go +++ b/commands/publish.go @@ -65,7 +65,7 @@ Total: {{.Total}} [errors] {{range $i, $v := .Google.Errors }} - [{{$v.NotificationType}}] {{$v.URL}} : {{$v.Reason.Error}} {{ end -}} -{{- end -}} +{{- end }} ` ) diff --git a/commands/publish_test.go b/commands/publish_test.go index 1eb8b3b..27210ea 100644 --- a/commands/publish_test.go +++ b/commands/publish_test.go @@ -62,6 +62,7 @@ Total: 2 [skips] - [URL_UPDATED] https://example.com/b70b060b-1997-428d-afa3-35868614500e : Not Found - [URL_UPDATED] https://example.com/fabc6b58-827e-4177-827d-a0ee55c8b435 : quota exceeded + `, wantErr: false, }, @@ -106,6 +107,7 @@ Total: 2 [errors] - [URL_UPDATED] https://example.com/b70b060b-1997-428d-afa3-35868614500e : Internal Server Error - [URL_UPDATED] https://example.com/fabc6b58-827e-4177-827d-a0ee55c8b435 : Internal Server Error + `, wantErr: false, }, diff --git a/demo.gif b/demo.gif new file mode 100644 index 0000000..f507215 Binary files /dev/null and b/demo.gif differ diff --git a/mock/google.go b/mock/google.go index c054e0f..7430f07 100644 --- a/mock/google.go +++ b/mock/google.go @@ -7,21 +7,21 @@ import ( ) type ( - PrecheckScenario func(request *google.PublishRequest) (skipReason error) - PublishScenario func(request google.PublishRequest) (skip bool, err error) + GooglePrecheckScenario func(request *google.PublishRequest) (skipReason error) + GooglePublishScenario func(request google.PublishRequest) (skip bool, err error) mockPublisherImpl struct { config google.Config - precheckScenario PrecheckScenario - publishScenario PublishScenario + precheckScenario GooglePrecheckScenario + publishScenario GooglePublishScenario quota int } ) func Publisher( config google.Config, - precheck PrecheckScenario, - publish PublishScenario, + precheck GooglePrecheckScenario, + publish GooglePublishScenario, ) google.Publisher { quota := 200 if config.Quota != nil && *config.Quota > 0 { diff --git a/mock/indexnow.go b/mock/indexnow.go new file mode 100644 index 0000000..b4c8078 --- /dev/null +++ b/mock/indexnow.go @@ -0,0 +1,55 @@ +package mock + +import ( + "context" + + "github.com/usk81/easyindex/indexnow" +) + +type ( + IndexNowPrecheckScenario func(request string) (skipReason error) + IndexNowSubmitScenario func(request indexnow.SubmitInput) (err error) + + mockSubmitterrImpl struct { + config indexnow.Config + precheckScenario IndexNowPrecheckScenario + submitScenario IndexNowSubmitScenario + quota int + } +) + +func Submitter( + config indexnow.Config, + precheck IndexNowPrecheckScenario, + submit IndexNowSubmitScenario, +) indexnow.Submitter { + quota := 10000 + if config.Quota != nil && *config.Quota > 0 { + quota = *config.Quota + } + + return &mockSubmitterrImpl{ + config: config, + precheckScenario: precheck, + submitScenario: submit, + quota: quota, + } +} + +func (m *mockSubmitterrImpl) Precheck(ctx context.Context, input []string) (requests []string, skips []indexnow.SkipedPublishRequest) { + for _, v := range input { + if skip := m.precheckScenario(v); skip != nil { + skips = append(skips, indexnow.SkipedPublishRequest{ + URL: v, + Reason: skip, + }) + } else { + requests = append(requests, v) + } + } + return +} + +func (m *mockSubmitterrImpl) Execute(input indexnow.SubmitInput) (err error) { + return m.submitScenario(input) +}