2 // ========================LICENSE_START=================================
5 // Copyright (C) 2023: Nordix Foundation
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // ========================LICENSE_END===================================
30 log "github.com/sirupsen/logrus"
32 "github.com/labstack/echo/v4"
33 "oransc.org/nonrtric/capifprov/handler"
36 type TemplateRegistry struct {
37 templates map[string]*template.Template
40 func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
41 tmpl, ok := t.templates[name]
43 err := errors.New("Template not found -> " + name)
46 return tmpl.ExecuteTemplate(w, "base", data)
54 var capifCoreUrl string
55 flag.StringVar(&capifCoreUrl, "capifCoreUrl", "http://localhost:8090", "Url for CAPIF core")
56 var logLevelStr = flag.String("loglevel", "Info", "Log level")
57 var port = flag.Int("port", 9090, "Port for CAPIF Provider")
61 if loglevel, err := log.ParseLevel(*logLevelStr); err == nil {
62 log.SetLevel(loglevel)
65 templates := make(map[string]*template.Template)
66 templates["home.html"] = template.Must(template.ParseFiles("view/home.html", "view/base.html"))
67 templates["registration.html"] = template.Must(template.ParseFiles("view/registration.html", "view/base.html"))
68 templates["publishapi.html"] = template.Must(template.ParseFiles("view/publishapi.html", "view/base.html"))
69 templates["getapi.html"] = template.Must(template.ParseFiles("view/getapi.html", "view/base.html"))
71 e.Renderer = &TemplateRegistry{
76 e.GET("/", handler.HomeHandler)
77 e.POST("/", handler.HomeHandler)
79 e.GET("/registration", handler.RegistrationHandler)
80 e.POST("/registration", handler.RegistrationFormHandler(capifCoreUrl))
82 e.GET("/publishapi", handler.PublishapiHandler)
83 e.POST("/publishapi", handler.PublishApiFormHandler(capifCoreUrl))
85 e.GET("/getapi", handler.GetApiRequest(capifCoreUrl))
87 // Start the web server
88 e.Logger.Fatal(e.Start(fmt.Sprintf("0.0.0.0:%d", *port)))