mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
32 lines
549 B
Go
32 lines
549 B
Go
package modules
|
|
|
|
type PortAllocator interface {
|
|
NextPort() int32
|
|
}
|
|
type PortAllocatorFn func() int32
|
|
|
|
func (fn PortAllocatorFn) NextPort() int32 {
|
|
return fn()
|
|
}
|
|
func StaticPortAllocator(v int32) PortAllocatorFn {
|
|
return func() int32 {
|
|
return v
|
|
}
|
|
}
|
|
|
|
type portRangeAllocator struct {
|
|
startRange int32
|
|
offset int32
|
|
}
|
|
|
|
func (p *portRangeAllocator) NextPort() int32 {
|
|
p.offset++
|
|
return p.startRange + p.offset
|
|
}
|
|
|
|
func NewPortRangeAllocator(startRange int32) *portRangeAllocator {
|
|
return &portRangeAllocator{
|
|
startRange: startRange,
|
|
}
|
|
}
|