Skip to content

Commit

Permalink
add SuppressFormatParameter for debugging endpoints
Browse files Browse the repository at this point in the history
use case: metha-sync -format epicur -no-intervals
-suppress-format-parameter http://123.45.12.34:1234/oai2
  • Loading branch information
miku committed Jul 21, 2016
1 parent 1069b5d commit 24a5828
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
2 changes: 2 additions & 0 deletions cmd/metha-sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func main() {
maxRequests := flag.Int("max", 65536, "maximum number of token loops")
disableSelectiveHarvesting := flag.Bool("no-intervals", false, "harvest in one go, for funny endpoints")
ignoreHTTPErrors := flag.Bool("ignore-http-errors", false, "do not stop on HTTP errors, just skip to the next interval")
suppressFormatParameter := flag.Bool("suppress-format-parameter", false, "do not send format parameter")
version := flag.Bool("v", false, "show version")

logFile := flag.String("log", "", "filename to log to")
Expand Down Expand Up @@ -67,6 +68,7 @@ func main() {
harvest.DisableSelectiveHarvesting = *disableSelectiveHarvesting
harvest.MaxEmptyResponses = 10
harvest.IgnoreHTTPErrors = *ignoreHTTPErrors
harvest.SuppressFormatParameter = *suppressFormatParameter

log.Printf("harvest: %+v", harvest)

Expand Down
14 changes: 8 additions & 6 deletions harvest.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Harvest struct {
CleanBeforeDecode bool
IgnoreHTTPErrors bool
MaxEmptyResponses int
SuppressFormatParameter bool

Identify *Identify
Started time.Time
Expand Down Expand Up @@ -271,12 +272,13 @@ func (h *Harvest) runInterval(iv Interval) error {

for {
req := Request{
BaseURL: h.BaseURL,
MetadataPrefix: h.Format,
Verb: "ListRecords",
Set: h.Set,
ResumptionToken: token,
CleanBeforeDecode: h.CleanBeforeDecode,
BaseURL: h.BaseURL,
MetadataPrefix: h.Format,
Verb: "ListRecords",
Set: h.Set,
ResumptionToken: token,
CleanBeforeDecode: h.CleanBeforeDecode,
SuppressFormatParameter: h.SuppressFormatParameter,
}

var filedate string
Expand Down
31 changes: 18 additions & 13 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ var (
// A Request can express any request, that can be sent to an OAI server. Not all
// combination of values will yield valid requests.
type Request struct {
BaseURL string
Verb string
Identifier string
MetadataPrefix string
From string
Until string
Set string
ResumptionToken string
CleanBeforeDecode bool
BaseURL string
Verb string
Identifier string
MetadataPrefix string
From string
Until string
Set string
ResumptionToken string
CleanBeforeDecode bool
SuppressFormatParameter bool
}

type Values struct {
Expand Down Expand Up @@ -108,8 +109,10 @@ func (r *Request) URL() (*url.URL, error) {
switch r.Verb {
case "ListMetadataFormats", "ListSets":
case "ListIdentifiers", "ListRecords":
if err := addRequired("metadataPrefix", r.MetadataPrefix); err != nil {
return nil, err
if !r.SuppressFormatParameter {
if err := addRequired("metadataPrefix", r.MetadataPrefix); err != nil {
return nil, err
}
}
addOptional("from", r.From)
addOptional("until", r.Until)
Expand All @@ -120,8 +123,10 @@ func (r *Request) URL() (*url.URL, error) {
if err := addRequired("identifier", r.Identifier); err != nil {
return nil, err
}
if err := addRequired("metadataPrefix", r.MetadataPrefix); err != nil {
return nil, err
if !r.SuppressFormatParameter {
if err := addRequired("metadataPrefix", r.MetadataPrefix); err != nil {
return nil, err
}
}
default:
return nil, ErrInvalidVerb
Expand Down

0 comments on commit 24a5828

Please sign in to comment.