-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
51 lines (44 loc) · 1.22 KB
/
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
44
45
46
47
48
49
50
51
package main
import (
"nacos_consul_adapter/config"
"nacos_consul_adapter/consul"
"nacos_consul_adapter/rest"
"nacos_consul_adapter/started/cmd"
"os"
"strconv"
"time"
log "github.com/sirupsen/logrus"
"github.com/kataras/iris/v12"
)
func main() {
cmd.Execute()
consulRest := rest.ConsulPretenderRest{
Adapter: consul.InitNacosAdapter(config.Conf),
}
app := iris.New()
f, _ := os.Create("iris.log")
app.Logger().SetOutput(f)
app.Logger().SetLevelOutput("error", f)
app.Use(Logger())
consulAPI := app.Party("/v1")
{
consulAPI.Use(iris.Compression)
consulAPI.Get("/catalog/service/{serviceName}", consulRest.FetchServiceByName)
consulAPI.Get("/catalog/services", consulRest.FetchAllServices)
consulAPI.Get("/agent/self", consulRest.FetchAgentInformation)
consulAPI.Get("/health/service/{serviceName}", consulRest.FetchHealth)
}
app.Listen(":" + strconv.Itoa(int(config.Conf.Server.Port)))
}
func Logger() iris.Handler {
return func(ctx iris.Context) {
t := time.Now()
requestPath := ctx.Path()
log.Printf("请求路径信息:主机为:%s 地址为:%s\n", ctx.Request().Host, requestPath)
ctx.Next()
latency := time.Since(t)
log.Print(latency)
status := ctx.GetStatusCode()
log.Println(status)
}
}