Skip to content

Commit 7f557a4

Browse files
committed
[go/go-faster]: Add go-faster
1 parent 6394199 commit 7f557a4

File tree

9 files changed

+292
-0
lines changed

9 files changed

+292
-0
lines changed

frameworks/Go/go-faster/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM docker.io/golang:1.25.0
2+
3+
WORKDIR /go-faster
4+
5+
COPY ./src /go-faster
6+
7+
RUN GOAMD64=v3 go build -ldflags="-s -w" -o app .
8+
9+
EXPOSE 8080
10+
11+
CMD ./app

frameworks/Go/go-faster/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# [go-faster](https://github.com/go-faster) (Go) Benchmarking Test
2+
3+
The [go-faster/hx][hx] is a low-level http package for Go, simplified fork of [fasthttp][fasthttp].
4+
The [go-faster/jx][jx] is a low-level json package for Go.
5+
The [ogen][ogen] project is a fast OpenAPI v3 implementation for Go.
6+
7+
8+
[go-faster]: https://github.com/go-faster
9+
[hx]: https://github.com/go-faster/hx
10+
[jx]: https://github.com/go-faster/jx
11+
[ogen]: https://github.com/ogen-go
12+
[fasthttp]: https://github.com/valyala/fasthttp
13+
14+
## Test URLs
15+
16+
http://localhost:8080/plaintext
17+
http://localhost:8080/json
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"framework": "go-faster",
3+
"tests": [{
4+
"default": {
5+
"json_url": "/json",
6+
"plaintext_url": "/plaintext",
7+
"port": 8080,
8+
"approach": "Realistic",
9+
"classification": "Platform",
10+
"database": "None",
11+
"framework": "go-faster",
12+
"language": "Go",
13+
"flavor": "None",
14+
"orm": "Raw",
15+
"platform": "None",
16+
"webserver": "None",
17+
"os": "Linux",
18+
"database_os": "Linux",
19+
"display_name": "go-faster",
20+
"notes": "",
21+
"versus": "go"
22+
}
23+
}]
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[framework]
2+
name = "go-faster"
3+
4+
[main]
5+
urls.plaintext = "/plaintext"
6+
urls.json = "/json"
7+
approach = "Realistic"
8+
classification = "Platform"
9+
database = "None"
10+
database_os = "Linux"
11+
os = "Linux"
12+
orm = "Raw"
13+
platform = "None"
14+
webserver = "None"
15+
versus = "go"

frameworks/Go/go-faster/src/go.mod

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module go-faster/app
2+
3+
go 1.23.0
4+
5+
toolchain go1.25.0
6+
7+
require (
8+
github.com/go-faster/errors v0.7.1
9+
github.com/go-faster/hx v0.1.0
10+
github.com/go-faster/jx v1.1.0
11+
github.com/ogen-go/ogen v1.14.0
12+
)
13+
14+
tool github.com/ogen-go/ogen/cmd/jschemagen
15+
16+
require (
17+
github.com/dlclark/regexp2 v1.11.5 // indirect
18+
github.com/fatih/color v1.18.0 // indirect
19+
github.com/ghodss/yaml v1.0.0 // indirect
20+
github.com/go-faster/yaml v0.4.6 // indirect
21+
github.com/google/uuid v1.6.0 // indirect
22+
github.com/mattn/go-colorable v0.1.13 // indirect
23+
github.com/mattn/go-isatty v0.0.20 // indirect
24+
github.com/segmentio/asm v1.2.0 // indirect
25+
github.com/valyala/bytebufferpool v1.0.0 // indirect
26+
go.uber.org/multierr v1.11.0 // indirect
27+
go.uber.org/zap v1.27.0 // indirect
28+
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 // indirect
29+
golang.org/x/mod v0.24.0 // indirect
30+
golang.org/x/net v0.40.0 // indirect
31+
golang.org/x/sync v0.14.0 // indirect
32+
golang.org/x/sys v0.33.0 // indirect
33+
golang.org/x/text v0.25.0 // indirect
34+
golang.org/x/tools v0.33.0 // indirect
35+
gopkg.in/yaml.v2 v2.4.0 // indirect
36+
)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"flag"
6+
"log/slog"
7+
8+
"github.com/go-faster/hx"
9+
)
10+
11+
//go:generate go tool jschemagen -target message.go -typename Message message.schema.json
12+
13+
func main() {
14+
var arg struct {
15+
Workers int
16+
Addr string
17+
Mode string
18+
}
19+
flag.StringVar(&arg.Addr, "addr", "localhost:8080", "listen address")
20+
flag.IntVar(&arg.Workers, "j", 1024, "count of workers")
21+
flag.Parse()
22+
23+
slog.Info("starting server",
24+
slog.String("addr", arg.Addr),
25+
slog.Int("workers", arg.Workers),
26+
)
27+
28+
s := &hx.Server{
29+
Workers: arg.Workers,
30+
Handler: func(ctx *hx.Ctx) {
31+
switch string(ctx.Request.URI().Path()) {
32+
case "/plaintext":
33+
ctx.Response.AppendBodyString("Hello, World!")
34+
case "/json":
35+
ctx.Response.Header.Add("Content-Type", "application/json")
36+
37+
msg := Message{Message: "Hello, World!"}
38+
ctx.JSON.Encode(msg)
39+
ctx.Response.AppendBody(ctx.JSON.Encoder.Bytes())
40+
default:
41+
ctx.Response.SetStatusCode(404)
42+
}
43+
},
44+
}
45+
if err := s.ListenAndServe(context.Background(), arg.Addr); err != nil {
46+
slog.Error("Failed to start server", slog.Any("err", err))
47+
}
48+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "github.com/go-faster/jx"
4+
5+
func (m Message) JSONEncode(e *jx.Encoder) {
6+
m.Encode(e)
7+
}

frameworks/Go/go-faster/src/message.go

Lines changed: 123 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"properties": {
5+
"message": {
6+
"type": "string"
7+
}
8+
},
9+
"required": ["message"],
10+
"additionalProperties": false
11+
}

0 commit comments

Comments
 (0)