Skip to content

Commit

Permalink
Merge pull request #17 from usk81/chore
Browse files Browse the repository at this point in the history
Chore
  • Loading branch information
usk81 authored Apr 7, 2023
2 parents d9f30fb + e573311 commit 62717e5
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# easyindex-cli <!-- omit in toc -->

`easyindex-cli` makes super easy to use Google Index API and IndexNow API!!

![Demo](demo.gif)

## index <!-- omit in toc -->

- [preinstall](#preinstall)
- [required](#required)
- [install](#install)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion commands/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Total: {{.Total}}
[errors]
{{range $i, $v := .Google.Errors }} - [{{$v.NotificationType}}] {{$v.URL}} : {{$v.Reason.Error}}
{{ end -}}
{{- end -}}
{{- end }}
`
)

Expand Down
2 changes: 2 additions & 0 deletions commands/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down
Binary file added demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions mock/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
55 changes: 55 additions & 0 deletions mock/indexnow.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 62717e5

Please sign in to comment.