-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: clean-up configuration code
- Loading branch information
1 parent
696cb85
commit e27c671
Showing
4 changed files
with
123 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package hibpsync | ||
|
||
import "io" | ||
|
||
type commonConfig struct { | ||
dataDir string | ||
noCompression bool | ||
} | ||
|
||
type syncConfig struct { | ||
commonConfig | ||
endpoint string | ||
minWorkers int | ||
progressFn ProgressFunc | ||
stateFile io.ReadWriteSeeker | ||
lastRange int64 | ||
} | ||
|
||
type SyncOption func(config *syncConfig) | ||
|
||
func SyncWithDataDir(dataDir string) SyncOption { | ||
return func(c *syncConfig) { | ||
c.dataDir = dataDir | ||
} | ||
} | ||
|
||
func SyncWithEndpoint(endpoint string) SyncOption { | ||
return func(c *syncConfig) { | ||
c.endpoint = endpoint | ||
} | ||
} | ||
|
||
func SyncWithMinWorkers(workers int) SyncOption { | ||
return func(c *syncConfig) { | ||
c.minWorkers = workers | ||
} | ||
} | ||
|
||
func SyncWithStateFile(stateFile io.ReadWriteSeeker) SyncOption { | ||
return func(c *syncConfig) { | ||
c.stateFile = stateFile | ||
} | ||
} | ||
|
||
func SyncWithProgressFn(progressFn ProgressFunc) SyncOption { | ||
return func(c *syncConfig) { | ||
c.progressFn = progressFn | ||
} | ||
} | ||
|
||
func SyncWithNoCompression() SyncOption { | ||
return func(c *syncConfig) { | ||
c.noCompression = true | ||
} | ||
} | ||
|
||
func SyncWithLastRange(to int64) SyncOption { | ||
return func(c *syncConfig) { | ||
c.lastRange = to | ||
} | ||
} | ||
|
||
type exportConfig struct { | ||
commonConfig | ||
} | ||
|
||
type ExportOption func(*exportConfig) | ||
|
||
func ExportWithDataDir(dataDir string) ExportOption { | ||
return func(c *exportConfig) { | ||
c.dataDir = dataDir | ||
} | ||
} | ||
|
||
func ExportWithNoCompression() ExportOption { | ||
return func(c *exportConfig) { | ||
c.noCompression = true | ||
} | ||
} | ||
|
||
type queryConfig struct { | ||
commonConfig | ||
} | ||
|
||
type QueryOption func(*queryConfig) | ||
|
||
func QueryWithDataDir(dataDir string) QueryOption { | ||
return func(c *queryConfig) { | ||
c.dataDir = dataDir | ||
} | ||
} | ||
|
||
func QueryWithNoCompression() QueryOption { | ||
return func(c *queryConfig) { | ||
c.noCompression = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters