Skip to content

Commit e27e16c

Browse files
committed
refactor: standardize UID method naming across registries
1 parent 588028d commit e27e16c

File tree

25 files changed

+65
-65
lines changed

25 files changed

+65
-65
lines changed

docs/advanced/how-to-create-a-registry.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
## File Naming Conventions
44

5-
* `{{registry_name}}.go`: This file defines the registry, including key components like structs, interfaces, constants, and variables.
6-
* `functions.go`: Contains the implementation of exported functions, making them accessible to other developers.
7-
* `functions_test.go`: Includes tests for the exported functions to ensure they function as expected.
8-
* `helpers.go`: Contains internal helper functions that support the registry but are not exposed for public use.
9-
* `helpers_test.go`: Holds tests for the helper functions to validate their reliability.
5+
- `{{registry_name}}.go`: This file defines the registry, including key components like structs, interfaces, constants, and variables.
6+
- `functions.go`: Contains the implementation of exported functions, making them accessible to other developers.
7+
- `functions_test.go`: Includes tests for the exported functions to ensure they function as expected.
8+
- `helpers.go`: Contains internal helper functions that support the registry but are not exposed for public use.
9+
- `helpers_test.go`: Holds tests for the helper functions to validate their reliability.
1010

1111
{% hint style="info" %}
1212
This structure ensures consistency and maintainability across different registries, making it easier for developers to contribute and collaborate effectively.\
@@ -42,9 +42,9 @@ func NewRegistry() *OwnRegistry {
4242
return &OwnRegistry{}
4343
}
4444

45-
// Uid provides a unique identifier for your registry.
46-
func (or *OwnRegistry) Uid() string {
47-
return "organization/repo.ownregistry" // Ensure this identifier is unique and uses lowercase, prefixed by your handler/repo separated with a dot.
45+
// UID provides a unique identifier for your registry.
46+
func (or *OwnRegistry) UID() string {
47+
return "organization/repo.ownregistry" // Ensure this identifier is unique and uses lowercase, prefixed by your handler/repo separated with a dot.
4848
}
4949

5050
// LinkHandler connects the Handler to your registry, enabling runtime functionalities.

handler_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type MockRegistry struct {
2222

2323
var errMock = errors.New("mock error")
2424

25-
func (m *MockRegistry) Uid() string {
25+
func (m *MockRegistry) UID() string {
2626
args := m.Called()
2727
return args.String(0)
2828
}
@@ -79,7 +79,7 @@ func TestDefaultHandler_Logger(t *testing.T) {
7979
func TestDefaultHandler_AddRegistries_Error(t *testing.T) {
8080
mockRegistry := new(MockRegistry)
8181
mockRegistry.linkHandlerMustCrash = true
82-
mockRegistry.On("Uid").Return("mockRegistry")
82+
mockRegistry.On("UID").Return("mockRegistry")
8383
mockRegistry.On("LinkHandler", mock.Anything).Return(errMock)
8484

8585
dh := &DefaultHandler{
@@ -98,7 +98,7 @@ func TestDefaultHandler_AddRegistries_Error(t *testing.T) {
9898
func TestDefaultHandler_AddRegistry_Error_RegisterFuiesctions(t *testing.T) {
9999
mockRegistry := new(MockRegistry)
100100
mockRegistry.registerFuncsMustCrash = true
101-
mockRegistry.On("Uid").Return("mockRegistry")
101+
mockRegistry.On("UID").Return("mockRegistry")
102102
mockRegistry.On("LinkHandler", mock.Anything).Return()
103103
mockRegistry.On("RegisterFunctions", mock.Anything).Return(errMock)
104104

@@ -117,7 +117,7 @@ func TestDefaultHandler_AddRegistry_Error_RegisterFuiesctions(t *testing.T) {
117117
func TestDefaultHandler_AddRegistry_Error_RegisteriesAliases(t *testing.T) {
118118
mockRegistry := new(MockRegistryWithAlias)
119119
mockRegistry.registerAliasesMustCrash = true
120-
mockRegistry.On("Uid").Return("mockRegistry")
120+
mockRegistry.On("UID").Return("mockRegistry")
121121
mockRegistry.On("LinkHandler", mock.Anything).Return()
122122
mockRegistry.On("RegisterFunctions", mock.Anything).Return()
123123
mockRegistry.On("RegisterAliases", mock.Anything).Return(errMock)
@@ -139,7 +139,7 @@ func TestDefaultHandler_AddRegistry_Error_RegisteriesAliases(t *testing.T) {
139139
func TestDefaultHandler_AddRegistry_Error_RegisteriesNotices(t *testing.T) {
140140
mockRegistry := new(MockRegistryWithNotices)
141141
mockRegistry.registerNoticesMustCrash = true
142-
mockRegistry.On("Uid").Return("mockRegistryWithNotices")
142+
mockRegistry.On("UID").Return("mockRegistryWithNotices")
143143
mockRegistry.On("LinkHandler", mock.Anything).Return()
144144
mockRegistry.On("RegisterFunctions", mock.Anything).Return()
145145
mockRegistry.On("RegisterNotices", mock.Anything).Return()
@@ -163,7 +163,7 @@ func TestDefaultHandler_AddRegistry_Error_RegisteriesNotices(t *testing.T) {
163163
// TestDefaultHandler_AddRegistry tests the AddRegistry method of DefaultHandler.
164164
func TestDefaultHandler_AddRegistry(t *testing.T) {
165165
mockRegistry := new(MockRegistry)
166-
mockRegistry.On("Uid").Return("mockRegistry")
166+
mockRegistry.On("UID").Return("mockRegistry")
167167
mockRegistry.On("LinkHandler", mock.Anything).Return()
168168
mockRegistry.On("RegisterFunctions", mock.Anything).Return()
169169

@@ -184,12 +184,12 @@ func TestDefaultHandler_AddRegistry(t *testing.T) {
184184
// TestDefaultHandler_AddRegistries tests the AddRegistries method of DefaultHandler.
185185
func TestDefaultHandler_AddRegistries(t *testing.T) {
186186
mockRegistry1 := new(MockRegistry)
187-
mockRegistry1.On("Uid").Return("mockRegistry1")
187+
mockRegistry1.On("UID").Return("mockRegistry1")
188188
mockRegistry1.On("LinkHandler", mock.Anything).Return()
189189
mockRegistry1.On("RegisterFunctions", mock.Anything).Return()
190190

191191
mockRegistry2 := new(MockRegistry)
192-
mockRegistry2.On("Uid").Return("mockRegistry2")
192+
mockRegistry2.On("UID").Return("mockRegistry2")
193193
mockRegistry2.On("LinkHandler", mock.Anything).Return()
194194
mockRegistry2.On("RegisterFunctions", mock.Anything).Return()
195195

@@ -213,7 +213,7 @@ func TestDefaultHandler_AddRegistries(t *testing.T) {
213213
// TestDefaultHandler_AddRegistryWithAlias tests AddRegistry when the registry also implements RegistryWithAlias.
214214
func TestDefaultHandler_AddRegistryWithAlias(t *testing.T) {
215215
mockRegistry := new(MockRegistryWithAlias)
216-
mockRegistry.On("Uid").Return("mockRegistryWithAlias")
216+
mockRegistry.On("UID").Return("mockRegistryWithAlias")
217217
mockRegistry.On("LinkHandler", mock.Anything).Return()
218218
mockRegistry.On("RegisterFunctions", mock.Anything).Return()
219219
mockRegistry.On("RegisterAliases", mock.Anything).Return()
@@ -236,7 +236,7 @@ func TestDefaultHandler_AddRegistryWithAlias(t *testing.T) {
236236

237237
func TestDefaultHandler_AddRegistryWithNotices(t *testing.T) {
238238
mockRegistry := new(MockRegistryWithNotices)
239-
mockRegistry.On("Uid").Return("mockRegistryWithNotices")
239+
mockRegistry.On("UID").Return("mockRegistryWithNotices")
240240
mockRegistry.On("LinkHandler", mock.Anything).Return()
241241
mockRegistry.On("RegisterFunctions", mock.Anything).Return()
242242
mockRegistry.On("RegisterNotices", mock.Anything).Return()

registry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ type FunctionMap = template.FuncMap
1414
// performance of the template engine.
1515
// It also allows for easy extension of the template functions by adding a new one.
1616
type Registry interface {
17-
// Uid returns the unique name of the registry. This name is used to identify
17+
// UID returns the unique name of the registry. This name is used to identify
1818
// the registry author and name and prevent duplicate registry registration.
19-
Uid() string
19+
UID() string
2020
// LinkHandler links the given Handler to the registry.
2121
// * This method help you to have access to the main handler and its
2222
// * functionalities, like the logger, error handling, and more.

registry/_example/_example.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ func NewRegistry() *ExampleRegistry {
1313
return &ExampleRegistry{}
1414
}
1515

16-
// Uid returns the unique identifier of the registry.
17-
func (or *ExampleRegistry) Uid() string {
16+
// UID returns the unique identifier of the registry.
17+
func (or *ExampleRegistry) UID() string {
1818
return "go-sprout/sprout.exampleofregistry" // ! Must be unique and in lowercase, replace `exampleofregistry` with your registry name and `go-sprout/sprout` with your handle name
1919
}
2020

registry/backward/backward.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func NewRegistry() *BackwardCompatibilityRegistry {
3434
return &BackwardCompatibilityRegistry{}
3535
}
3636

37-
// Uid returns the unique identifier of the registry.
38-
func (bcr *BackwardCompatibilityRegistry) Uid() string {
37+
// UID returns the unique identifier of the registry.
38+
func (bcr *BackwardCompatibilityRegistry) UID() string {
3939
return "go-sprout/sprout.backwardcompatibilitywithsprig"
4040
}
4141

registry/checksum/checksum.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func NewRegistry() *ChecksumRegistry {
1111
return &ChecksumRegistry{}
1212
}
1313

14-
// Uid returns the unique identifier of the registry.
15-
func (cr *ChecksumRegistry) Uid() string {
14+
// UID returns the unique identifier of the registry.
15+
func (cr *ChecksumRegistry) UID() string {
1616
return "go-sprout/sprout.checksum"
1717
}
1818

registry/conversion/conversion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func NewRegistry() *ConversionRegistry {
1111
return &ConversionRegistry{}
1212
}
1313

14-
// Uid returns the unique identifier of the registry.
15-
func (or *ConversionRegistry) Uid() string {
14+
// UID returns the unique identifier of the registry.
15+
func (or *ConversionRegistry) UID() string {
1616
return "go-sprout/sprout.conversion"
1717
}
1818

registry/crypto/crypto.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func NewRegistry() *CryptoRegistry {
5656
return &CryptoRegistry{}
5757
}
5858

59-
// Uid returns the unique identifier of the crypto handler.
60-
func (ch *CryptoRegistry) Uid() string {
59+
// UID returns the unique identifier of the crypto handler.
60+
func (ch *CryptoRegistry) UID() string {
6161
return "go-sprout/sprout.crypto"
6262
}
6363

registry/encoding/encoding.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func NewRegistry() *EncodingRegistry {
1111
return &EncodingRegistry{}
1212
}
1313

14-
// Uid returns the unique identifier of the registry.
15-
func (or *EncodingRegistry) Uid() string {
14+
// UID returns the unique identifier of the registry.
15+
func (or *EncodingRegistry) UID() string {
1616
return "go-sprout/sprout.encoding"
1717
}
1818

registry/env/env.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func NewRegistry() *EnvironmentRegistry {
1111
return &EnvironmentRegistry{}
1212
}
1313

14-
// Uid returns the unique identifier of the registry.
15-
func (or *EnvironmentRegistry) Uid() string {
14+
// UID returns the unique identifier of the registry.
15+
func (or *EnvironmentRegistry) UID() string {
1616
return "go-sprout/sprout.env"
1717
}
1818

registry/filesystem/filesystem.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func NewRegistry() *FileSystemRegistry {
1111
return &FileSystemRegistry{}
1212
}
1313

14-
// Uid returns the unique identifier of the registry.
15-
func (fsr *FileSystemRegistry) Uid() string {
14+
// UID returns the unique identifier of the registry.
15+
func (fsr *FileSystemRegistry) UID() string {
1616
return "go-sprout/sprout.filesystem"
1717
}
1818

registry/maps/maps.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func NewRegistry() *MapsRegistry {
1111
return &MapsRegistry{}
1212
}
1313

14-
// Uid returns the unique identifier of the registry.
15-
func (mr *MapsRegistry) Uid() string {
14+
// UID returns the unique identifier of the registry.
15+
func (mr *MapsRegistry) UID() string {
1616
return "go-sprout/sprout.maps"
1717
}
1818

registry/network/network.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ func NewRegistry() *NetworkRegistry {
1313
return &NetworkRegistry{}
1414
}
1515

16-
// Uid returns the unique identifier of the registry.
17-
func (nr *NetworkRegistry) Uid() string {
16+
// UID returns the unique identifier of the registry.
17+
func (nr *NetworkRegistry) UID() string {
1818
return "go-sprout/sprout.network"
1919
}
2020

registry/numeric/numeric.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ func NewRegistry() *NumericRegistry {
2525
return &NumericRegistry{}
2626
}
2727

28-
// Uid returns the unique identifier of the registry.
29-
func (nr *NumericRegistry) Uid() string {
28+
// UID returns the unique identifier of the registry.
29+
func (nr *NumericRegistry) UID() string {
3030
return "go-sprout/sprout.numeric"
3131
}
3232

registry/random/random.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func NewRegistry() *RandomRegistry {
4242
return &RandomRegistry{}
4343
}
4444

45-
// Uid returns the unique identifier of the registry.
46-
func (rr *RandomRegistry) Uid() string {
45+
// UID returns the unique identifier of the registry.
46+
func (rr *RandomRegistry) UID() string {
4747
return "go-sprout/sprout.random"
4848
}
4949

registry/reflect/reflect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func NewRegistry() *ReflectRegistry {
1111
return &ReflectRegistry{}
1212
}
1313

14-
// Uid returns the unique identifier of the registry.
15-
func (rr *ReflectRegistry) Uid() string {
14+
// UID returns the unique identifier of the registry.
15+
func (rr *ReflectRegistry) UID() string {
1616
return "go-sprout/sprout.reflect"
1717
}
1818

registry/regexp/regexp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func NewRegistry() *RegexpRegistry {
1111
return &RegexpRegistry{}
1212
}
1313

14-
// Uid returns the unique identifier of the registry.
15-
func (rr *RegexpRegistry) Uid() string {
14+
// UID returns the unique identifier of the registry.
15+
func (rr *RegexpRegistry) UID() string {
1616
return "go-sprout/sprout.regexp"
1717
}
1818

registry/semver/semver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func NewRegistry() *SemverRegistry {
1111
return &SemverRegistry{}
1212
}
1313

14-
// Uid returns the unique identifier of the registry.
15-
func (sr *SemverRegistry) Uid() string {
14+
// UID returns the unique identifier of the registry.
15+
func (sr *SemverRegistry) UID() string {
1616
return "go-sprout/sprout.semver"
1717
}
1818

registry/slices/slices.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func NewRegistry() *SlicesRegistry {
1111
return &SlicesRegistry{}
1212
}
1313

14-
// Uid returns the unique identifier of the registry.
15-
func (sr *SlicesRegistry) Uid() string {
14+
// UID returns the unique identifier of the registry.
15+
func (sr *SlicesRegistry) UID() string {
1616
return "go-sprout/sprout.slices"
1717
}
1818

registry/std/std.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func NewRegistry() *StdRegistry {
1111
return &StdRegistry{}
1212
}
1313

14-
// Uid returns the unique identifier of the registry.
15-
func (sr *StdRegistry) Uid() string {
14+
// UID returns the unique identifier of the registry.
15+
func (sr *StdRegistry) UID() string {
1616
return "go-sprout/sprout.std"
1717
}
1818

registry/strings/strings.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ func NewRegistry() *StringsRegistry {
8181
return &StringsRegistry{}
8282
}
8383

84-
// Uid returns the unique identifier of the registry.
85-
func (sr *StringsRegistry) Uid() string {
84+
// UID returns the unique identifier of the registry.
85+
func (sr *StringsRegistry) UID() string {
8686
return "go-sprout/sprout.strings"
8787
}
8888

registry/time/time.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func NewRegistry() *TimeRegistry {
1111
return &TimeRegistry{}
1212
}
1313

14-
// Uid returns the unique identifier of the registry.
15-
func (tr *TimeRegistry) Uid() string {
14+
// UID returns the unique identifier of the registry.
15+
func (tr *TimeRegistry) UID() string {
1616
return "go-sprout/sprout.time"
1717
}
1818

registry/uniqueid/uniqueid.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func NewRegistry() *UniqueIDRegistry {
1111
return &UniqueIDRegistry{}
1212
}
1313

14-
// Uid returns the unique identifier of the registry.
15-
func (ur *UniqueIDRegistry) Uid() string {
14+
// UID returns the unique identifier of the registry.
15+
func (ur *UniqueIDRegistry) UID() string {
1616
return "go-sprout/sprout.uniqueid"
1717
}
1818

registry_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ func TestAddAlias(t *testing.T) {
5858
func TestWithRegistries(t *testing.T) {
5959
// Define two registries with functions and aliases
6060
mockRegistry1 := new(MockRegistry)
61-
mockRegistry1.On("Uid").Return("mockRegistry1")
61+
mockRegistry1.On("UID").Return("mockRegistry1")
6262
mockRegistry1.On("LinkHandler", mock.Anything).Return(nil)
6363
mockRegistry1.On("RegisterFunctions", mock.Anything).Return(nil)
6464

6565
mockRegistry2 := new(MockRegistry)
6666
mockRegistry2.linkHandlerMustCrash = true
67-
mockRegistry2.On("Uid").Return("mockRegistry2")
67+
mockRegistry2.On("UID").Return("mockRegistry2")
6868
mockRegistry2.On("LinkHandler", mock.Anything).Return(nil)
6969
mockRegistry1.On("RegisterFunctions", mock.Anything).Return(nil)
7070

sprigin/sprig_backward_compatibility_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ func TestSprigHandler(t *testing.T) {
5858

5959
assert.Len(t, handler.registries, 18) // Hardcoded for backward compatibility
6060

61-
registriesUids := []string{}
61+
registriesUIDs := []string{}
6262
for _, registry := range handler.registries {
63-
registriesUids = append(registriesUids, registry.Uid())
63+
registriesUIDs = append(registriesUIDs, registry.UID())
6464
}
6565

66-
assert.ElementsMatch(t, registriesUids, []string{
66+
assert.ElementsMatch(t, registriesUIDs, []string{
6767
"go-sprout/sprout.std",
6868
"go-sprout/sprout.uniqueid",
6969
"go-sprout/sprout.semver",

0 commit comments

Comments
 (0)