Skip to content

Commit 3e23b16

Browse files
committed
add fiber example
1 parent 5f1f8a9 commit 3e23b16

File tree

10 files changed

+102
-8
lines changed

10 files changed

+102
-8
lines changed

archaius/cse/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package main
22

3-
import _ "github.com/huaweicse/auth/adaptor/gochassis"
43
import (
54
"github.com/go-chassis/go-chassis-examples/archaius/resource"
65
"github.com/go-chassis/go-chassis/v2"

go.mod

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
module github.com/go-chassis/go-chassis-examples
22

33
require (
4-
github.com/emicklei/go-restful v2.12.0+incompatible
5-
github.com/go-chassis/go-archaius v1.5.5
6-
github.com/go-chassis/go-chassis-extension/protocol/grpc v0.0.0-20220528080737-c7602af2459f
7-
github.com/go-chassis/go-chassis-extension/tracing/zipkin v0.0.0-20220528080737-c7602af2459f
8-
github.com/go-chassis/go-chassis/v2 v2.4.0
4+
github.com/emicklei/go-restful v2.15.1-0.20220703112237-d9c71e118c95+incompatible
5+
github.com/go-chassis/go-archaius v1.5.6
6+
github.com/go-chassis/go-chassis v1.8.3
7+
github.com/go-chassis/go-chassis-extension/protocol/fiber4r v0.0.0-20220815025917-8cf6a8451620
8+
github.com/go-chassis/go-chassis-extension/protocol/grpc v0.0.0-20220812101205-352f5742bee5
9+
github.com/go-chassis/go-chassis-extension/tracing/zipkin v0.0.0-20220812101205-352f5742bee5
10+
github.com/go-chassis/go-chassis/v2 v2.5.3-0.20220812094026-da04106bf75b
911
github.com/go-chassis/openlog v1.1.3
12+
github.com/gofiber/fiber/v2 v2.36.0 // indirect
1013
github.com/golang/protobuf v1.5.2
11-
github.com/huaweicse/auth v1.1.2
1214
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
1315
google.golang.org/grpc v1.40.0
1416
)

hello/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ module github.com/go-chassis/go-chassis-examples/hello
33
go 1.13
44

55
require (
6-
github.com/go-chassis/go-chassis/v2 v2.0.2
6+
github.com/go-chassis/go-chassis/v2 v2.5.2
77
github.com/go-chassis/openlog v1.1.2
88
)

protocol/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Protocol examples
2+
3+
4+
# Benchmarks
5+
| Plugin | Thoughput | Latency | CPU | Mem |
6+
|------------ |----------- |--------- |------ |------ |
7+
| fiber | 54638tps | 0.88ms | 170% | 20mb |
8+
| go-restful | 23564tps | 1.4ms | 200% | 22mb |
9+
## Conclusion
10+
fiber is 2.43x faster than go-restful with less cpu and mem consumption
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
servicecomb:
3+
registry:
4+
address: http://127.0.0.1:30100
5+
disabled: true
6+
protocols:
7+
rest:
8+
listenAddress: 127.0.0.1:9000
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
servicecomb:
2+
service:
3+
name: HelloFiber

protocol/gofiber/server/main.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"github.com/go-chassis/go-chassis/v2"
5+
6+
_ "github.com/go-chassis/go-chassis-extension/protocol/fiber4r"
7+
8+
"github.com/go-chassis/openlog"
9+
"github.com/gofiber/fiber/v2"
10+
)
11+
12+
func SayHello(c *fiber.Ctx) error {
13+
return c.SendString("hello. go chassis")
14+
}
15+
16+
func main() {
17+
app := fiber.New()
18+
app.Get("/", SayHello)
19+
chassis.RegisterSchema("rest", app)
20+
if err := chassis.Init(); err != nil {
21+
openlog.Fatal("init failed." + err.Error())
22+
return
23+
}
24+
if err := chassis.Run(); err != nil {
25+
openlog.Fatal("run failed." + err.Error())
26+
return
27+
}
28+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
servicecomb:
3+
registry:
4+
address: http://127.0.0.1:30100
5+
disabled: true
6+
protocols:
7+
rest:
8+
listenAddress: 127.0.0.1:7000
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
servicecomb:
2+
service:
3+
name: HelloResftul

protocol/gorestful/main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"github.com/go-chassis/go-chassis/v2"
5+
rf "github.com/go-chassis/go-chassis/v2/server/restful"
6+
"github.com/go-chassis/openlog"
7+
"net/http"
8+
)
9+
10+
type HelloResource struct {
11+
}
12+
13+
func (r *HelloResource) SayHi(b *rf.Context) {
14+
b.Write([]byte("hello. go chassis"))
15+
return
16+
}
17+
18+
func (r *HelloResource) URLPatterns() []rf.Route {
19+
return []rf.Route{
20+
{Method: http.MethodGet, Path: "/hello", ResourceFunc: r.SayHi},
21+
}
22+
}
23+
24+
//if you use go run main.go instead of binary run, plz export CHASSIS_HOME=/{path}/{to}/server/
25+
26+
func main() {
27+
chassis.RegisterSchema("rest", &HelloResource{})
28+
if err := chassis.Init(); err != nil {
29+
openlog.Fatal("Init failed." + err.Error())
30+
return
31+
}
32+
chassis.Run()
33+
}

0 commit comments

Comments
 (0)