-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a501fc
commit 3df116e
Showing
9 changed files
with
172 additions
and
89 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,53 @@ | ||
package goload | ||
|
||
import ( | ||
"context" | ||
"github.com/mroth/weightedrand/v2" | ||
"time" | ||
) | ||
|
||
type executorGroup struct { | ||
name string | ||
chooser *weightedrand.Chooser[Executor, int] | ||
weight int | ||
timeout time.Duration | ||
} | ||
|
||
// TODO: add options | ||
func NewGroup(name string, weight int, executors []Executor) Executor { | ||
if len(executors) == 0 { | ||
panic("group can't be empty") | ||
} | ||
choises := make([]weightedrand.Choice[Executor, int], 0, len(executors)) | ||
for _, exec := range executors { | ||
choises = append(choises, weightedrand.NewChoice(exec, exec.Options().Weight)) | ||
} | ||
chooser, err := weightedrand.NewChooser( | ||
choises..., | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return &executorGroup{ | ||
name: name, | ||
chooser: chooser, | ||
weight: weight, | ||
timeout: 0, | ||
} | ||
} | ||
|
||
func (e *executorGroup) Execute(ctx context.Context) ExecutionResponse { | ||
return e.chooser.Pick().Execute(ctx) | ||
} | ||
|
||
func (e *executorGroup) Name() string { | ||
return e.name | ||
} | ||
|
||
func (e *executorGroup) Options() *ExecutorOptions { | ||
return &ExecutorOptions{ | ||
Weight: e.weight, | ||
Timeout: e.timeout, | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
package url_builder | ||
|
||
func WithRawURL(rawURL string) URLBuilderOption { | ||
return func(builder *URLBuilder) { | ||
builder.rawURL = rawURL | ||
} | ||
} | ||
|
||
func WithQueryParams(queryParams ...QueryParamBuilder) URLBuilderOption { | ||
return func(builder *URLBuilder) { | ||
builder.queryParams = append(builder.queryParams, queryParams...) | ||
} | ||
} | ||
|
||
func WithURLParam(key string, values []string) URLBuilderOption { | ||
return func(builder *URLBuilder) { | ||
builder.urlParameterRandomizers = append(builder.urlParameterRandomizers, URLParameterRandomizer{key, values}) | ||
} | ||
} |
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
Oops, something went wrong.