Skip to content

Commit

Permalink
build setup handler
Browse files Browse the repository at this point in the history
  • Loading branch information
0c34 committed Nov 5, 2017
1 parent 1387eda commit e16f71d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions setup/setup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package setup

import(
"fmt"
"net/http"

"govwa/util"
"govwa/util/database"
"govwa/util/middleware"

"github.com/julienschmidt/httprouter"
)

type Setup struct{}

func New() Setup {
return Setup{}
}

func (self Setup) SetRouter(r *httprouter.Router) {

mw := middleware.New()

r.GET("/setup", mw.LoggingMiddleware(mw.CapturePanic(setupViewHandler)))
r.POST("/setupaction", mw.LoggingMiddleware(mw.CapturePanic(setupActionHandler)))

}

func setupViewHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params){

var info string

data := make(map[string]interface{})
ok, err := database.CheckDatabase()

if !ok || err != nil{
info = fmt.Sprintf(`<div id="info" class="alert alert-danger">%s</div>`,err.Error())
data["error"] = util.ToHTML(info)
}

info = fmt.Sprintf(`<div id="info" class="alert alert-success">Connection Success</div>`)
data["error"] = util.ToHTML(info)

data["title"] = "Setup/Reset"

util.SafeRender(w,r,"template.setup", data)
}

func setupActionHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params){

}

0 comments on commit e16f71d

Please sign in to comment.