Skip to content

Commit

Permalink
Add randomized port handling
Browse files Browse the repository at this point in the history
  • Loading branch information
farazfazli committed Jan 24, 2016
1 parent 980d10a commit 65de9c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Binary file modified GoBlog
Binary file not shown.
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func AdminPage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
func AdminHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
blogname := r.FormValue("blogname")
website := r.FormValue("website")
port := 1001
port := rand.Intn(63000) + 2000
blogcheck := []byte("")

if getUser(w, r) != "" {
Expand All @@ -176,6 +176,7 @@ func AdminHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("80 -> " + strconv.Itoa(port))
fmt.Fprintf(w, "%s", create)
db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("UsersBucket"))
Expand Down Expand Up @@ -305,6 +306,7 @@ func getUserFromCookie(value string) string {
}

func main() {
fmt.Println("Started server on port 1337")
router := httprouter.New()
router.GET("/", MainPage)
router.POST("/login/", LoginHandler)
Expand All @@ -313,5 +315,5 @@ func main() {
router.GET("/admin/", AdminPage)
router.POST("/admin/", AdminHandler)
router.GET("/logout/", LogoutHandler)
log.Fatal(http.ListenAndServe(":1338", router))
log.Fatal(http.ListenAndServe(":1337", router))
}

0 comments on commit 65de9c8

Please sign in to comment.