-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
load extensions during compile time using go build tags
- Loading branch information
1 parent
2e5e6fb
commit 452b501
Showing
19 changed files
with
670 additions
and
149 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package extensions | ||
|
||
import "context" | ||
|
||
type extensionBuilder struct { | ||
extension *Extension | ||
} | ||
|
||
// ExtensionBuilder is the interface for creating an extension server | ||
type ExtensionBuilder interface { | ||
// WithMethods specifies the methods that should be provided | ||
// by the extension | ||
WithMethods(map[string]MethodFunc) ExtensionBuilder | ||
// WithInitializer is a function that initializes a new extension instance. | ||
WithInitializer(InitializeFunc) ExtensionBuilder | ||
// Named specifies the name of the extensions. | ||
Named(string) ExtensionBuilder | ||
|
||
// Build creates the extensions | ||
Build() (*Extension, error) | ||
} | ||
|
||
func Builder() ExtensionBuilder { | ||
return &extensionBuilder{ | ||
extension: &Extension{ | ||
methods: make(map[string]MethodFunc), | ||
initializeFunc: func(ctx context.Context, metadata map[string]string) (map[string]string, error) { | ||
return metadata, nil | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (b *extensionBuilder) Named(name string) ExtensionBuilder { | ||
b.extension.name = name | ||
return b | ||
} | ||
|
||
func (b *extensionBuilder) WithMethods(methods map[string]MethodFunc) ExtensionBuilder { | ||
b.extension.methods = methods | ||
return b | ||
} | ||
|
||
func (b *extensionBuilder) WithInitializer(fn InitializeFunc) ExtensionBuilder { | ||
b.extension.initializeFunc = fn | ||
return b | ||
} | ||
|
||
func (b *extensionBuilder) Build() (*Extension, error) { | ||
return b.extension, nil | ||
} |
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,19 @@ | ||
package extensions | ||
|
||
import "strings" | ||
|
||
var registeredExtensions = make(map[string]*Extension) | ||
|
||
func RegisterExtension(name string, ext *Extension) error { | ||
name = strings.ToLower(name) | ||
if _, ok := registeredExtensions[name]; ok { | ||
panic("extension of same name already registered: " + name) | ||
} | ||
|
||
registeredExtensions[name] = ext | ||
return nil | ||
} | ||
|
||
func GetRegisteredExtensions() map[string]*Extension { | ||
return registeredExtensions | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.