Skip to content

3. Initializations and Configurations

kooinam edited this page Sep 3, 2020 · 4 revisions

To ensure proper initializations of Fab.io, do the following:

func main() {
	fab.ConfigureAndServe(&FabInitializer{})
}

FabInitializer needs to implement the following functions:

  1. Configure(*Configuration) can be used to configure configurations like port and http handler.
// Configure used to configure configurations
func (initializer *FabInitializer) Configure(configuration *fab.Configuration) {
	configuration.SetPort("8000")
	configuration.SetHttpHandler(func() {
		fs := http.FileServer(http.Dir("./demo"))
		http.Handle("/demo/", http.StripPrefix("/demo/", fs))
	})
}
  1. RegisterAdapters(*models.Manager) can be used to register adapters.
  2. RegisterCollections(*models.Manager) can be used to register collections.
  3. RegisterControllers(*controllers.Manager) can be used to register controllers.
  4. RegisterViews(*views.Manager) can be used to register views.
  5. BeforeServe() can be used to implementing customized application initialization logics like loading application data. BeforeServe will be called after Fab.io initializes and before starting to serve.

Clone this wiki locally