@@ -14,6 +14,7 @@ import (
14
14
"github.com/Sirupsen/logrus"
15
15
16
16
"github.com/zalando-incubator/postgres-operator/pkg/spec"
17
+ "github.com/zalando-incubator/postgres-operator/pkg/util"
17
18
"github.com/zalando-incubator/postgres-operator/pkg/util/config"
18
19
)
19
20
@@ -24,7 +25,7 @@ const (
24
25
)
25
26
26
27
// ControllerInformer describes stats methods of a controller
27
- type ControllerInformer interface {
28
+ type controllerInformer interface {
28
29
GetConfig () * spec.ControllerConfig
29
30
GetOperatorConfig () * config.Config
30
31
GetStatus () * spec.ControllerStatus
@@ -40,7 +41,7 @@ type ControllerInformer interface {
40
41
type Server struct {
41
42
logger * logrus.Entry
42
43
http http.Server
43
- controller ControllerInformer
44
+ controller controllerInformer
44
45
}
45
46
46
47
var (
54
55
)
55
56
56
57
// New creates new HTTP API server
57
- func New (controller ControllerInformer , port int , logger * logrus.Logger ) * Server {
58
+ func New (controller controllerInformer , port int , logger * logrus.Logger ) * Server {
58
59
s := & Server {
59
60
logger : logger .WithField ("pkg" , "apiserver" ),
60
61
controller : controller ,
@@ -140,24 +141,24 @@ func (s *Server) clusters(w http.ResponseWriter, req *http.Request) {
140
141
err error
141
142
)
142
143
143
- if matches := clusterStatusURL . FindAllStringSubmatch ( req .URL .Path , - 1 ); matches != nil {
144
- resp , err = s .controller .ClusterStatus (matches [0 ][ 1 ] , matches [0 ][ 2 ])
145
- } else if matches := teamURL . FindAllStringSubmatch ( req .URL .Path , - 1 ); matches != nil {
144
+ if matches := util . FindNamedStringSubmatch ( clusterStatusURL , req .URL .Path ); matches != nil {
145
+ resp , err = s .controller .ClusterStatus (matches ["team" ] , matches ["cluster" ])
146
+ } else if matches := util . FindNamedStringSubmatch ( teamURL , req .URL .Path ); matches != nil {
146
147
teamClusters := s .controller .TeamClusterList ()
147
- clusters , found := teamClusters [matches [0 ][ 1 ]]
148
+ clusters , found := teamClusters [matches ["team" ]]
148
149
if ! found {
149
150
s .respond (nil , fmt .Errorf ("could not find clusters for the team" ), w )
150
151
}
151
152
152
153
clusterNames := make ([]string , 0 )
153
154
for _ , cluster := range clusters {
154
- clusterNames = append (clusterNames , cluster .Name [len (matches [0 ][ 1 ])+ 1 :])
155
+ clusterNames = append (clusterNames , cluster .Name [len (matches ["team" ])+ 1 :])
155
156
}
156
157
157
158
s .respond (clusterNames , nil , w )
158
159
return
159
- } else if matches := clusterLogsURL . FindAllStringSubmatch ( req .URL .Path , - 1 ); matches != nil {
160
- resp , err = s .controller .ClusterLogs (matches [0 ][ 1 ] , matches [0 ][ 2 ])
160
+ } else if matches := util . FindNamedStringSubmatch ( clusterLogsURL , req .URL .Path ); matches != nil {
161
+ resp , err = s .controller .ClusterLogs (matches ["team" ] , matches ["cluster" ])
161
162
} else if req .URL .Path == clustersURL {
162
163
res := make (map [string ][]string )
163
164
for team , clusters := range s .controller .TeamClusterList () {
@@ -181,15 +182,16 @@ func (s *Server) workers(w http.ResponseWriter, req *http.Request) {
181
182
resp interface {}
182
183
err error
183
184
)
185
+
184
186
if workerAllQueue .MatchString (req .URL .Path ) {
185
187
s .allQueues (w , req )
186
188
return
187
- } else if matches := workerLogsURL . FindAllStringSubmatch ( req .URL .Path , - 1 ); matches != nil {
188
- workerID , _ := strconv .Atoi (matches [0 ][ 1 ])
189
+ } else if matches := util . FindNamedStringSubmatch ( workerLogsURL , req .URL .Path ); matches != nil {
190
+ workerID , _ := strconv .Atoi (matches ["id" ])
189
191
190
192
resp , err = s .controller .WorkerLogs (uint32 (workerID ))
191
- } else if matches := workerEventsQueueURL . FindAllStringSubmatch ( req .URL .Path , - 1 ); matches != nil {
192
- workerID , _ := strconv .Atoi (matches [0 ][ 1 ])
193
+ } else if matches := util . FindNamedStringSubmatch ( workerEventsQueueURL , req .URL .Path ); matches != nil {
194
+ workerID , _ := strconv .Atoi (matches ["id" ])
193
195
194
196
resp , err = s .controller .ListQueue (uint32 (workerID ))
195
197
} else {
0 commit comments