Celerity supports environment specific operation. If you are using the
CelerityCLI handler this is handled automatically for you. The built CLI can
read the environment from the ENV
environment variable, an env
property in a
configuration file, or it can be passed as a command line flag to the run
subcommand.
Celerity supports two operational environments Production and development which can be specified with “prod” and dev” respectively.
myserver run --env=prod
ENV=prod myserver run
Failure responses
The environment changes how failed requests are processed and demonstraites a
major difference between responding with Error
or Fail
. If a request is
failed in development the error message will be sent to the client. In
production it will be replaced with a generic error message.
func MyHandler(c celerity.Context) celerity.Response {
err := myCriticalProcess()
if err != nil {
c.Fail(err)
}
}
Detecting the current environment
You can detect which environment you are running in from within the context.
func MyHandler(c celerity.Context) celerity.Response {
if (c.Env == celerity.DEV) {
// some debug specific code
}
if (c.Env == celerity.PROD) {
// Run only if we are in production
}
}