Connor McCutcheon
/ Skykit
option.go
go
package skykit
import (
	"log"
)
type Option func(*Application) error
// WithFunc adds a template function to the application
func WithFunc(name string, fn any) Option {
	return func(app *Application) error {
		app.funcs[name] = fn
		return nil
	}
}
// WithValue adds a template value to the application
func WithValue(name string, value any) Option {
	return func(app *Application) error {
		app.funcs[name] = func() any { return value }
		return nil
	}
}
// WithController adds a controller to the application
func WithController(name string, ctrl Handler) Option {
	return func(app *Application) error {
		return app.WithController(name, ctrl)
	}
}
// WithController adds a controller to the application
func (app *Application) WithController(name string, controller Handler) error {
	if _, ok := app.controllers[name]; !ok {
		app.controllers[name] = controller
		controller.Setup(app)
	} else {
		log.Fatal(name, "already registered controller")
	}
	return nil
}
No comments yet.