Skip to content

Commit bb92bc9

Browse files
committed
Begin backend work
1 parent 1bdd112 commit bb92bc9

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

GopherFazs.exe

6.39 MB
Binary file not shown.

main.go

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
11
package main
22

33
import (
4-
"io"
4+
"fmt"
55
"log"
66
"net/http"
7+
8+
"github.com/julienschmidt/httprouter"
79
)
810

9-
func MainPage(w http.ResponseWriter, req *http.Request) {
10-
io.WriteString(w, "Welcome to GoBlog!\n")
11+
func mainpage(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
12+
fmt.Fprintf(w, "Welcome to GoBlog!")
1113
}
1214

13-
func main() {
14-
http.HandleFunc("/", MainPage)
15-
err := http.ListenAndServe(":1337", nil)
16-
if err != nil {
17-
log.Fatal("ListenAndServe: ", err)
15+
func signup(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
16+
username := ps.ByName("username")
17+
password := ps.ByName("password")
18+
// create new user
19+
if len(username)+len(password) < 11 {
20+
fmt.Fprintf(w, "New user"+username+" with pass:"+password+"has signed up")
21+
} else {
22+
fmt.Fprintf(w, "Invalid arguments!")
1823
}
1924
}
25+
26+
func newblog(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
27+
// authenticate username and password
28+
blogname := ps.ByName("blogname")
29+
30+
if len(blogname) < 20 {
31+
// create new blog
32+
}
33+
}
34+
35+
func main() {
36+
router := httprouter.New()
37+
router.GET("/", mainpage)
38+
router.GET("/new/:username/:password", signup)
39+
router.GET("/new/:username/:password/:blogname", newblog)
40+
log.Fatal(http.ListenAndServe(":1337", router))
41+
}

0 commit comments

Comments
 (0)