summaryrefslogtreecommitdiff
path: root/README.md
blob: e3a172b426ed8b24e88ab3c4fb56f5643e7d0d8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Growel

![](https://github.com/BigCoke233/growel/actions/workflows/go.yml/badge.svg)

**Minimal, headless, zero-dependency Web framework written in Go.** This is toy software I develop to learn, so do not use in production.

## Usage

```go
e := growel.New()

e.GET("/hello", func(c *growel.Context) {
	c.JSON(200, map[string]string{
		"message": "Hello, Growel!"
	})
})

e.Group("/api", func(api *growel.Group) {
	api.Group("/user", func(user *growel.Group) {
		user.GET("/", func(c *growel.Context) {
			c.JSON(200, Users)
		})

		user.GET("/:uid", func(c *growel.Context) {
			uid, err := strconv.Atoi(c.Params["uid"])
			if err != nil {
				c.BadRequest("Invalid user ID")
				return
			}

			for _, user := range Users {
				if user.ID == uid {
					c.JSON(200, user)
					return
				}
			}

			c.NotFound("User not found")
		})
	})
})
```

## License

MIT