-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.go
71 lines (57 loc) · 1.74 KB
/
demo.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"time"
"github.com/gin-gonic/gin"
"github.com/shengyanli1982/orbit"
)
// customMiddleware 函数定义了一个自定义的中间件
// The customMiddleware function defines a custom middleware
func customMiddleware() gin.HandlerFunc {
// 返回一个 Gin 的 HandlerFunc
// Return a Gin HandlerFunc
return func(c *gin.Context) {
// 打印一条消息
// Print a message
fmt.Println(">>>>>>!!! demo")
// 调用下一个中间件或处理函数
// Call the next middleware or handler function
c.Next()
}
}
// 定义 service 结构体
// Define the service struct
type service struct{}
// RegisterGroup 方法将路由组注册到 service
// The RegisterGroup method registers a router group to the service
func (s *service) RegisterGroup(g *gin.RouterGroup) {
// 在 "/demo" 路径上注册一个 GET 方法的处理函数
// Register a GET method handler function on the "/demo" path
g.GET("/demo", func(c *gin.Context) {})
}
func main() {
// 创建一个新的 Orbit 配置
// Create a new Orbit configuration
config := orbit.NewConfig()
// 创建一个新的 Orbit 功能选项,并启用 metric
// Create a new Orbit feature options and enable metric
opts := orbit.NewOptions().EnableMetric()
// 创建一个新的 Orbit 引擎
// Create a new Orbit engine
engine := orbit.NewEngine(config, opts)
// 注册一个自定义的中间件
// Register a custom middleware
engine.RegisterMiddleware(customMiddleware())
// 注册一个自定义的路由组
// Register a custom router group
engine.RegisterService(&service{})
// 启动引擎
// Start the engine
engine.Run()
// 等待 30 秒
// Wait for 30 seconds
time.Sleep(30 * time.Second)
// 停止引擎
// Stop the engine
engine.Stop()
}