Browse Source

Upgrade bootstrap version

Vova Tkach 6 years ago
parent
commit
04a925cc55
5 changed files with 15 additions and 12 deletions
  1. 1 1
      go.mod
  2. 2 0
      go.sum
  3. 3 3
      main.go
  4. 8 7
      vendor/github.com/vladimirok5959/golang-server-bootstrap/bootstrap/bootstrap.go
  5. 1 1
      vendor/modules.txt

+ 1 - 1
go.mod

@@ -2,7 +2,7 @@ module golang-fave
 
 require (
 	github.com/go-sql-driver/mysql v1.4.1
-	github.com/vladimirok5959/golang-server-bootstrap v1.0.4
+	github.com/vladimirok5959/golang-server-bootstrap v1.0.5
 	github.com/vladimirok5959/golang-server-resources v1.0.2
 	github.com/vladimirok5959/golang-server-sessions v1.0.4
 	github.com/vladimirok5959/golang-server-static v1.0.0

+ 2 - 0
go.sum

@@ -3,6 +3,8 @@ github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG
 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 github.com/vladimirok5959/golang-server-bootstrap v1.0.4 h1:+Su6EAc5ZXntjEOkYKVZUJ8pRVrh7GIvqrkmeMS48Vo=
 github.com/vladimirok5959/golang-server-bootstrap v1.0.4/go.mod h1:R5PGBuqlupYd0evIXoi81plWH/HpNQO2V/jHxZzg2y0=
+github.com/vladimirok5959/golang-server-bootstrap v1.0.5 h1:+7MfVJCh/c5LcDV9xCWeXSE3KVDSP5EiQPddkccznV8=
+github.com/vladimirok5959/golang-server-bootstrap v1.0.5/go.mod h1:R5PGBuqlupYd0evIXoi81plWH/HpNQO2V/jHxZzg2y0=
 github.com/vladimirok5959/golang-server-resources v1.0.2 h1:XwxFXyaOtfDGRmYp8P9q4P4gx4YK8NiYacpHe9V8Lck=
 github.com/vladimirok5959/golang-server-resources v1.0.2/go.mod h1:tsf2oAEf3E3ukiQSCO7dstl0IXbEXec68UUIiMWysBc=
 github.com/vladimirok5959/golang-server-sessions v1.0.2 h1:VG14aTnH8+vb81quhekkrJ1vTi57EU4USDX1UzDYIzw=

+ 3 - 3
main.go

@@ -87,9 +87,9 @@ func main() {
 	mods := modules.New()
 
 	// Init and start web server
-	bootstrap.Start(lg.Handler, fmt.Sprintf("%s:%d", consts.ParamHost, consts.ParamPort), 9, consts.AssetsPath, func(w http.ResponseWriter, r *http.Request) {
+	bootstrap.Start(lg.Handler, fmt.Sprintf("%s:%d", consts.ParamHost, consts.ParamPort), 9, consts.AssetsPath, func(w http.ResponseWriter, r *http.Request, o interface{}) {
 		w.Header().Set("Server", "fave.pro/"+consts.ServerVersion)
-	}, func(w http.ResponseWriter, r *http.Request) {
+	}, func(w http.ResponseWriter, r *http.Request, o interface{}) {
 		// Schema
 		r.URL.Scheme = "http"
 
@@ -165,7 +165,7 @@ func main() {
 		utils.SystemErrorPage404(w)
 	}, func(s *http.Server) {
 		s.SetKeepAlivesEnabled(consts.ParamKeepAlive)
-	})
+	}, nil)
 }
 
 func ServeTemplateFile(w http.ResponseWriter, r *http.Request, file string, path string, dir string) bool {

+ 8 - 7
vendor/github.com/vladimirok5959/golang-server-bootstrap/bootstrap/bootstrap.go

@@ -11,22 +11,23 @@ import (
 )
 
 type customHandler func(h http.Handler) http.Handler
-type callbackBeforeAfter func(w http.ResponseWriter, r *http.Request)
+type callbackBeforeAfter func(w http.ResponseWriter, r *http.Request, o interface{})
 type callbackServer func(s *http.Server)
 
 type bootstrap struct {
 	path   string
 	before callbackBeforeAfter
 	after  callbackBeforeAfter
+	object interface{}
 }
 
-func new(path string, before callbackBeforeAfter, after callbackBeforeAfter) *bootstrap {
-	return &bootstrap{path, before, after}
+func new(path string, before callbackBeforeAfter, after callbackBeforeAfter, object interface{}) *bootstrap {
+	return &bootstrap{path, before, after, object}
 }
 
 func (this *bootstrap) handler(w http.ResponseWriter, r *http.Request) {
 	if this.before != nil {
-		this.before(w, r)
+		this.before(w, r, this.object)
 	}
 	if r.URL.Path == "/"+this.path+"/bootstrap.css" {
 		w.Header().Set("Cache-Control", "public, max-age=31536000")
@@ -50,13 +51,13 @@ func (this *bootstrap) handler(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 	if this.after != nil {
-		this.after(w, r)
+		this.after(w, r, this.object)
 	}
 }
 
-func Start(h customHandler, host string, timeout time.Duration, path string, before callbackBeforeAfter, after callbackBeforeAfter, cbserv callbackServer) {
+func Start(h customHandler, host string, timeout time.Duration, path string, before callbackBeforeAfter, after callbackBeforeAfter, cbserv callbackServer, object interface{}) {
 	mux := http.NewServeMux()
-	mux.HandleFunc("/", new(path, before, after).handler)
+	mux.HandleFunc("/", new(path, before, after, object).handler)
 
 	var srv *http.Server
 	if h == nil {

+ 1 - 1
vendor/modules.txt

@@ -1,6 +1,6 @@
 # github.com/go-sql-driver/mysql v1.4.1
 github.com/go-sql-driver/mysql
-# github.com/vladimirok5959/golang-server-bootstrap v1.0.4
+# github.com/vladimirok5959/golang-server-bootstrap v1.0.5
 github.com/vladimirok5959/golang-server-bootstrap/bootstrap
 # github.com/vladimirok5959/golang-server-resources v1.0.2
 github.com/vladimirok5959/golang-server-resources/resource