feat: automate demo-site deployment and configuration (#42)

* add demo env variable

* setup initialization when demo

* disable password when in demo mode

* expose demo status to API

* improve UI for demo instance
This commit is contained in:
Hayden 2022-10-12 12:53:22 -08:00 committed by GitHub
parent eca071f974
commit 92368dabf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 166 additions and 45 deletions

View file

@ -13,9 +13,16 @@ func WithMaxUploadSize(maxUploadSize int64) func(*V1Controller) {
}
}
func WithDemoStatus(demoStatus bool) func(*V1Controller) {
return func(ctrl *V1Controller) {
ctrl.isDemo = demoStatus
}
}
type V1Controller struct {
svc *services.AllServices
maxUploadSize int64
isDemo bool
}
type (
@ -30,7 +37,8 @@ type (
Versions []string `json:"versions"`
Title string `json:"title"`
Message string `json:"message"`
Build Build
Build Build `json:"build"`
Demo bool `json:"demo"`
}
)
@ -48,6 +56,10 @@ func NewControllerV1(svc *services.AllServices, options ...func(*V1Controller))
svc: svc,
}
for _, opt := range options {
opt(ctrl)
}
return ctrl
}
@ -66,6 +78,7 @@ func (ctrl *V1Controller) HandleBase(ready ReadyFunc, build Build) http.HandlerF
Title: "Go API Template",
Message: "Welcome to the Go API Template Application!",
Build: build,
Demo: ctrl.isDemo,
})
}
}

View file

@ -136,6 +136,11 @@ type (
// @Security Bearer
func (ctrl *V1Controller) HandleUserSelfChangePassword() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if ctrl.isDemo {
server.RespondError(w, http.StatusForbidden, nil)
return
}
var cp ChangePassword
err := server.Decode(r, &cp)
if err != nil {