commit | b601a5f26268b404a32fbd104dafb6f98d47934c | [log] [tgz] |
---|---|---|
author | Scott Ganyo <scott@ganyo.com> | Thu Apr 13 16:54:20 2017 -0700 |
committer | GitHub <noreply@github.com> | Thu Apr 13 16:54:20 2017 -0700 |
tree | 2d69a17e2d21cecab0db5b0057db05efd12dc5e8 | |
parent | f748c2055a38c23e6ca38d32aa7196230cc4f2b8 [diff] | |
parent | 417c35d99d4c84aef088d0ae432edd398b227e72 [diff] |
Merge pull request #8 from 30x/XAPID-922 Xapid 922
apid-core is a library that provides 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.
Disambiguation: You might be looking for the executable builder, apid.
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 }
go test $(glide novendor)