-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05c26e8
commit 2d21592
Showing
30 changed files
with
465 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/infraboard/mcube/v2/ioc" | ||
"github.com/infraboard/mcube/v2/ioc/config/logger" | ||
) | ||
|
||
func main() { | ||
ioc.DevelopmentSetup() | ||
|
||
gLogger := logger.L() | ||
gLogger.Debug().Msg("this is global logger debug msg") | ||
|
||
subLogger := logger.Sub("app1") | ||
subLogger.Debug().Msg("this is app1 sub logger debug msg") | ||
|
||
ctx := context.Background() | ||
traceLogger := logger.T("app1").Trace(ctx) | ||
traceLogger.Debug().Msg("this is app1 trace logger debug msg") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package metric | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/infraboard/mcube/v2/ioc" | ||
"github.com/infraboard/mcube/v2/ioc/apps/metric" | ||
"github.com/infraboard/mcube/v2/ioc/config/http" | ||
"github.com/infraboard/mcube/v2/ioc/config/logger" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
"github.com/rs/zerolog" | ||
) | ||
|
||
func init() { | ||
ioc.Api().Registry(&ginHandler{ | ||
Metric: metric.NewDefaultMetric(), | ||
}) | ||
} | ||
|
||
type ginHandler struct { | ||
log *zerolog.Logger | ||
ioc.ObjectImpl | ||
|
||
*metric.Metric | ||
} | ||
|
||
func (h *ginHandler) Init() error { | ||
h.log = logger.Sub(metric.AppName) | ||
return nil | ||
} | ||
|
||
func (h *ginHandler) Name() string { | ||
return metric.AppName | ||
} | ||
|
||
func (h *ginHandler) Version() string { | ||
return "v1" | ||
} | ||
|
||
func (h *ginHandler) Meta() ioc.ObjectMeta { | ||
meta := ioc.DefaultObjectMeta() | ||
meta.CustomPathPrefix = h.Endpoint | ||
return meta | ||
} | ||
|
||
func (h *ginHandler) Registry(r gin.IRouter) { | ||
r.GET("/", func(ctx *gin.Context) { | ||
// 基于标准库 包装了一层 | ||
promhttp.Handler().ServeHTTP(ctx.Writer, ctx.Request) | ||
}) | ||
|
||
h.log.Info().Msgf("Get the Metric using http://%s%s", http.Get().Addr(), h.Endpoint) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package metric | ||
|
||
import ( | ||
restfulspec "github.com/emicklei/go-restful-openapi/v2" | ||
"github.com/emicklei/go-restful/v3" | ||
"github.com/infraboard/mcube/v2/ioc" | ||
"github.com/infraboard/mcube/v2/ioc/apps/metric" | ||
"github.com/infraboard/mcube/v2/ioc/config/http" | ||
"github.com/infraboard/mcube/v2/ioc/config/logger" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
"github.com/rs/zerolog" | ||
) | ||
|
||
func init() { | ||
ioc.Api().Registry(&restfulHandler{ | ||
Metric: metric.NewDefaultMetric(), | ||
}) | ||
} | ||
|
||
type restfulHandler struct { | ||
log *zerolog.Logger | ||
ioc.ObjectImpl | ||
|
||
*metric.Metric | ||
} | ||
|
||
func (h *restfulHandler) Init() error { | ||
h.log = logger.Sub(metric.AppName) | ||
return nil | ||
} | ||
|
||
func (h *restfulHandler) Name() string { | ||
return metric.AppName | ||
} | ||
|
||
func (h *restfulHandler) Version() string { | ||
return "v1" | ||
} | ||
|
||
func (h *restfulHandler) Meta() ioc.ObjectMeta { | ||
meta := ioc.DefaultObjectMeta() | ||
meta.CustomPathPrefix = h.Endpoint | ||
return meta | ||
} | ||
|
||
func (h *restfulHandler) Registry(ws *restful.WebService) { | ||
tags := []string{"健康检查"} | ||
ws.Route(ws. | ||
GET("/"). | ||
To(h.Check). | ||
Doc("创建Job"). | ||
Metadata(restfulspec.KeyOpenAPITags, tags), | ||
) | ||
|
||
h.log.Info().Msgf("Get the Metric using http://%s%s", http.Get().Addr(), h.Endpoint) | ||
} | ||
|
||
func (h *restfulHandler) Check(r *restful.Request, w *restful.Response) { | ||
// 基于标准库 包装了一层 | ||
promhttp.Handler().ServeHTTP(w, r.Request) | ||
} |
Oops, something went wrong.