diff --git a/edition/community.go b/edition/community.go index d954050b..5fd70428 100644 --- a/edition/community.go +++ b/edition/community.go @@ -35,7 +35,7 @@ func main() { // wire up logging implementation rt.Log = logging.NewLogger() - // define product edition details + // product details rt.Product = env.ProdInfo{} rt.Product.Major = "1" rt.Product.Minor = "50" diff --git a/server/routing/table.go b/server/routing/table.go index 0327f68e..4e2378b8 100644 --- a/server/routing/table.go +++ b/server/routing/table.go @@ -43,6 +43,23 @@ type routeMap map[string]RouteFunc var routes = make(routeMap) +type routeSortItem struct { + def routeDef + fun RouteFunc + ord int +} + +type routeSorter []routeSortItem + +func (s routeSorter) Len() int { return len(s) } +func (s routeSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s routeSorter) Less(i, j int) bool { + if s[i].def.Prefix == s[j].def.Prefix && s[i].def.Path == s[j].def.Path { + return len(s[i].def.Queries) > len(s[j].def.Queries) + } + return s[i].ord < s[j].ord +} + func routesKey(rt env.Runtime, prefix, path string, methods, queries []string) (string, error) { rd := routeDef{ Prefix: prefix, @@ -79,23 +96,6 @@ func Remove(rt env.Runtime, prefix, path string, methods, queries []string) erro return nil } -type routeSortItem struct { - def routeDef - fun RouteFunc - ord int -} - -type routeSorter []routeSortItem - -func (s routeSorter) Len() int { return len(s) } -func (s routeSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] } -func (s routeSorter) Less(i, j int) bool { - if s[i].def.Prefix == s[j].def.Prefix && s[i].def.Path == s[j].def.Path { - return len(s[i].def.Queries) > len(s[j].def.Queries) - } - return s[i].ord < s[j].ord -} - // BuildRoutes returns all matching routes for specified scope. func BuildRoutes(rt env.Runtime, prefix string) *mux.Router { var rs routeSorter diff --git a/server/server.go b/server/server.go index de7e691c..907fbe2b 100644 --- a/server/server.go +++ b/server/server.go @@ -32,7 +32,6 @@ var testHost string // used during automated testing // Start router to handle all HTTP traffic. func Start(rt env.Runtime, ready chan struct{}) { - routing.RegisterEndpoints(rt) err := plugins.LibSetup() if err != nil { @@ -42,6 +41,7 @@ func Start(rt env.Runtime, ready chan struct{}) { rt.Log.Info(fmt.Sprintf("Starting %s version %s", api.Runtime.Product.Title, api.Runtime.Product.Version)) + // decide which mode to serve up switch api.Runtime.Flags.SiteMode { case web.SiteModeOffline: rt.Log.Info("Serving OFFLINE web server") @@ -54,6 +54,10 @@ func Start(rt env.Runtime, ready chan struct{}) { rt.Log.Info("Starting web server") } + // define API endpoints + routing.RegisterEndpoints(rt) + + // wire up API endpoints router := mux.NewRouter() // "/api/public/..." @@ -80,6 +84,7 @@ func Start(rt env.Runtime, ready chan struct{}) { n.Use(negroni.HandlerFunc(metrics)) n.UseHandler(router) + // start server if !api.Runtime.Flags.SSLEnabled() { rt.Log.Info("Starting non-SSL server on " + api.Runtime.Flags.HTTPPort) n.Run(testHost + ":" + api.Runtime.Flags.HTTPPort)