// Application is responsible to manage the state of the application.// It contains and handles all the necessary parts to create a fast web server.typeApplicationstruct {// routing embedded | exposing APIBuilder's and Router's public API.*router.APIBuilder*router.Router ContextPool *context.Pool config *Configuration logger *golog.Logger I18n *i18n.I18n// view engine view view.View// used for build builded bool defaultMode bool mu sync.Mutex Hosts []*host.Supervisor hostConfigurators []host.Configurator}
// Route contains the information about a registered Route.// If any of the following fields are changed then the// caller should Refresh the router.typeRoutestruct {// The Party which this Route was created and registered on. Party Party Title string`json:"title"`// custom name to replace the method on debug logging. Name string`json:"name"`// "userRoute" Description string`json:"description"`// "lists a user" Method string`json:"method"`// "GET" StatusCode int`json:"statusCode"`// 404 (only for HTTP error handlers). methodBckp string// if Method changed to something else (which is possible at runtime as well, via RefreshRouter) then this field will be filled with the old one. Subdomain string`json:"subdomain"`// "admin." tmpl macro.Template// Tmpl().Src: "/api/user/{id:uint64}" beginHandlers context.Handlers builtinBeginHandlers context.Handlers Handlers context.Handlers`json:"-"` MainHandlerName string`json:"mainHandlerName"` MainHandlerIndex int`json:"mainHandlerIndex"` doneHandlers context.Handlers Path string`json:"path"`// the underline router's representation, i.e "/api/user/:id" FormattedPath string`json:"formattedPath"` SourceFileName string`json:"sourceFileName"` SourceLineNumber int`json:"sourceLineNumber"` RegisterFileName string`json:"registerFileName"` RegisterLineNumber int`json:"registerLineNumber"` topLink *Route overlappedLink *Route// Sitemap properties: https://www.sitemaps.org/protocol.html NoSitemap bool// when this route should be hidden from sitemap. LastMod time.Time`json:"lastMod,omitempty"` ChangeFreq string`json:"changeFreq,omitempty"` Priority float32`json:"priority,omitempty"`// ReadOnly is the read-only structure of the Route. ReadOnly context.RouteReadOnly// OnBuild runs right before BuildHandlers. OnBuild func(r *Route) NoLog bool// disables debug logging.}
3.2 APIBuilder
APIBuilder:创建Route的Builder模式,Party也是它创建的.
// APIBuilder the visible API for constructing the router// and child routers.typeAPIBuilderstruct { logger *golog.Logger parent *APIBuilder// currently it's not used anywhere. apiBuilderDI *APIContainer macros *macro.Macros properties context.Map routes *repository routesNoLog bool middleware context.Handlers middlewareErrorCode context.Handlers beginGlobalHandlers context.Handlers// the per-party done handlers, order matters. doneHandlers context.Handlers doneGlobalHandlers context.Handlers relativePath string allowMethods []string handlerExecutionRules ExecutionRules routeRegisterRule RouteRegisterRule routerFilterHandlers context.Handlers routerFilters map[Party]*Filter partyMatcher PartyMatcherFunc}
3.3 repository
repository:存储了所有的Routes,有点接近GIN的methodTrees的概念
// repository passed to all parties(subrouters), it's the object witch keeps// all the routes.typerepositorystruct { routes []*Route paths map[string]*Route// only the fullname path part, required at CreateRoutes for registering index page.}