-
Notifications
You must be signed in to change notification settings - Fork 8
Structure
This article is to review the manner in which Mongolar is setup.
All the configurations are in YAML format.
When Mongolar boots it will attempt to load an environement variable to find the
server configuration. If the environment variable is not set it will default to
/etc/mongolar.
The file name is mongolar.yaml
The server config has 3 settings.
Port - The port Mongolar should listen on
SitesDirectory - Where configurations for sites should be located
LogDirectory - Where all logs should be set
If the server successfully boots it will then attempt to load all the Site configurations.
A Site configuration has too many settings to list, but you can view the built in fields here.
You can also add as many custom settings as you wish to retrieve any custom controllers you write for Mongolar. These settings will be available for marshalling when needed.
Each Site Config should an Aliases entry with at least one entry. Aliases is a list of all domains that you can apply to the site.
After Sites have been loaded Mongolar will create a map of aliases with a pointer to the site configurations. When a request comes in, and if a domain matches one in the aliases array, Mongolar will begin to process the request with the correct site configuration for that alias.
Mongolar will also build a controller map based on the values you provide in the mongolar.go file prior to compiling the program.
The controller map is a map of all controllers that can return a value from Mongolar, based on the next value in a url after the api end point.
Controller is any function that will take a Request Wrapper from Mongolar and returns nothing.
m := controller.NewMap()
m["my_controller"] = MyController
function MyController(w *wrapper.Wrapper){
w.SetPayload("my_values", "Hello")
w.Serve()
return
}In the above example we create a new map, and add the a new controller to "my_controller". My Controller will return a value of hello.
The above would have to be included in the mongolar.go file.
With the above example you would visit my.domain.com/my_api_endpoint/my_controller, and that would return.
{"my_values": "Hello"}