diff --git a/template.go b/template.go index e4e5324..90ee063 100644 --- a/template.go +++ b/template.go @@ -6,14 +6,35 @@ var tpl = template.Must(template.New("generated").Parse(` // Code generated by github.com/vektah/dataloaden, DO NOT EDIT. package {{.Package}} - + import ( "sync" "time" - + {{if .Import}}"{{.Import}}"{{end}} ) +// {{.LoaderName}}Config captures the config to create a new {{.LoaderName}} +type {{.LoaderName}}Config struct { + // Fetch is a method that provides the data for the loader + Fetch func(keys []{{.KeyType}}) ([]{{.ValType}}, []error) + + // Wait is how long wait before sending a batch + Wait time.Duration + + // MaxBatch will limit the maximum number of keys to send in one batch, 0 = not limit + MaxBatch int +} + +// New{{.LoaderName}} creates a new {{.LoaderName}} given a fetch, wait, and maxBatch +func New{{.LoaderName}}(config {{.LoaderName}}Config) *{{.LoaderName}} { + return &{{.LoaderName}}{ + fetch: config.Fetch, + wait: config.Wait, + maxBatch: config.MaxBatch, + } +} + // {{.LoaderName}} batches and caches requests type {{.LoaderName}} struct { // this method provides the data for the loader