Rename config vars. Add widget holder template and endpoint to serve it. Add dockerfile
This commit is contained in:
9
internal/api/widget/module.go
Normal file
9
internal/api/widget/module.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package widget
|
||||
|
||||
import (
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
var Module = fx.Options(
|
||||
fx.Provide(NewWidgetHandler),
|
||||
)
|
||||
55
internal/api/widget/widget_handler.go
Normal file
55
internal/api/widget/widget_handler.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package widget
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"go.uber.org/fx"
|
||||
|
||||
"payouts/internal/service/yookassa"
|
||||
yookassaConf "payouts/internal/service/yookassa/config"
|
||||
"payouts/internal/templates"
|
||||
)
|
||||
|
||||
const WidgetPage = "/payout/widget"
|
||||
|
||||
type Handler interface {
|
||||
WidgetHandler(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
|
||||
type widgetHandler struct {
|
||||
template *template.Template
|
||||
config yookassaConf.YooKassa
|
||||
}
|
||||
|
||||
// Params represents the module input params
|
||||
type Params struct {
|
||||
fx.In
|
||||
|
||||
YookassaService yookassa.Service
|
||||
}
|
||||
|
||||
func NewWidgetHandler(p Params) (Handler, error) {
|
||||
return &widgetHandler{
|
||||
template: templates.Templates,
|
||||
config: p.YookassaService.GetConfig(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WidgetHandler renders the payouts widget page
|
||||
func (h *widgetHandler) WidgetHandler(w http.ResponseWriter, r *http.Request) {
|
||||
data := struct {
|
||||
ApiPayoutKey string
|
||||
WidgetVersion string
|
||||
}{
|
||||
ApiPayoutKey: h.config.ApiPayoutKey,
|
||||
WidgetVersion: h.config.WidgetVersion,
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
err := h.template.ExecuteTemplate(w, "payouts-widget.html", data)
|
||||
if err != nil {
|
||||
http.Error(w, "internal error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user