Documentation
¶
Overview ¶
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadConfigure ¶ added in v0.2.0
func SaveConfigure ¶ added in v0.2.0
Types ¶
type Allocator ¶ added in v0.2.0
type Allocator struct {
// contains filtered or unexported fields
}
Allocator manages variable name allocation and mapping
It provides a way to generate unique variable names and maintain a mapping between original names and generated names. This is useful for code generation where you need to ensure variable names don't conflict and potentially obfuscate the original names.
Example:
allocator := NewAllocator( WithLock(&util.NoOpLocker{}), WithPrefix("_var_"), WithInitialCounter(100), ) name := allocator.AllocName("userCount") // might return "_var_101"
func NewAllocator ¶ added in v0.2.0
func NewAllocator(opts ...AllocatorOption) *Allocator
NewAllocator creates a new Allocator with the given options
Example:
allocator := NewAllocator( WithLock(&util.NoOpLocker{}), WithPrefix("_var_"), WithInitialCounter(100), )
func (*Allocator) AllocName ¶ added in v0.2.0
AllocName allocates a new unique name for the given original name
If the original name has already been allocated, it returns the previously generated name. Otherwise, it generates a new unique name.
Example:
name := allocator.AllocName("count") // might return "_v1" name2 := allocator.AllocName("count") // returns the same "_v1"
func (*Allocator) GetGeneratedName ¶ added in v0.2.0
GetGeneratedName returns the generated name for an original name
Returns empty string if the original name is not found.
Example:
genName := allocator.GetGeneratedName("count") // returns "_v1"
func (*Allocator) GetOriginalName ¶ added in v0.2.0
GetOriginalName returns the original name for a generated name
Returns empty string if the generated name is not found.
Example:
origName := allocator.GetOriginalName("_v1") // returns "count"
type AllocatorOption ¶ added in v0.2.0
type AllocatorOption func(*Allocator)
AllocatorOption defines a function that configures an Allocator
func WithInitialCounter ¶ added in v0.2.0
func WithInitialCounter(counter uint64) AllocatorOption
WithInitialCounter sets the initial counter value
Example:
allocator := NewAllocator(WithInitialCounter(100))
func WithLock ¶ added in v0.2.0
func WithLock(lock sync.Locker) AllocatorOption
WithLock sets the lock implementation for the Allocator
Example:
allocator := NewAllocator(WithLock(&util.NoOpLocker{}))
func WithPrefix ¶ added in v0.2.0
func WithPrefix(prefix string) AllocatorOption
WithPrefix sets the prefix for generated variable names
Example:
allocator := NewAllocator(WithPrefix("_var_"))
type NoOpLocker ¶
type NoOpLocker struct{}
NoOpLocker is a virtual implementation of Locker
This is a no-op implementation that does nothing when Lock() or Unlock() is called. It's useful for testing or when you want to maintain the locking interface without actual synchronization.