github.com/argoproj/argo-events@v1.9.1/eventsources/common/webhook/types.go (about) 1 /* 2 Copyright 2018 BlackRock, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package webhook 18 19 import ( 20 "net/http" 21 "sync" 22 23 "github.com/gorilla/mux" 24 "go.uber.org/zap" 25 26 metrics "github.com/argoproj/argo-events/metrics" 27 "github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1" 28 ) 29 30 var ( 31 // Mutex synchronizes ActiveServerHandlers 32 Lock sync.Mutex 33 ) 34 35 // Router is an interface to manage the route 36 type Router interface { 37 // GetRoute returns the route 38 GetRoute() *Route 39 // HandleRoute processes the incoming requests on the route 40 HandleRoute(writer http.ResponseWriter, request *http.Request) 41 // PostActivate captures the operations if any after route being activated and ready to process requests. 42 PostActivate() error 43 // PostInactivate captures cleanup operations if any after route is inactivated 44 PostInactivate() error 45 } 46 47 // Route contains general information about a route 48 type Route struct { 49 // WebhookContext refers to the webhook context 50 Context *v1alpha1.WebhookContext 51 // Logger to log stuff 52 Logger *zap.SugaredLogger 53 // StartCh controls the 54 StartCh chan struct{} 55 // EventSourceName refers to event source name 56 EventSourceName string 57 // EventName refers to event name 58 EventName string 59 // active determines whether the route is active and ready to process incoming requets 60 // or it is an inactive route 61 Active bool 62 // data channel to receive data on this endpoint 63 DataCh chan []byte 64 // Stop channel to signal the end of the event source. 65 StopChan chan struct{} 66 67 Metrics *metrics.Metrics 68 } 69 70 // Controller controls the active servers and endpoints 71 type Controller struct { 72 // ActiveServerHandlers keeps track of currently active mux/router for the http servers. 73 ActiveServerHandlers map[string]*mux.Router 74 // AllRoutes keep track of routes that are already registered with server and their status active or inactive 75 AllRoutes map[string]*mux.Route 76 // RouteActivateChan handles activation of routes 77 RouteActivateChan chan Router 78 // RouteDeactivateChan handles inactivation of routes 79 RouteDeactivateChan chan Router 80 }