mirror of
https://github.com/documize/community.git
synced 2025-07-20 21:59:42 +02:00
cosmetics
This commit is contained in:
parent
d888962082
commit
25b576f861
3 changed files with 24 additions and 19 deletions
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue