generated from goexl/template
-
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.
- Loading branch information
1 parent
2212702
commit a8b798c
Showing
8 changed files
with
52 additions
and
12 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
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 |
---|---|---|
@@ -1,44 +1,49 @@ | ||
package schedule | ||
|
||
type limitBuilder struct { | ||
type limitBuilder[T limitType] struct { | ||
params *limitParams | ||
builder *addBuilder | ||
builder T | ||
} | ||
|
||
func newLimitBuilder(builder *addBuilder) *limitBuilder { | ||
return &limitBuilder{ | ||
func newLimitBuilder[T limitType](builder T) *limitBuilder[T] { | ||
return &limitBuilder[T]{ | ||
params: newLimitParams(), | ||
builder: builder, | ||
} | ||
} | ||
|
||
func (lb *limitBuilder) Cpu(percent float64) *limitBuilder { | ||
func (lb *limitBuilder[T]) Cpu(percent float64) *limitBuilder[T] { | ||
lb.params.cpu = percent | ||
|
||
return lb | ||
} | ||
|
||
func (lb *limitBuilder) Memory(percent float64) *limitBuilder { | ||
func (lb *limitBuilder[T]) Memory(percent float64) *limitBuilder[T] { | ||
lb.params.memory = percent | ||
|
||
return lb | ||
} | ||
|
||
func (lb *limitBuilder) Process(count int) *limitBuilder { | ||
func (lb *limitBuilder[T]) Process(count int) *limitBuilder[T] { | ||
lb.params.process = count | ||
|
||
return lb | ||
} | ||
|
||
func (lb *limitBuilder) Max(max int) *limitBuilder { | ||
func (lb *limitBuilder[T]) Max(max int) *limitBuilder[T] { | ||
lb.params.max = max | ||
|
||
return lb | ||
} | ||
|
||
func (lb *limitBuilder) Build() (builder *addBuilder) { | ||
lb.builder.self.limit = lb.params | ||
builder = lb.builder | ||
func (lb *limitBuilder[T]) Build() (t T) { | ||
switch target := any(lb.builder).(type) { | ||
case *builder: | ||
target.params.limit = lb.params | ||
case *addBuilder: | ||
target.self.limit = lb.params | ||
} | ||
t = lb.builder | ||
|
||
return | ||
} |
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,5 @@ | ||
package schedule | ||
|
||
type limitType interface { | ||
*builder | *addBuilder | ||
} |
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