Browse Source

Update bootstrap

Vova Tkach 6 years ago
parent
commit
267fbfd982

+ 3 - 3
Gopkg.lock

@@ -2,12 +2,12 @@
 
 
 [[projects]]
-  digest = "1:32c86e5ce15a42e48631f1384891c840f6067333f4735b3e904a462d14344114"
+  digest = "1:43fda75367d9fc8a715e2f1484dd9290c5a111c33eaf883c0f19edc035ba41ec"
   name = "github.com/vladimirok5959/golang-server-bootstrap"
   packages = ["bootstrap"]
   pruneopts = "UT"
-  revision = "1afc55739623b0d65c665abaa71624b4b48fa0df"
-  version = "v1.0.0"
+  revision = "560c0e2d2ce09276299ab1d50ad80b2fe5f50382"
+  version = "v1.0.1"
 
 [[projects]]
   digest = "1:3d823a99a747dbcdfb547754418ca792a57dfef66c2d1f540bffbf12c07bd7bf"

+ 1 - 2
main.go

@@ -51,7 +51,7 @@ func main() {
 	stat := static.New(consts.DirIndexFile)
 
 	// Init and start web server
-	bootstrap.Start(fmt.Sprintf("%s:%d", ParamHost, ParamPort), 30, consts.AssetsPath, func(w http.ResponseWriter, r *http.Request) {
+	bootstrap.Start(nil, fmt.Sprintf("%s:%d", ParamHost, ParamPort), 30, consts.AssetsPath, func(w http.ResponseWriter, r *http.Request) {
 		w.Header().Set("Server", "fave.pro/"+consts.ServerVersion)
 	}, func(w http.ResponseWriter, r *http.Request) {
 		// Mounted assets
@@ -74,7 +74,6 @@ func main() {
 		vhost_dir_logs := vhost_dir + string(os.PathSeparator) + "logs"
 		vhost_dir_template := vhost_dir + string(os.PathSeparator) + "template"
 		vhost_dir_tmp := vhost_dir + string(os.PathSeparator) + "tmp"
-
 		if !utils.IsHostDirExists(vhost_dir_config) {
 			utils.SystemErrorPageEngine(w, errors.New("Folder "+vhost_dir_config+" is not found"))
 			return

+ 15 - 4
vendor/github.com/vladimirok5959/golang-server-bootstrap/bootstrap/bootstrap.go

@@ -9,6 +9,7 @@ import (
 	"time"
 )
 
+type hndl func(h http.Handler) http.Handler
 type callback func(w http.ResponseWriter, r *http.Request)
 
 type bootstrap struct {
@@ -47,13 +48,23 @@ func (this *bootstrap) handler(w http.ResponseWriter, r *http.Request) {
 	}
 }
 
-func Start(host string, timeout time.Duration, path string, before callback, after callback) {
+func Start(h hndl, host string, timeout time.Duration, path string, before callback, after callback) {
 	mux := http.NewServeMux()
 	mux.HandleFunc("/", new(path, before, after).handler)
-	srv := &http.Server{
-		Addr:    host,
-		Handler: mux,
+
+	var srv *http.Server
+	if h == nil {
+		srv = &http.Server{
+			Addr:    host,
+			Handler: mux,
+		}
+	} else {
+		srv = &http.Server{
+			Addr:    host,
+			Handler: h(mux),
+		}
 	}
+
 	stop := make(chan os.Signal)
 	signal.Notify(stop, os.Interrupt)
 	go func() {