istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/ctrlz/fw/context.go (about) 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 15 package fw 16 17 import ( 18 "html/template" 19 20 "github.com/gorilla/mux" 21 ) 22 23 // Topic is used to describe a single major ControlZ functional area. 24 type Topic interface { 25 // Title returns the title for the area, which will be used in the sidenav and window title. 26 Title() string 27 28 // Prefix is the name used to reference this functionality in URLs. 29 Prefix() string 30 31 // Activate triggers a topic to register itself to receive traffic. 32 Activate(TopicContext) 33 } 34 35 // TopicContext provides support objects needed to register a topic. 36 type TopicContext interface { 37 // HTMLRouter is used to control HTML traffic delivered to this topic. 38 HTMLRouter() *mux.Router 39 40 // JSONRouter is used to control HTML traffic delivered to this topic. 41 JSONRouter() *mux.Router 42 43 // Layout is the template used as the primary layout for the topic's HTML content. 44 Layout() *template.Template 45 } 46 47 type context struct { 48 htmlRouter *mux.Router 49 jsonRouter *mux.Router 50 layout *template.Template 51 } 52 53 // NewContext creates a new TopicContext. 54 func NewContext(htmlRouter *mux.Router, jsonRouter *mux.Router, layout *template.Template) TopicContext { 55 return context{ 56 htmlRouter: htmlRouter, 57 jsonRouter: jsonRouter, 58 layout: layout, 59 } 60 } 61 62 func (c context) HTMLRouter() *mux.Router { 63 return c.htmlRouter 64 } 65 66 func (c context) JSONRouter() *mux.Router { 67 return c.jsonRouter 68 } 69 70 func (c context) Layout() *template.Template { 71 return c.layout 72 }