2023-07-18 19:48:38 +00:00
|
|
|
# server
|
2023-07-18 11:37:05 +00:00
|
|
|
|
2023-07-18 19:48:38 +00:00
|
|
|
HTTP server.
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
```shell
|
|
|
|
go get git.akyoto.dev/go/server
|
|
|
|
```
|
|
|
|
|
2023-07-22 09:54:13 +00:00
|
|
|
## Examples
|
|
|
|
|
|
|
|
Init:
|
2023-07-18 19:48:38 +00:00
|
|
|
|
|
|
|
```go
|
|
|
|
s := server.New()
|
|
|
|
|
2023-07-22 09:54:13 +00:00
|
|
|
// Add your routes here.
|
|
|
|
|
|
|
|
http.ListenAndServe(":8080", s)
|
|
|
|
```
|
|
|
|
|
2023-07-22 09:55:11 +00:00
|
|
|
Static:
|
2023-07-22 09:54:13 +00:00
|
|
|
|
|
|
|
```go
|
2023-07-18 19:48:38 +00:00
|
|
|
s.Get("/", func(ctx server.Context) error {
|
|
|
|
return ctx.String("Hello")
|
|
|
|
})
|
2023-07-22 09:54:13 +00:00
|
|
|
```
|
2023-07-18 19:48:38 +00:00
|
|
|
|
2023-07-22 09:55:11 +00:00
|
|
|
Parameter:
|
2023-07-22 09:54:13 +00:00
|
|
|
|
|
|
|
```go
|
|
|
|
s.Get("/blog/:post", func(ctx server.Context) error {
|
|
|
|
return ctx.String(ctx.Get("post"))
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2023-07-22 09:55:11 +00:00
|
|
|
Wildcard:
|
2023-07-22 09:54:13 +00:00
|
|
|
|
|
|
|
```go
|
|
|
|
s.Get("/images/*file", func(ctx server.Context) error {
|
|
|
|
return ctx.String(ctx.Get("file"))
|
|
|
|
})
|
2023-07-18 19:48:38 +00:00
|
|
|
```
|