-
-
Notifications
You must be signed in to change notification settings - Fork 155
/
main.go
43 lines (35 loc) · 789 Bytes
/
main.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
package main
import (
"context"
"fmt"
"github.com/gotomicro/ego"
"github.com/gotomicro/ego/client/ehttp"
"github.com/gotomicro/ego/core/elog"
"github.com/gotomicro/ego/core/etrace"
)
func main() {
if err := ego.New().Invoker(
invokerHTTP,
callHTTP,
).Run(); err != nil {
elog.Error("startup", elog.FieldErr(err))
}
}
var httpComp *ehttp.Component
func invokerHTTP() error {
httpComp = ehttp.Load("http.test").Build()
return nil
}
func callHTTP() error {
span, ctx := etrace.StartSpanFromContext(context.Background(), "callHTTP()")
defer span.Finish()
req := httpComp.R()
// Inject traceId Into Header
c1 := etrace.HeaderInjector(ctx, req.Header)
info, err := req.SetContext(c1).Get("/hello")
if err != nil {
return err
}
fmt.Println(info)
return nil
}