| commit | d2ce2e51ab80c7e8e750700876c120cb55cfb1b3 | [log] [tgz] |
|---|---|---|
| author | alexanderkhimich <akhimich@apigee.com> | Wed Jan 18 16:47:36 2017 -0800 |
| committer | alexanderkhimich <akhimich@apigee.com> | Thu Jan 19 15:20:30 2017 -0800 |
| tree | ed243361056c24975de582675bcb7a5fdb8cd377 | |
| parent | 0a5a3d74691da50a1b57de7f3b239a587524a699 [diff] |
Opened logger as public
Apid is a container for publishing APIs that provides core services to its plugins including configuration, API publishing, data access, and a local pub/sub event system.
cd cmd/apid glide install go build ./apid
For command line options:
./apid -help
Configuration can be done via yaml file or environment variables. Keys are case-insensitive. By default, apid will look for a file called apid_config.yaml in the current working directory.
Config will pick up env vars automatically. Use “apid_” as a prefix for settings. For example, for apid's “log_level” configuration setting, set env var “apid_log_level”.
api_port: 9000 api_expvar_path: nil # not exposed data_path: /var/tmp events_buffer_size: 5 log_level: debug # valid values: Debug, Info, Warning, Error, Fatal, Panic
apid provides the following services:
A driver process must initialize apid and its plugins like this:
apid.Initialize(factory.DefaultServicesFactory()) // when done, all services are available apid.InitializePlugins() // when done, all plugins are running api := apid.API() // access the API service err := api.Listen() // start the listener
Once apid.Initialize() has been called, all services are accessible via the apid package functions as details above.
The only requirement of an apid plugin is to register itself upon init(). However, generally plugins will access the Log service and some kind of driver (via API or Events), so it's common practice to see something like this:
var log apid.LogService
func init() {
apid.RegisterPlugin(initPlugin)
}
func initPlugin(services apid.Services) error {
log = services.Log().ForModule("myPluginName") // note: could also access via `apid.Log().ForModule()`
services.API().HandleFunc("/verifyAPIKey", handleRequest)
}
func handleRequest(w http.ResponseWriter, r *http.Request) {
// respond to request
}
export APID_DATA_TRACE_LOG_LEVEL=debug to see DB Tracing