-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRouter.go
More file actions
80 lines (71 loc) · 2.75 KB
/
Router.go
File metadata and controls
80 lines (71 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Copyright (c) 2024. Devtron Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package api
import (
"encoding/json"
"net/http"
"github.com/devtron-labs/central-api/api/currency"
"github.com/devtron-labs/central-api/api/handler"
"github.com/gorilla/mux"
"go.uber.org/zap"
)
type MuxRouter struct {
logger *zap.SugaredLogger
Router *mux.Router
restHandler RestHandler
currencyRouter currency.Router
}
func NewMuxRouter(logger *zap.SugaredLogger, restHandler RestHandler, currencyRouter currency.Router) *MuxRouter {
return &MuxRouter{
logger: logger,
Router: mux.NewRouter(),
restHandler: restHandler,
currencyRouter: currencyRouter,
}
}
func (r MuxRouter) Init() {
r.Router.StrictSlash(true)
//r.Router.Handle("/metrics", promhttp.Handler())
r.Router.Path("/health").HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
handler.SetupCorsOriginHeader(&writer, request)
writer.Header().Set("Content-Type", "application/json")
writer.WriteHeader(200)
response := handler.Response{}
response.Code = 200
response.Result = "OK"
b, err := json.Marshal(response)
if err != nil {
b = []byte("OK")
r.logger.Errorw("Unexpected error in apiError", "err", err)
}
_, _ = writer.Write(b)
})
r.Router.Path("/release/notes").HandlerFunc(r.restHandler.GetReleases).Methods("GET")
r.Router.Path("/release/webhook").HandlerFunc(r.restHandler.ReleaseWebhookHandler).Methods("POST")
r.Router.Path("/modules").HandlerFunc(r.restHandler.GetModules).Methods("GET")
r.Router.Path("/dockerfileTemplate").HandlerFunc(r.restHandler.GetDockerfileTemplateMetadata).Methods("GET")
r.Router.Path("/buildpackMetadata").HandlerFunc(r.restHandler.GetBuildpackMetadata).Methods("GET")
r.Router.Path("/v2/modules").HandlerFunc(r.restHandler.GetModulesV2).Methods("GET")
r.Router.Path("/module").
Queries("name", "{name}").
HandlerFunc(r.restHandler.GetModuleByName).Methods("GET")
// Create a sub-router for currency endpoints
currencyRouter := r.Router.PathPrefix("/currency").Subrouter()
// Initialize currency routes
r.currencyRouter.InitCurrencyRoutes(currencyRouter)
// athena-ai-chat feedback router
r.Router.Path("/athena-feedback").HandlerFunc(r.restHandler.SubmitFeedback).Methods("POST")
}