istio
1// Copyright Istio Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package fw16
17import (18"html/template"19
20"github.com/gorilla/mux"21)
22
23// Topic is used to describe a single major ControlZ functional area.
24type Topic interface {25// Title returns the title for the area, which will be used in the sidenav and window title.26Title() string27
28// Prefix is the name used to reference this functionality in URLs.29Prefix() string30
31// Activate triggers a topic to register itself to receive traffic.32Activate(TopicContext)33}
34
35// TopicContext provides support objects needed to register a topic.
36type TopicContext interface {37// HTMLRouter is used to control HTML traffic delivered to this topic.38HTMLRouter() *mux.Router39
40// JSONRouter is used to control HTML traffic delivered to this topic.41JSONRouter() *mux.Router42
43// Layout is the template used as the primary layout for the topic's HTML content.44Layout() *template.Template45}
46
47type context struct {48htmlRouter *mux.Router49jsonRouter *mux.Router50layout *template.Template51}
52
53// NewContext creates a new TopicContext.
54func NewContext(htmlRouter *mux.Router, jsonRouter *mux.Router, layout *template.Template) TopicContext {55return context{56htmlRouter: htmlRouter,57jsonRouter: jsonRouter,58layout: layout,59}60}
61
62func (c context) HTMLRouter() *mux.Router {63return c.htmlRouter64}
65
66func (c context) JSONRouter() *mux.Router {67return c.jsonRouter68}
69
70func (c context) Layout() *template.Template {71return c.layout72}
73