cmd

package
v0.0.0-...-2022bb5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start http gateway server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {

			exporter, err := prometheus.New(
				prometheus.WithoutCounterSuffixes(),
				prometheus.WithoutUnits(),
			)
			if err != nil {
				g.Log().Fatal(ctx, err)
			}

			provider := otelmetric.MustProvider(otelmetric.WithReader(exporter))
			provider.SetAsGlobal()
			defer provider.Shutdown(ctx)

			counter.Inc(ctx)
			counter.Add(ctx, 10)

			upDownCounter.Inc(ctx)
			upDownCounter.Add(ctx, 10)
			upDownCounter.Dec(ctx)

			histogram.Record(1)
			histogram.Record(20)
			histogram.Record(30)
			histogram.Record(101)
			histogram.Record(2000)
			histogram.Record(9000)
			histogram.Record(20000)

			s := g.Server()
			s.BindHandler("/metrics", ghttp.WrapH(promhttp.Handler()))
			s.Group("/", func(group *ghttp.RouterGroup) {

				group.Middleware(middleware.Response)

				group.Group("/v1", func(group *ghttp.RouterGroup) {

					group.Group("/", func(group *ghttp.RouterGroup) {
						group.Bind(login.NewV1())
						group.Bind(seat.NewV1())
					})

					group.Group("/", func(group *ghttp.RouterGroup) {
						group.Middleware(middleware.Auth)
						group.Bind(account.NewV1())
					})
				})
			})
			s.Run()
			return nil
		},
	}
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL