Skip to content

Commit 65de9c8

Browse files
committed
Add randomized port handling
1 parent 980d10a commit 65de9c8

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

GoBlog

184 Bytes
Binary file not shown.

main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func AdminPage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
157157
func AdminHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
158158
blogname := r.FormValue("blogname")
159159
website := r.FormValue("website")
160-
port := 1001
160+
port := rand.Intn(63000) + 2000
161161
blogcheck := []byte("")
162162

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

307308
func main() {
309+
fmt.Println("Started server on port 1337")
308310
router := httprouter.New()
309311
router.GET("/", MainPage)
310312
router.POST("/login/", LoginHandler)
@@ -313,5 +315,5 @@ func main() {
313315
router.GET("/admin/", AdminPage)
314316
router.POST("/admin/", AdminHandler)
315317
router.GET("/logout/", LogoutHandler)
316-
log.Fatal(http.ListenAndServe(":1338", router))
318+
log.Fatal(http.ListenAndServe(":1337", router))
317319
}

0 commit comments

Comments
 (0)