mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Fixes to recent extension changes. (#568)
* Fixes to recent extension changes. * Fixes issue where gin will continue calling the handler even if next() isn't called. * Updated docs.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/fnproject/fn/fnext"
|
||||
@@ -10,15 +9,15 @@ import (
|
||||
// TODO: Move this into `github.com/fnproject/fn` package after main is moved out of root dir.
|
||||
var extensions = map[string]fnext.Extension{}
|
||||
|
||||
// RegisterExtension registers the extension so it's available, but does not initialize it or anything
|
||||
// RegisterExtension registers the extension so it's available, but does not initialize it.
|
||||
// This is generally what third party extensions will use in their init() method.
|
||||
func RegisterExtension(ext fnext.Extension) {
|
||||
extensions[ext.Name()] = ext
|
||||
}
|
||||
|
||||
// AddExtensionByName This essentially just makes sure the extensions are ordered properly.
|
||||
// It could do some initialization if required too.
|
||||
// AddExtensionByName This essentially just makes sure the extensions are ordered properly and is
|
||||
// what the CLI uses for the `fn build-server` command. Probably not used by much else.
|
||||
func (s *Server) AddExtensionByName(name string) {
|
||||
fmt.Printf("extensions: %+v\n", extensions)
|
||||
e, ok := extensions[name]
|
||||
if !ok {
|
||||
log.Fatalf("Extension %v not registered.\n", name)
|
||||
@@ -28,3 +27,10 @@ func (s *Server) AddExtensionByName(name string) {
|
||||
log.Fatalf("Failed to add extension %v: %v\n", name, err)
|
||||
}
|
||||
}
|
||||
|
||||
// AddExtension both registers an extension and adds it. This is useful during extension development
|
||||
// or if you want to build a custom server without using `fn build-server`.
|
||||
func (s *Server) AddExtension(ext fnext.Extension) {
|
||||
RegisterExtension(ext)
|
||||
s.AddExtensionByName(ext.Name())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user