cmd

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

			s := g.Server()

			s.BindHookHandler("/*", ghttp.HookBeforeServe, beforeServeHook)

			s.Group("/", func(g *ghttp.RouterGroup) {

				g.Middleware(middlewareHandlerResponse)

				g.Bind(
					func(r *ghttp.Request) {
						r.Response.WriteStatus(http.StatusOK, "Hello Fast API")
						r.Exit()
						return
					},
					health.NewV1(),
				)
			})

			s.BindHandler("/v1/realtime", func(r *ghttp.Request) {
				middleware(r)
				if err := service.Realtime().Realtime(r.GetCtx(), r, model.RealtimeRequest{
					Model: r.FormValue("model"),
				}, nil, nil); err != nil {
					err := errors.Error(r.GetCtx(), err)
					r.Response.Header().Set("Content-Type", "application/json")
					r.Response.WriteStatus(err.Status(), gjson.MustEncodeString(err))
					r.Exit()
				}
			})

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

				v1.Middleware(middlewareHandlerResponse)
				v1.Middleware(middleware)

				v1.Group("/", func(g *ghttp.RouterGroup) {
					g.Bind(
						dashboard.NewV1(),
						embedding.NewV1(),
						moderation.NewV1(),
						file.NewV1(),
					)
				})

				v1.Group("/dashboard", func(g *ghttp.RouterGroup) {
					g.Bind(
						dashboard.NewV1(),
					)
				})

				v1.Group("/chat", func(g *ghttp.RouterGroup) {
					g.Bind(
						chat.NewV1(),
					)
				})

				v1.Group("/images", func(g *ghttp.RouterGroup) {
					g.Bind(
						image.NewV1(),
					)
				})

				v1.Group("/audio", func(g *ghttp.RouterGroup) {
					g.Bind(
						audio.NewV1(),
					)
				})
			})

			s.Group("/mj**", func(v1 *ghttp.RouterGroup) {
				v1.Middleware(middlewareHandlerResponse)
				v1.Middleware(middleware)
				v1.Bind(
					midjourney.NewV1(),
				)
			})

			if config.Cfg.ApiServerAddress != "" {
				s.SetAddr(config.Cfg.ApiServerAddress)
			}

			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