Migrated all http mechanics to a central handler, changed static
content to all be front-loaded and thread safe
This commit is contained in:
		
							
								
								
									
										16
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								main.go
									
									
									
									
									
								
							@ -7,7 +7,6 @@ import (
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"os"
 | 
			
		||||
	"qurl/pages"
 | 
			
		||||
	"qurl/static"
 | 
			
		||||
	"qurl/storage"
 | 
			
		||||
	"runtime"
 | 
			
		||||
)
 | 
			
		||||
@ -54,22 +53,15 @@ func main() {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	mux := http.NewServeMux()
 | 
			
		||||
	mux.Handle("/index.html", &static.StaticContent{Content: "index.html"})
 | 
			
		||||
	mux.Handle("/favicon.ico", &static.StaticContent{Content: "favicon.ico"})
 | 
			
		||||
	mux.Handle("/qurl.css", &static.StaticContent{Content: "qurl.css"})
 | 
			
		||||
 | 
			
		||||
	submit := &pages.SubmitHandler{Storage: stor}
 | 
			
		||||
	err = submit.Init()
 | 
			
		||||
	root := &pages.RootHandler{Storage: stor}
 | 
			
		||||
	err = root.Init()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		fmt.Fprintf(os.Stderr, "Submit init error: %s\n", err.Error())
 | 
			
		||||
		fmt.Fprintf(os.Stderr, "Handler Init Error: %s\n", err.Error())
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	mux.Handle("/submit.html", submit)
 | 
			
		||||
 | 
			
		||||
	fmt.Fprintf(os.Stdout, "qurl listening .. \n")
 | 
			
		||||
	err = http.Serve(listen, mux)
 | 
			
		||||
	err = http.Serve(listen, root)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		fmt.Fprintf(os.Stderr, "Serve error: %s\n", err.Error())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user